Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bit4woo committed Aug 13, 2024
1 parent e1d1f85 commit 8d54881
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 40 deletions.
9 changes: 5 additions & 4 deletions src/base/FindUrlAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public static void doSendRequest(List<String> full_urls, String refererToUse) {
} catch (Exception e) {
e.printStackTrace(BurpExtender.getStderr());
}

doRequest(inputQueue, refererToUse);
HashMap<String, String> headers = new HashMap<String,String>();
headers.put("Referer", refererToUse);
doRequest(inputQueue, headers);
} catch (Exception e1) {
e1.printStackTrace(BurpExtender.getStderr());
}
Expand Down Expand Up @@ -275,7 +276,7 @@ public static List<String> findUrls(String content) {
*
* @param inputQueue
*/
public static void doRequest(BlockingQueue<RequestTask> inputQueue, String referUrl) {
public static void doRequest(BlockingQueue<RequestTask> inputQueue, HashMap<String,String> headers) {
if (CurrentProxy == null) {
CurrentProxy = Proxy.inputProxy();
}
Expand All @@ -286,7 +287,7 @@ public static void doRequest(BlockingQueue<RequestTask> inputQueue, String refer
int max = threadNumberShouldUse(inputQueue.size());

for (int i = 0; i <= max; i++) {
threadRequester requester = new threadRequester(inputQueue, CurrentProxy.getHost(), CurrentProxy.getPort(), referUrl, i);
threadRequester requester = new threadRequester(inputQueue, CurrentProxy.getHost(), CurrentProxy.getPort(), headers, i);
requester.start();
}
}
Expand Down
68 changes: 40 additions & 28 deletions src/base/RequestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

import com.bit4woo.utilbox.burp.HelperPlus;
import com.github.kevinsawicki.http.HttpRequest;
Expand All @@ -15,72 +16,83 @@ public class RequestTask {

String url;
RequestType requestType;

static final String userAgentKey = "User-Agent";
static final String userAgentValue = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0";
static final String RefererKey = "Referer";

public RequestTask(String url,RequestType requestType) {
this.url = url;
this.requestType = requestType;
}


private static HttpRequest configHttpRequest(HttpRequest request,String proxyHost,int proxyPort,HashMap<String,String> headers) {

public static void doGetReq(String url,String proxyHost,int proxyPort,String referUrl) {
HttpRequest request = HttpRequest.get(url);
//Configure proxy
request.useProxy(proxyHost, proxyPort);
request.header("Referer", referUrl);


for (String key:headers.keySet()) {
String value =headers.get(key);
request.header(key, value);
}

if (!headers.keySet().contains(userAgentKey)) {
request.header(userAgentKey, userAgentValue);
}

//Accept all certificates
request.trustAllCerts();
//Accept all hostnames
request.trustAllHosts();

return request;
}


//TODO 使用已有请求的header?尤其是cookie
public static void doGetReq(String url,String proxyHost,int proxyPort,HashMap<String,String> headers) {
HttpRequest request = HttpRequest.get(url);
request = configHttpRequest(request,proxyHost,proxyPort,headers);
request.code();
}


public static void doPostReq(String url,String proxyHost,int proxyPort,String referUrl)
public static void doPostReq(String url,String proxyHost,int proxyPort,HashMap<String,String> headers)
{
HttpRequest postRequest = HttpRequest.post(url);
//Configure proxy
postRequest.useProxy(proxyHost, proxyPort);
postRequest.header("Referer", referUrl);
//Accept all certificates
postRequest.trustAllCerts();
//Accept all hostnames
postRequest.trustAllHosts();
postRequest = configHttpRequest(postRequest,proxyHost,proxyPort,headers);

postRequest.send("test=test");
postRequest.code();
}

public static void doPostJsonReq(String url,String proxyHost,int proxyPort,String referUrl)
public static void doPostJsonReq(String url,String proxyHost,int proxyPort,HashMap<String,String> headers)
{
HttpRequest postRequest = HttpRequest.post(url);
//Configure proxy
postRequest.useProxy(proxyHost, proxyPort);
postRequest.header("Referer", referUrl);

postRequest = configHttpRequest(postRequest,proxyHost,proxyPort,headers);


postRequest.header("Content-Type", "application/json");
//Accept all certificates
postRequest.trustAllCerts();
//Accept all hostnames
postRequest.trustAllHosts();


postRequest.send("{}");
postRequest.code();
}

public void sendRequest(String proxyHost,int proxyPort,String referUrl) {
public void sendRequest(String proxyHost,int proxyPort,HashMap<String,String> headers) {

if (referUrl ==null || referUrl.equals("")) {
referUrl = url;
if (!headers.keySet().contains(RefererKey)) {
headers.put(RefererKey, url);
}
System.out.println("send request:"+url+" using proxy:"+proxyHost+":"+proxyPort);
if (requestType == RequestType.GET) {
doGetReq(url,proxyHost,proxyPort,referUrl);
doGetReq(url,proxyHost,proxyPort,headers);
}
if (requestType == RequestType.POST) {
doPostReq(url,proxyHost,proxyPort,referUrl);
doPostReq(url,proxyHost,proxyPort,headers);
}
if (requestType == RequestType.JSON) {
doPostJsonReq(url,proxyHost,proxyPort,referUrl);
doPostJsonReq(url,proxyHost,proxyPort,headers);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/burp/threadRequester.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package burp;

import java.util.HashMap;
import java.util.concurrent.BlockingQueue;

import base.RequestTask;
Expand All @@ -8,13 +9,13 @@ public class threadRequester extends Thread {
private final BlockingQueue<RequestTask> inputQueue;
private String proxyHost;
private int proxyPort;
private String referUrl;
private HashMap<String,String> headers;

public threadRequester(BlockingQueue<RequestTask> inputQueue,String proxyHost,int proxyPort,String referUrl,int threadNo) {
public threadRequester(BlockingQueue<RequestTask> inputQueue,String proxyHost,int proxyPort,HashMap<String,String> headers,int threadNo) {
this.inputQueue = inputQueue;
this.proxyHost = proxyHost;
this.proxyPort = proxyPort;
this.referUrl = referUrl;
this.headers = headers;
this.setName(this.getClass().getName()+threadNo);
}

Expand All @@ -30,7 +31,7 @@ public void run() {
}

RequestTask task = inputQueue.take();
task.sendRequest(proxyHost,proxyPort,referUrl);
task.sendRequest(proxyHost,proxyPort,headers);
} catch (Exception error) {
error.printStackTrace(BurpExtender.getStderr());
}
Expand Down
21 changes: 17 additions & 4 deletions src/config/ProcessManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public static String getLatestHeaderFromHistory(String shortUrl, String headerNa
}
return null;
}

public static String getLatestCookieFromHistory(IHttpRequestResponse messageInfo) {
return getLatestHeaderFromHistory(messageInfo, "Cookie");
}

public static String getLatestCookieFromHistory(String shortUrl) {
return getLatestHeaderFromHistory(shortUrl, "Cookie");
}

/**
* 是否有必要从sitemap中获取,如果它是按照时间排序的话,还是有用的。后续测试一下//TODO
Expand All @@ -94,13 +102,18 @@ public static String getLatestHeaderFromSiteMap(String shortUrl, String headerNa
}
return null;
}

public static String getLatestHeaderFromSiteMap(IHttpRequestResponse messageInfo, String headerName) {
String sourceshorturl = HelperPlus.getBaseURL(messageInfo).toString();
return getLatestHeaderFromSiteMap(sourceshorturl, headerName);
}

public static String getLatestCookieFromHistory(IHttpRequestResponse messageInfo) {
return getLatestHeaderFromHistory(messageInfo, "Cookie");
public static String getLatestHeaderFromSiteMap(IHttpRequestResponse messageInfo) {
return getLatestHeaderFromSiteMap(messageInfo, "Cookie");
}

public static String getLatestCookieFromHistory(String shortUrl) {
return getLatestHeaderFromHistory(shortUrl, "Cookie");
public static String getLatestHeaderFromSiteMap(String shortUrl) {
return getLatestHeaderFromSiteMap(shortUrl, "Cookie");
}


Expand Down
4 changes: 4 additions & 0 deletions src/knife/UpdateCookieMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public void actionPerformed(ActionEvent event) {
IHttpRequestResponse[] selectedItems = invocation.getSelectedMessages();

String latestCookie = ProcessManager.getLatestCookieFromHistory(selectedItems[0]);//自行查找一次

if (!isVaildCookie(latestCookie)) {
ProcessManager.getLatestHeaderFromSiteMap(selectedItems[0]);//自行查找一次
}

//通过弹窗交互 获取Cookie
int time = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/messageTab/Info/InfoTableMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void actionPerformed(ActionEvent actionEvent) {
}
});

/**
* TODO 自动查找对应cookie并用于请求
*/
JMenuItem doRequestItem = new JMenuItem(new AbstractAction("Request URL With Burp Proxy") {
@Override
public void actionPerformed(ActionEvent actionEvent) {
Expand Down

0 comments on commit 8d54881

Please sign in to comment.