Skip to content

Commit a606ff7

Browse files
authored
Merge pull request #9 from bit4woo/dev
tuning the logic of display some menus tuning the logic of "Update Cookie" & "Set Cookie" To support multiple selection for some menus
2 parents ca486b0 + 39661fc commit a606ff7

23 files changed

+344
-296
lines changed

src/burp/BurpExtender.java

Lines changed: 33 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
import config.ConfigTable;
2020
import config.ConfigTableModel;
2121
import 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;
2232
import knife.*;
2333

2434
public 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()){

src/burp/Getter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public String getHeaderString(boolean messageIsRequest,IHttpRequestResponse mess
5757
public LinkedHashMap<String,String> getHeaderHashMap(boolean messageIsRequest,IHttpRequestResponse messageInfo) {
5858
List<String> headers = getHeaderList(messageIsRequest,messageInfo);
5959
LinkedHashMap<String,String> result = new LinkedHashMap<String, String>();
60+
if (headers.size() <=0) return result;
6061
headers.remove(0);
6162
for (String header : headers) {
6263
try {

src/burp/Utils.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package burp;
22

3+
import java.awt.Desktop;
4+
import java.net.URI;
5+
import java.net.URL;
6+
37
public class Utils {
48
public static boolean isWindows() {
59
String OS_NAME = System.getProperties().getProperty("os.name").toLowerCase();
@@ -9,4 +13,29 @@ public static boolean isWindows() {
913
return false;
1014
}
1115
}
16+
17+
18+
public static void browserOpen(Object url,String browser) throws Exception{
19+
String urlString = null;
20+
URI uri = null;
21+
if (url instanceof String) {
22+
urlString = (String) url;
23+
uri = new URI((String)url);
24+
}else if (url instanceof URL) {
25+
uri = ((URL)url).toURI();
26+
urlString = url.toString();
27+
}
28+
if(browser == null ||browser.equalsIgnoreCase("default") || browser.equalsIgnoreCase("")) {
29+
//whether null must be the first
30+
Desktop desktop = Desktop.getDesktop();
31+
if(Desktop.isDesktopSupported()&&desktop.isSupported(Desktop.Action.BROWSE)){
32+
desktop.browse(uri);
33+
}
34+
}else {
35+
Runtime runtime = Runtime.getRuntime();
36+
runtime.exec(browser+" "+urlString);
37+
//C:\Program Files\Mozilla Firefox\firefox.exe
38+
//C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe
39+
}
40+
}
1241
}

src/config/Config.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
import com.alibaba.fastjson.annotation.JSONField;
1010

1111
import burp.IBurpExtenderCallbacks;
12+
import knife.HeaderEntry;
1213

1314
public class Config {
1415

1516
private String ConfigName = "";
1617
private List<String> stringConfigEntries = new ArrayList<String>();// get from configTableModel
1718
private int enableStatus = IBurpExtenderCallbacks.TOOL_PROXY;
1819
private boolean onlyForScope = true;
19-
private HashMap<String,String> tmpMap = new HashMap<String,String>();
20+
private HashMap<String,HeaderEntry> setCookieMap = new HashMap<String,HeaderEntry>();
21+
private HeaderEntry usedCookie = null;
2022

2123
Config(){
2224
//to resolve "default constructor not found" error
@@ -58,14 +60,23 @@ public void setOnlyForScope(boolean onlyForScope) {
5860
this.onlyForScope = onlyForScope;
5961
}
6062

61-
public HashMap<String, String> getTmpMap() {
62-
return tmpMap;
63+
@JSONField(serialize=false)//表明不序列号该字段
64+
public HashMap<String, HeaderEntry> getSetCookieMap() {
65+
return setCookieMap;
66+
}
67+
@JSONField(serialize=false)//表明不序列号该字段
68+
public void setSetCookieMap(HashMap<String, HeaderEntry> setCookieMap) {
69+
this.setCookieMap = setCookieMap;
70+
}
71+
@JSONField(serialize=false)//表明不序列号该字段
72+
public HeaderEntry getUsedCookie() {
73+
return usedCookie;
74+
}
75+
@JSONField(serialize=false)//表明不序列号该字段
76+
public void setUsedCookie(HeaderEntry usedCookie) {
77+
this.usedCookie = usedCookie;
6378
}
6479

65-
public void setTmpMap(HashMap<String, String> tmpMap) {
66-
this.tmpMap = tmpMap;
67-
}
68-
6980
@JSONField(serialize=false)//表明不序列号该字段
7081
public String ToJson(){//注意函数名称,如果是get set开头,会被认为是Getter和Setter函数,会在序列化过程中被调用。
7182
return JSONObject.toJSONString(this);
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
package burp;
1+
package hackbar;
22

33
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionListener;
55
import javax.swing.JMenu;
66

7+
import burp.BurpExtender;
8+
import burp.IHttpRequestResponse;
9+
import burp.Methods;
10+
711

812
/**
913
*
@@ -26,7 +30,7 @@ public class File_Payload_Menu extends JMenu {
2630
{"PDF XSS"}
2731
};//TODO
2832

29-
File_Payload_Menu(BurpExtender burp){
33+
public File_Payload_Menu(BurpExtender burp){
3034
this.setText("File Payload");
3135
this.myburp = burp;
3236
Methods.Create_Main_Menu(this, Second_Menu, Third_MenuItems, new File_Upload_Menu_ItemListener(myburp));
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
* To change this template file, choose Tools | Templates
44
* and open the template in the editor.
55
*/
6-
package burp;
6+
package hackbar;
77

88
import java.awt.event.ActionEvent;
99
import java.awt.event.ActionListener;
1010
import java.util.Arrays;
1111
import javax.swing.JMenu;
1212

13+
import burp.BurpExtender;
14+
import burp.IHttpRequestResponse;
15+
import burp.Methods;
16+
1317
/**
1418
*
1519
* @author abdul.wahab
@@ -26,7 +30,7 @@ public class LFI_Menu extends JMenu {
2630
{"C:\\boot.ini", "C:\\WINDOWS\\win.ini", "C:\\WINDOWS\\php.ini", "C:\\WINDOWS\\System32\\Config\\SAM", "C:\\WINNT\\php.ini", "C:\\xampp\\phpMyAdmin\\config.inc", "C:\\xampp\\phpMyAdmin\\phpinfo.php", "C:\\xampp\\phpmyadmin\\config.inc.php", "C:\\xampp\\apache\\conf\\httpd.conf", "C:\\xampp\\MercuryMail\\mercury.ini", "C:\\xampp\\php\\php.ini", "C:\\xampp\\phpMyAdmin\\config.inc.php", "C:\\xampp\\tomcat\\conf\\tomcat-users.xml", "C:\\xampp\\tomcat\\conf\\web.xml", "C:\\xampp\\sendmail\\sendmail.ini", "C:\\xampp\\webalizer\\webalizer.conf", "C:\\xampp\\webdav\\webdav.txt", "C:\\xampp\\apache\\logs\\error.log", "C:\\xampp\\apache\\logs\\access.log", "C:\\xampp\\FileZillaFTP\\Logs", "C:\\xampp\\FileZillaFTP\\Logs\\error.log", "C:\\xampp\\FileZillaFTP\\Logs\\access.log", "C:\\xampp\\MercuryMail\\LOGS\\error.log", "C:\\xampp\\MercuryMail\\LOGS\\access.log", "C:\\xampp\\mysql\\data\\mysql.err", "C:\\xampp\\sendmail\\sendmail.log"}
2731
};
2832

29-
LFI_Menu(BurpExtender burp){
33+
public LFI_Menu(BurpExtender burp){
3034
this.setText("LFI");
3135
this.myburp = burp;
3236
Methods.Create_Main_Menu(this, LFI_Menu, LFIMenuItems, new LFIItemListener(myburp));

0 commit comments

Comments
 (0)