This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzzer.py
388 lines (336 loc) · 9.45 KB
/
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
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
import sys
import requests
import random
import pageDiscovery
from urllib.parse import urlparse
from requests.exceptions import ConnectionError, MissingSchema, ReadTimeout
#DATA STRUCTURES
fuzzerSession = requests.Session()
queryDict = {}
sensitive = []
urls = []
commonWords = []
slowLinks = []
responseCodeLinks = []
sensitiveDataLinks = []
unsanitizedLinks = []
#GLOBAL SETTINGS
mode = ''
domain = ''
randomFuzz = 0
slow = 500
pageExtensions = ['.html', '.aspx', '.jsp', '.jspx', '.php', '.asp', '.htm', '.do', '.rb', '.rhtml']
sensitiveWords = []
vector = []
def main():
print('Fuzzer has started!')
global domain
global fuzzerSession
global mode
if sys.argv.__len__() > 2 and sys.argv.__len__() <= 8:
if sys.argv[1].lower() == 'discover':
mode = 'discover'
elif sys.argv[1].lower() == 'test':
mode = 'test'
domain = sys.argv[2].lower()
try:
r = fuzzerSession.get(domain, timeout=10)
if r.status_code == 200:
print(domain + ' is a valid URL')
print('')
fuzzerSession.get(domain)
if mode == 'discover':
#Call discover function here
discoverHelper()
elif mode == 'test':
#Call test function here
discoverHelper(False)
testHelper()
except ConnectionError as e:
print(domain + ' is not responding')
except MissingSchema as m:
print(domain + ' is not a valid URL')
except ReadTimeout as t:
print('Request to ' + domain + ' timed out')
else:
print('Please enter a fuzzer mode followed by a domain')
def discoverHelper(prints=True):
global domain
global fuzzerSession
global commonWords
global sensitiveWords
global urls
global randomFuzz
global slow
customAuthflag = False
for x in range(3, sys.argv.__len__()):
if '--common-words=' in sys.argv[x]:
filePath = sys.argv[x][15:]
wordFile = open(filePath)
for line in wordFile:
commonWords.append(line)
wordFile.close()
if '--sensitive-words=' in sys.argv[x]:
filePath = sys.argv[x][18:]
wordFile = open(filePath)
for line in wordFile:
sensitiveWords.append(line)
wordFile.close()
if '--vectors=' in sys.argv[x]:
filePath = sys.argv[x][10:]
vectorFile = open(filePath)
print(filePath)
for line in vectorFile:
vector.append(line)
vectorFile.close()
if '--random=' in sys.argv[x]:
randomSetting = sys.argv[x][9:]
if randomSetting.lower() == 'true':
randomFuzz = 1
elif randomSetting.lower() == 'false':
randomFuzz = 0;
if '--slow=' in sys.argv[x]:
slowSetting = sys.argv[x][7:]
if slowSetting.isdigit():
slow = slowSetting
if '--custom-auth=' in sys.argv[x]:
customAuthflag = True
authString = sys.argv[x][14:]
if(authString.lower() == "dvwa"):
payload = {"username":"admin", "password":"password","Login":"Login"}
fuzzerSession.post("http://127.0.0.1/dvwa/login.php", data=payload, timeout=3)
urls = pageDiscovery.allValidWebPages("http://127.0.0.1/dvwa/", "http://127.0.0.1/dvwa/index.php", fuzzerSession)
if(authString.lower() == "bodgeit"):
reg = {"username":"admin@admin.com", "password":"password1","password":"password2","Login":"Login"}
fuzzerSession.post("http://127.0.0.1:8080/bodgeit/register.jsp", data=reg)
login = {"username":"admin@admin.com", "password":"password","Login":"Login"}
fuzzerSession.post("http://127.0.0.1:8080/bodgeit/login.jsp", data=login)
urls = pageDiscovery.allValidWebPages("http://127.0.0.1:8080/", "http://127.0.0.1:8080/bodgeit/home.jsp", fuzzerSession)
if not customAuthflag:
urls = pageDiscovery.allValidWebPages(domain, domain, fuzzerSession)
guessPages()
cookieFinder(fuzzerSession)
queryUrl = []
i = 0
while(i < len(urls)):
if("?" in urls[i]):
queryUrl.append(urls[i])
substring = urls[i][0 : urls[i].index("?")]
if(substring in urls):
urls.remove(urls[i])
else:
urls[i] = substring
i+=1
else:
i+=1
if(prints):
if urls.__len__() < 1:
print('No URL\'s found')
else:
print('URL')
print('===')
for url in urls:
print(url)
print('')
inputs = pageDiscovery.getInput()
if inputs.__len__() < 1:
print('No inputs found')
else:
print('Input ID')
print('=======')
for i in inputs:
print(i)
print('')
for url in urls + queryUrl:
parseUrlForInput(url)
if queryDict.__len__() < 1:
print('No query string inputs')
else:
print('Query strings')
print('=======')
for key, value in queryDict.items():
print('Query strings for ' + key)
print('=======')
for i in value:
print(i)
print('')
def testHelper():
global randomFuzz
global vector
global fuzzerSession
global slowLinks
global responseCodeLinks
global slow
global queryDict
seconds = int(slow) / 1000
if randomFuzz == 1:
#insert randomization here
while(True):
randomUrlInt = random.randrange(0, urls.__len__()+1)
randomUrl = urls[randomUrlInt]
if pageDiscovery.getInputDict(randomUrl) != -1:
break
randomInputInt = random.randrange(0, len(pageDiscovery.getInputDict(randomUrl))+1)
randomInput = pageDiscovery.getInputDict(randomUrl)[randomInputInt]
for vectorData in vector:
payload = {randomInput: vectorData}
#send POST Ruquest here
try:
r = fuzzerSession.post(randomUrl, data=payload, timeout=seconds)
if r.status_code != 200:
responseCodeLinks.append(randomUrl)
else:
html = r.text
sensitiveDataChecker(randomUrl, html)
checkSanatization(randomUrl, html, vectorData)
except ConnectionError as e:
pass
except MissingSchema as m:
pass
except ReadTimeout as t:
slowLinks.append(randomUrl)
elif randomFuzz == 0:
for url in urls:
if pageDiscovery.getInputDict(url) != -1:
for inputs in pageDiscovery.getInputDict(url):
for vectorData in vector:
payload = {inputs: vectorData}
#send POST Request here
try:
r = fuzzerSession.post(url, data=payload, timeout=seconds)
if r.status_code != 200:
responseCodeLinks.append(url)
else:
html = r.text
sensitiveDataChecker(url, html)
checkSanatization(url, html, vectorData)
except ConnectionError as e:
pass
except MissingSchema as m:
pass
except ReadTimeout as t:
slowLinks.append(url)
if url in queryDict:
for query in queryDict[url]:
for vectorData in vector:
newUrl = replaceQueryStrings(url, vectorData)
if newUrl != "":
try:
r = fuzzerSession.get(url, timeout=seconds)
if r.status_code != 200:
responseCodeLinks.append(url)
else:
html = r.text
sensitiveDataChecker(url, html)
checkSanatization(url, html, vectorData)
except ConnectionError as e:
pass
except MissingSchema as m:
pass
except ReadTimeout as t:
slowLinks.append(url)
printTest()
def cookieFinder(sess):
cookies = sess.cookies
if cookies.__len__() < 1:
print('No cookies')
else:
print('Cookie Name \t Cookie Value')
print('=============================')
for c in cookies:
print(c.name + '\t\t\t\t' + c.value)
print('')
def parseUrlForInput(url):
global queryDict
result = urlparse(url)
#should be in the form: query=something
queryString = result.query
key = url
if queryString != '':
if key not in queryDict:
queryDict[key] = []
queryAry = queryString.split('&')
for q in queryAry:
qStr = q.partition('=')
#should return the "query" component
queryDict[key].append(qStr[0])
def guessPages():
global commonWords
for word in commonWords:
if domain[-1] == '/':
for ext in pageExtensions:
urlGuess = domain + word + ext
try:
r = requests.get(urlGuess, timeout=3)
if r.status_code == 200:
urls.append(urlGuess)
except ConnectionError as e:
pass
except MissingSchema as m:
pass
except ReadTimeout as t:
pass
else:
for ext in pageExtensions:
urlGuess = domain + '/' + word + ext
try:
r = requests.get(urlGuess, timeout=3)
if r.status_code == 200:
urls.append(urlGuess)
except ConnectionError as e:
pass
except MissingSchema as m:
pass
except ReadTimeout as t:
pass
def sensitiveDataChecker(testUrl, html):
global sensitiveWords
global fuzzerSession
global SensitiveDataLinks
for word in sensitiveWords:
if word in html:
sensitiveDataLinks.append(testUrl)
def checkSanatization(url, html, vectorData):
global unsanitizedLinks
before = ["<",">","&",'"']
after = ["<",">","&","""]
for each in before:
if each in vectorData:
if vectorData in html:
unsanitizedLinks.append(url)
def replaceQueryStrings(url, data):
result = urlparse(url)
#should be in the form: query=something
queryString = result.query
if queryString != '':
queryAry = queryString.split('&')
count = 0
for q in queryAry:
old = q
qStr = q.partition('=')
new = qStr[0] + "=" + data[count]
url.replace(old, new)
count += 1
return url
else:
return ""
def printTest():
global urls
global slowLinks
global responseCodeLinks
global sensitiveDataLinks
global unsanitizedLinks
print("\n")
for url in urls:
if(url in (slowLinks + responseCodeLinks + sensitiveDataLinks + unsanitizedLinks)):
print(url)
if url in slowLinks:
print("This url timed out when fuzzed")
if url in responseCodeLinks:
print("The response code was not 200 when fuzzed")
if url in sensitiveDataLinks:
print("Senesitive data may have been leaked")
if url in unsanitizedLinks:
print("The input was not sanitized")
print("\n")
main()