@@ -101,7 +101,7 @@ public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation) {
101101 if (context == IContextMenuInvocation .CONTEXT_MESSAGE_EDITOR_REQUEST ) {
102102
103103 menu_list .add (new UpdateCookieMenu (this ));
104- if (this .config .getTmpMap (). containsKey ( "UsedCookie" ) ){
104+ if (this .config .getUsedCookie ()!= null ){
105105 menu_list .add (new UpdateCookieWithHistoryMenu (this ));
106106 }
107107
@@ -114,7 +114,7 @@ public List<JMenuItem> createMenuItems(IContextMenuInvocation invocation) {
114114 }
115115
116116 menu_list .add (new SetCookieMenu (this ));
117- if (this .config .getTmpMap (). containsKey ( "cookieToSetHistory" ) ){
117+ if (this .config .getUsedCookie () != null ){
118118 menu_list .add (new SetCookieWithHistoryMenu (this ));
119119 }
120120
@@ -195,17 +195,19 @@ public void processProxyMessage(boolean messageIsRequest, IInterceptedProxyMessa
195195 }
196196
197197 //当函数第一次被调用时,还没来得及设置cookie,获取到的cookieToSet必然为空。
198- String cookieToSet = config .getTmpMap (). get ( "cookieToSet" );
198+ HashMap < String , HeaderEntry > cookieToSetMap = config .getSetCookieMap ( );
199199 //stderr.println("called"+cookieToSet);
200- if (cookieToSet != null ){//第二次调用如果cookie不为空,就走到这里
201- String targetUrl = cookieToSet .split (CookieUtils .SPLITER )[0 ];
202- String originUrl = cookieToSet .split (CookieUtils .SPLITER )[1 ];
203- String cookieValue = cookieToSet .split (CookieUtils .SPLITER )[2 ];
200+ if (cookieToSetMap != null && !cookieToSetMap .isEmpty ()){//第二次调用如果cookie不为空,就走到这里
204201
205202 IHttpRequestResponse messageInfo = message .getMessageInfo ();
206203 String CurrentUrl = messageInfo .getHttpService ().toString ();
207204 //stderr.println(CurrentUrl+" "+targetUrl);
208- 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+
209211 if (messageIsRequest ) {
210212 byte [] newRequest = CookieUtils .updateCookie (messageInfo ,cookieValue );
211213 messageInfo .setRequest (newRequest );
@@ -219,9 +221,7 @@ public void processProxyMessage(boolean messageIsRequest, IInterceptedProxyMessa
219221 byte [] response = helpers .buildHttpMessage (responseHeaders ,responseBody );
220222
221223 messageInfo .setResponse (response );
222- config .getTmpMap ().remove ("cookieToSet" );//only need to set once
223- config .getTmpMap ().put ("cookieToSetHistory" ,cookieToSet );//store used cookie, change name to void change every request of host
224- //临时换名称存储,避免这个参数影响这里的逻辑,导致域名下的每个请求都会进行该操作。
224+ cookieToSetMap .remove (CurrentUrl );//only need to set once
225225 }
226226 }
227227
@@ -363,144 +363,6 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequ
363363 }
364364 }
365365
366- @ Deprecated
367- public void processHttpMessageWithEditor (int toolFlag , boolean messageIsRequest , IHttpRequestResponse messageInfo ) {
368- //messageeditor
369- synchronized (messageInfo ) {
370- if (messageIsRequest ) {
371-
372- boolean isRequestChanged = false ;
373- MessageEditor editer = new MessageEditor (messageIsRequest , messageInfo , helpers );
374-
375- URL url = editer .getURL ();
376- String path = url .getPath ();
377- String host = editer .getHost ();
378- byte [] body = editer .getBody ();
379- LinkedHashMap <String , String > headers = editer .getHeaderMap ();//this will lost the first line
380-
381-
382- //remove header
383- List <ConfigEntry > configEntries = tableModel .getConfigByType (ConfigEntry .Action_Remove_From_Headers );
384- for (ConfigEntry entry : configEntries ) {
385- String key = entry .getKey ();
386- if (headers .remove (key ) != null ) {
387- isRequestChanged = true ;
388- }
389- }
390-
391- if (config .getTmpMap ().containsKey (host )) {//自动更新cookie
392- String cookieValue = config .getTmpMap ().get (host );
393- String [] values = cookieValue .split ("::::" );
394- String trueCookie = values [1 ];
395- headers .put ("Cookie" , trueCookie );
396- isRequestChanged = true ;
397- }
398-
399- //add/update/append header
400- if (toolFlag == (toolFlag & checkEnabledFor ())) {
401- //if ((config.isOnlyForScope() && callbacks.isInScope(url))|| !config.isOnlyForScope()) {
402- if (!config .isOnlyForScope ()||callbacks .isInScope (url )){
403- try {
404- List <ConfigEntry > updateOrAddEntries = tableModel .getConfigEntries ();
405- for (ConfigEntry entry : updateOrAddEntries ) {
406- String key = entry .getKey ();
407- String value = entry .getValue ();
408-
409- if (value .contains ("%host" )) {
410- value = value .replaceAll ("%host" , host );
411- //stdout.println("3333"+value);
412- }
413-
414- if (value .toLowerCase ().contains ("%dnslogserver" )) {
415- String dnslog = tableModel .getConfigByKey ("DNSlogServer" );
416- Pattern p = Pattern .compile ("(?u)%dnslogserver" );
417- Matcher m = p .matcher (value );
418-
419- while (m .find ()) {
420- String found = m .group (0 );
421- value = value .replaceAll (found , dnslog );
422- }
423- }
424-
425- if (entry .getType ().equals (ConfigEntry .Action_Add_Or_Replace_Header ) && entry .isEnable ()) {
426- headers .put (key , value );
427- isRequestChanged = true ;
428-
429- } else if (entry .getType ().equals (ConfigEntry .Action_Append_To_header_value ) && entry .isEnable ()) {
430- value = headers .get (key ) + value ;
431- headers .put (key , value );
432- isRequestChanged = true ;
433- //stdout.println("2222"+value);
434- } else if (entry .getKey ().equalsIgnoreCase ("Chunked-AutoEnable" ) && entry .isEnable ()) {
435- headers .put ("Transfer-Encoding" , "chunked" );
436- isRequestChanged = true ;
437-
438- try {
439- boolean useComment = false ;
440- if (this .tableModel .getConfigByKey ("Chunked-UseComment" ) != null ) {
441- useComment = true ;
442- }
443- String lenStr = this .tableModel .getConfigByKey ("Chunked-Length" );
444- int len = 10 ;
445- if (lenStr != null ) {
446- len = Integer .parseInt (lenStr );
447- }
448- body = Methods .encoding (body , len , useComment );
449- editer .setBody (body );
450- } catch (UnsupportedEncodingException e ) {
451- e .printStackTrace (stderr );
452- }
453- }
454- }
455-
456-
457- ///proxy function should be here
458- //reference https://support.portswigger.net/customer/portal/questions/17350102-burp-upstream-proxy-settings-and-sethttpservice
459- String proxy = this .tableModel .getConfigByKey ("Proxy-ServerList" );
460- String mode = this .tableModel .getConfigByKey ("Proxy-UseRandomMode" );
461-
462- if (proxy != null ) {//if enable is false, will return null.
463- List <String > proxyList = Arrays .asList (proxy .split (";" ));//如果字符串是以;结尾,会被自动丢弃
464-
465- if (mode != null ) {//random mode
466- proxyServerIndex = (int ) (Math .random () * proxyList .size ());
467- //proxyServerIndex = new Random().nextInt(proxyList.size());
468- } else {
469- proxyServerIndex = (proxyServerIndex + 1 ) % proxyList .size ();
470- }
471- String proxyhost = proxyList .get (proxyServerIndex ).split (":" )[0 ].trim ();
472- int port = Integer .parseInt (proxyList .get (proxyServerIndex ).split (":" )[1 ].trim ());
473- editer .setService (
474- helpers .buildHttpService (proxyhost , port , messageInfo .getHttpService ().getProtocol ()));
475- String firstrline = editer .getFirstLineOfHeader ().replaceFirst (path , url .toString ().split ("\\ ?" ,0 )[0 ]);
476- editer .setFirstLineOfHeader (firstrline );
477- isRequestChanged = true ;
478- //success or failed,need to check?
479- }
480- } catch (Exception e ) {
481- e .printStackTrace (stderr );
482- }
483- }
484- }
485- //set final request
486- editer .setHeaderMap (headers );
487- messageInfo = editer .getMessageInfo ();
488-
489- if (isRequestChanged ) {
490- //debug
491- List <String > finalheaders = helpers .analyzeRequest (messageInfo ).getHeaders ();
492- //List<String> finalheaders = editer.getHeaderList();//error here:bodyOffset getted twice are different
493- stdout .println (System .lineSeparator () + "//////////edited request by knife//////////////" + System .lineSeparator ());
494- for (String entry : finalheaders ) {
495- stdout .println (entry );
496- }
497- }
498- }
499- }//sync
500- }
501-
502-
503-
504366 public List <String > GetSetCookieHeaders (String cookies ){
505367 if (cookies .startsWith ("Cookie: " )){
506368 cookies = cookies .replaceFirst ("Cookie: " ,"" );
0 commit comments