-
Notifications
You must be signed in to change notification settings - Fork 2
/
fuzzmybox.py
68 lines (58 loc) · 1.65 KB
/
fuzzmybox.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
#!/bin/python
import sys, getopt, os
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
import random
from array import *
try:
from scapy.all import * #Required for Scapy 2.0 and above
except:
from scapy import * #Scapy 1.0
from scapy.utils import rdpcap
from scapy.layers.inet import IP,UDP,TCP
from scapy.packet import Raw
def main(argv):
inputfile = ''
outputfile = ''
hookfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:t:",["ifile=","ofile=","transformation="])
except getopt.GetoptError:
print sys.argv[0] + ' -i inputfile -o outputfile -t [hook script]'
print sys.argv[0] + ' -i sample.pcap -o result.pcap -t example'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'test.py -i <inputfile> -o <outputfile>'
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
elif opt in ("-t", "--transformation"):
hookfile = arg
pkts=rdpcap(inputfile)
for pkt in pkts:
try:
my_array = []
if pkt.haslayer(TCP):
for d in str(pkt.getlayer(TCP).payload):
my_array.append(d)
if pkt.haslayer(UDP):
for d in str(pkt.getlayer(UDP).payload):
my_array.append(d)
modname = "hooks." + hookfile
module = __import__(modname, globals(), locals(), ['modify_payload'])
func = getattr(module, "modify_payload")
data = func(my_array)
str1 = ''.join(data)
#replace payload in origional packet
if pkt.haslayer(TCP):
pkt.getlayer(TCP).payload=str1
if pkt.haslayer(UDP):
pkt.getlayer(UDP).payload=str1
except:
raise
wrpcap(outputfile, pkts)
total = len(sys.argv)
main(sys.argv[1:])