-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbhp_fuzzer.py
81 lines (59 loc) · 2.44 KB
/
bhp_fuzzer.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
from burp import IBurpExtender
from burp import IIntruderPayloadGeneratorFactory
from burp import IIntruderPayloadGenerator
from java.util import List, ArrayList
import random
class BurpExtender(IBurpExtender, IIntruderPayloadGeneratorFactory):
def registerExtenderCallbacks(self, callbacks):
self._callbacks = callbacks
self._helpers = callbacks.getHelpers()
callbacks.registerIntruderPayloadGeneratorFactory(self)
return
def getGeneratorName(self):
return "BHP Payload Generator"
def createNewInstance(self, attack):
return BHPFuzzer(self, attack)
class BHPFuzzer(IIntruderPayloadGenerator):
def __init__(self, extender, attack):
self._extender = extender
self._helpers = extender._helpers
self._attack = attack
self.max_payloads = 10
self.num_iterations = 0
return
def hasMorePayloads(self):
if self.num_iterations == self.max_payloads:
return False
else:
return True
def getNextPayload(self, current_payload):
#convert into a string
payload = "".join(chr(x) for x in current_payload)
#call our simple mutator to fuzz the post
payload = self.mutate_payload(payload)
#increase the number of fuzzinf attempts
self.num_iterations += 1
return payload
def reset(self):
self.num_iterations = 0
return
def mutate_payload(self, original_payload):
#pick a simple mutator or even an external script
picker = random.randint(1, 3)
#select a random offet in the payload to mutate
offset = random.randint(0, len(original_payload)-1)
payload = original_payload[:offset]
#random offset insert a SQL injection attempt
if picker == 1:
payload += "'"
#jam an XSS attempt in
if picker == 2:
payload += "<script>alert('BHP!')</script>"
#repeat a chunk of the original payload a random number
if picker == 3:
chunk_length = random.randint(len(payload[offset:]), len(payload)-1)
repeater = random.randint(1,10)
for i in range(repeater):
payload += original_payload[offset:offset+chunk_length]
payload += original_payload[offset:]
return payload