1919import config .ConfigTable ;
2020import config .ConfigTableModel ;
2121import config .GUI ;
22+ import hackbar .File_Payload_Menu ;
23+ import hackbar .LFI_Menu ;
24+ import hackbar .Reverse_Shell_Menu ;
25+ import hackbar .SQL_Error ;
26+ import hackbar .SQL_Menu ;
27+ import hackbar .SQli_LoginBypass ;
28+ import hackbar .SSTI_Menu ;
29+ import hackbar .WebShell_Menu ;
30+ import hackbar .XSS_Menu ;
31+ import hackbar .XXE_Menu ;
2232import knife .*;
2333
2434public class BurpExtender extends GUI implements IBurpExtender , IContextMenuFactory , ITab , IHttpListener ,IProxyListener ,IExtensionStateListener {
@@ -77,7 +87,12 @@ public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation) {
7787
7888
7989 byte context = invocation .getInvocationContext ();
80- menu_list .add (new DismissMenu (this ));
90+
91+ String dismissed = this .tableModel .getConfigByKey ("DismissedHost" );
92+ if (dismissed != null ) {
93+ menu_list .add (new DismissMenu (this ));
94+ }
95+
8196 menu_list .add (new AddHostToScopeMenu (this ));
8297 menu_list .add (new OpenWithBrowserMenu (this ));
8398 menu_list .add (new RunSQLMap (this ));
@@ -86,8 +101,9 @@ public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation) {
86101 if (context == IContextMenuInvocation .CONTEXT_MESSAGE_EDITOR_REQUEST ) {
87102
88103 menu_list .add (new UpdateCookieMenu (this ));
89- menu_list .add (new UpdateCookieWithHistoryMenu (this ));
90-
104+ if (this .config .getUsedCookie ()!=null ){
105+ menu_list .add (new UpdateCookieWithHistoryMenu (this ));
106+ }
91107
92108 UpdateHeaderMenu uhmenu = new UpdateHeaderMenu (this );
93109 List <String > pHeaders = uhmenu .possibleHeaderNames (invocation );
@@ -98,7 +114,10 @@ public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation) {
98114 }
99115
100116 menu_list .add (new SetCookieMenu (this ));
101- menu_list .add (new SetCookieWithHistoryMenu (this ));
117+ if (this .config .getUsedCookie () != null ){
118+ menu_list .add (new SetCookieWithHistoryMenu (this ));
119+ }
120+
102121
103122 JMenu Hack_Bar_Menu = new JMenu ("^_^ Hack Bar++" );
104123 Hack_Bar_Menu .add (new SQL_Menu (this ));
@@ -176,17 +195,19 @@ public void processProxyMessage(boolean messageIsRequest, IInterceptedProxyMessa
176195 }
177196
178197 //当函数第一次被调用时,还没来得及设置cookie,获取到的cookieToSet必然为空。
179- String cookieToSet = config .getTmpMap (). get ( "cookieToSet" );
198+ HashMap < String , HeaderEntry > cookieToSetMap = config .getSetCookieMap ( );
180199 //stderr.println("called"+cookieToSet);
181- if (cookieToSet != null ){//第二次调用如果cookie不为空,就走到这里
182- String targetUrl = cookieToSet .split (CookieUtils .SPLITER )[0 ];
183- String originUrl = cookieToSet .split (CookieUtils .SPLITER )[1 ];
184- String cookieValue = cookieToSet .split (CookieUtils .SPLITER )[2 ];
200+ if (cookieToSetMap != null && !cookieToSetMap .isEmpty ()){//第二次调用如果cookie不为空,就走到这里
185201
186202 IHttpRequestResponse messageInfo = message .getMessageInfo ();
187203 String CurrentUrl = messageInfo .getHttpService ().toString ();
188204 //stderr.println(CurrentUrl+" "+targetUrl);
189- if (targetUrl .equalsIgnoreCase (CurrentUrl )){
205+ HeaderEntry cookieToSet = cookieToSetMap .get (CurrentUrl );
206+ if (cookieToSet != null ){
207+
208+ String targetUrl = cookieToSet .getTargetUrl ();
209+ String cookieValue = cookieToSet .getHeaderValue ();
210+
190211 if (messageIsRequest ) {
191212 byte [] newRequest = CookieUtils .updateCookie (messageInfo ,cookieValue );
192213 messageInfo .setRequest (newRequest );
@@ -200,9 +221,7 @@ public void processProxyMessage(boolean messageIsRequest, IInterceptedProxyMessa
200221 byte [] response = helpers .buildHttpMessage (responseHeaders ,responseBody );
201222
202223 messageInfo .setResponse (response );
203- config .getTmpMap ().remove ("cookieToSet" );//only need to set once
204- config .getTmpMap ().put ("cookieToSetHistory" ,cookieToSet );//store used cookie, change name to void change every request of host
205- //临时换名称存储,避免这个参数影响这里的逻辑,导致域名下的每个请求都会进行该操作。
224+ cookieToSetMap .remove (CurrentUrl );//only need to set once
206225 }
207226 }
208227
@@ -344,144 +363,6 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequ
344363 }
345364 }
346365
347- @ Deprecated
348- public void processHttpMessageWithEditor (int toolFlag , boolean messageIsRequest , IHttpRequestResponse messageInfo ) {
349- //messageeditor
350- synchronized (messageInfo ) {
351- if (messageIsRequest ) {
352-
353- boolean isRequestChanged = false ;
354- MessageEditor editer = new MessageEditor (messageIsRequest , messageInfo , helpers );
355-
356- URL url = editer .getURL ();
357- String path = url .getPath ();
358- String host = editer .getHost ();
359- byte [] body = editer .getBody ();
360- LinkedHashMap <String , String > headers = editer .getHeaderMap ();//this will lost the first line
361-
362-
363- //remove header
364- List <ConfigEntry > configEntries = tableModel .getConfigByType (ConfigEntry .Action_Remove_From_Headers );
365- for (ConfigEntry entry : configEntries ) {
366- String key = entry .getKey ();
367- if (headers .remove (key ) != null ) {
368- isRequestChanged = true ;
369- }
370- }
371-
372- if (config .getTmpMap ().containsKey (host )) {//自动更新cookie
373- String cookieValue = config .getTmpMap ().get (host );
374- String [] values = cookieValue .split ("::::" );
375- String trueCookie = values [1 ];
376- headers .put ("Cookie" , trueCookie );
377- isRequestChanged = true ;
378- }
379-
380- //add/update/append header
381- if (toolFlag == (toolFlag & checkEnabledFor ())) {
382- //if ((config.isOnlyForScope() && callbacks.isInScope(url))|| !config.isOnlyForScope()) {
383- if (!config .isOnlyForScope ()||callbacks .isInScope (url )){
384- try {
385- List <ConfigEntry > updateOrAddEntries = tableModel .getConfigEntries ();
386- for (ConfigEntry entry : updateOrAddEntries ) {
387- String key = entry .getKey ();
388- String value = entry .getValue ();
389-
390- if (value .contains ("%host" )) {
391- value = value .replaceAll ("%host" , host );
392- //stdout.println("3333"+value);
393- }
394-
395- if (value .toLowerCase ().contains ("%dnslogserver" )) {
396- String dnslog = tableModel .getConfigByKey ("DNSlogServer" );
397- Pattern p = Pattern .compile ("(?u)%dnslogserver" );
398- Matcher m = p .matcher (value );
399-
400- while (m .find ()) {
401- String found = m .group (0 );
402- value = value .replaceAll (found , dnslog );
403- }
404- }
405-
406- if (entry .getType ().equals (ConfigEntry .Action_Add_Or_Replace_Header ) && entry .isEnable ()) {
407- headers .put (key , value );
408- isRequestChanged = true ;
409-
410- } else if (entry .getType ().equals (ConfigEntry .Action_Append_To_header_value ) && entry .isEnable ()) {
411- value = headers .get (key ) + value ;
412- headers .put (key , value );
413- isRequestChanged = true ;
414- //stdout.println("2222"+value);
415- } else if (entry .getKey ().equalsIgnoreCase ("Chunked-AutoEnable" ) && entry .isEnable ()) {
416- headers .put ("Transfer-Encoding" , "chunked" );
417- isRequestChanged = true ;
418-
419- try {
420- boolean useComment = false ;
421- if (this .tableModel .getConfigByKey ("Chunked-UseComment" ) != null ) {
422- useComment = true ;
423- }
424- String lenStr = this .tableModel .getConfigByKey ("Chunked-Length" );
425- int len = 10 ;
426- if (lenStr != null ) {
427- len = Integer .parseInt (lenStr );
428- }
429- body = Methods .encoding (body , len , useComment );
430- editer .setBody (body );
431- } catch (UnsupportedEncodingException e ) {
432- e .printStackTrace (stderr );
433- }
434- }
435- }
436-
437-
438- ///proxy function should be here
439- //reference https://support.portswigger.net/customer/portal/questions/17350102-burp-upstream-proxy-settings-and-sethttpservice
440- String proxy = this .tableModel .getConfigByKey ("Proxy-ServerList" );
441- String mode = this .tableModel .getConfigByKey ("Proxy-UseRandomMode" );
442-
443- if (proxy != null ) {//if enable is false, will return null.
444- List <String > proxyList = Arrays .asList (proxy .split (";" ));//如果字符串是以;结尾,会被自动丢弃
445-
446- if (mode != null ) {//random mode
447- proxyServerIndex = (int ) (Math .random () * proxyList .size ());
448- //proxyServerIndex = new Random().nextInt(proxyList.size());
449- } else {
450- proxyServerIndex = (proxyServerIndex + 1 ) % proxyList .size ();
451- }
452- String proxyhost = proxyList .get (proxyServerIndex ).split (":" )[0 ].trim ();
453- int port = Integer .parseInt (proxyList .get (proxyServerIndex ).split (":" )[1 ].trim ());
454- editer .setService (
455- helpers .buildHttpService (proxyhost , port , messageInfo .getHttpService ().getProtocol ()));
456- String firstrline = editer .getFirstLineOfHeader ().replaceFirst (path , url .toString ().split ("\\ ?" ,0 )[0 ]);
457- editer .setFirstLineOfHeader (firstrline );
458- isRequestChanged = true ;
459- //success or failed,need to check?
460- }
461- } catch (Exception e ) {
462- e .printStackTrace (stderr );
463- }
464- }
465- }
466- //set final request
467- editer .setHeaderMap (headers );
468- messageInfo = editer .getMessageInfo ();
469-
470- if (isRequestChanged ) {
471- //debug
472- List <String > finalheaders = helpers .analyzeRequest (messageInfo ).getHeaders ();
473- //List<String> finalheaders = editer.getHeaderList();//error here:bodyOffset getted twice are different
474- stdout .println (System .lineSeparator () + "//////////edited request by knife//////////////" + System .lineSeparator ());
475- for (String entry : finalheaders ) {
476- stdout .println (entry );
477- }
478- }
479- }
480- }//sync
481- }
482-
483-
484-
485366 public List <String > GetSetCookieHeaders (String cookies ){
486367 if (cookies .startsWith ("Cookie: " )){
487368 cookies = cookies .replaceFirst ("Cookie: " ,"" );
@@ -498,6 +379,7 @@ public List<String> GetSetCookieHeaders(String cookies){
498379
499380 public boolean isDismissedHost (String host ){
500381 String dissmissed = tableModel .getConfigByKey ("DismissedHost" );
382+ if (dissmissed == null ) return false ;//表示配置被禁用了
501383 String [] dissmissedHosts = dissmissed .split ("," );
502384 Iterator <String > it = Arrays .asList (dissmissedHosts ).iterator ();
503385 while (it .hasNext ()){
0 commit comments