-
Notifications
You must be signed in to change notification settings - Fork 28
/
binaryWaf.py
62 lines (52 loc) · 1.28 KB
/
binaryWaf.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
'''
add payload into shell
last 4 bytes record length of payload
'''
import struct
import getopt
import sys
def help():
print ''''
Usage:
python binaryWaf.py -s shell -p payload -o outfile
-s equal to --shell
-p equal to --payload
-o equal to --output
'''
if __name__ == '__main__':
if len(sys.argv) == 1:
help()
exit(0)
try:
options, args = getopt.getopt(sys.argv[1:], "hs:p:o:", ["help", "shell", "payload"])
except getopt.GetoptError:
help()
exit(0)
file_shell = ''
file_payload = ''
file_output = ''
for name, value in options:
if name in ("-h", "--help"):
help()
exit(0)
elif name in ("-s", "--shell"):
file_shell = value
elif name in ("-p", "--payload"):
file_payload = value
elif name in ("-o"):
file_output = value
if file_shell == "":
print 'no parameter for -s'
exit(0)
elif file_payload == "":
print 'no parameter for -p'
exit(0)
elif file_output == "":
print 'no parameter for -o'
exit(0)
payload = open(file_payload,'r').read()
payload_len = len(payload)
print 'payload len is', hex(payload_len)
shell = open(file_shell,'r').read()
new_binary = shell + payload + struct.pack('I', payload_len)
open(file_output, 'w').write(new_binary)