Skip to content

Commit

Permalink
Merge pull request #20 from augustd/fix-load-from-file
Browse files Browse the repository at this point in the history
Fix loading rules from file
  • Loading branch information
augustd authored Nov 8, 2017
2 parents 2f4596f + df427a8 commit 2625c7a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.codemagi</groupId>
<artifactId>burp-suite-utils</artifactId>
<version>1.0.10</version>
<version>1.0.11</version>
<packaging>jar</packaging>
<name>Burp Suite Utils</name>
<description>The Burp Suite Utils project provides developers with APIs for building Burp Suite Extensions.</description>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/burp/impl/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ public void setProtocol(String protocol) {
this.protocol = protocol;
}

public boolean useHttps() {
return PROTOCOL_HTTPS.equalsIgnoreCase(protocol);
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/codemagi/burp/HttpRequestThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.codemagi.burp;

import burp.IBurpExtenderCallbacks;
import burp.IHttpService;
import burp.impl.HttpService;

/**
*
Expand All @@ -38,6 +40,14 @@ public HttpRequestThread(String host, int port, boolean useHttps, byte[] request
this.callbacks = callbacks;
}

public HttpRequestThread(IHttpService service, byte[] request, IBurpExtenderCallbacks callbacks) {
this.host = service.getHost();
this.port = service.getPort();
this.useHttps = HttpService.PROTOCOL_HTTPS.equalsIgnoreCase(service.getProtocol());
this.request = request;
this.callbacks = callbacks;
}

@Override
public void run() {
synchronized(this){
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/com/codemagi/burp/RuleTableComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,22 @@ public void tableChanged(TableModelEvent e) {
private boolean loadMatchRules(String rulesUrl) {
//load match rules from file
try {
//check for file URL
if (rulesUrl != null && rulesUrl.toLowerCase().startsWith("file:")) {
return loadMatchRulesFromFile(rulesUrl);
}

//request match rules from remote URL
mCallbacks.printOutput("Loading match rules from: " + rulesUrl);
URL url = new URL(rulesUrl);
IHttpService service = new HttpService(url);
HttpRequest request = new HttpRequest(url);
IHttpRequestResponse ihrr = mCallbacks.makeHttpRequest(service, request.getBytes());
HttpRequestThread requestThread = new HttpRequestThread(service, request.getBytes(), mCallbacks);
requestThread.start();
requestThread.join();

//parse the response
byte[] responseBytes = ihrr.getResponse();
byte[] responseBytes = requestThread.getResponse();
if (responseBytes == null) return false; //no response received from server
HttpResponse response = HttpResponse.parseMessage(responseBytes);

Expand Down Expand Up @@ -166,6 +173,29 @@ private boolean loadMatchRulesFromJar(String rulesUrl) {

return false;
}

/**
* Load match rules from a file URL
*/
private boolean loadMatchRulesFromFile(String rulesUrl) {
//load match rules from a local file
try {
mCallbacks.printOutput("Loading match rules from file: " + rulesUrl);
InputStream in = new URL(rulesUrl).openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));

processMatchRules(reader);

return true;

} catch (IOException e) {
scan.printStackTrace(e);
} catch (NumberFormatException e) {
scan.printStackTrace(e);
}

return false;
}

private void processMatchRules(BufferedReader reader) throws IOException {
DefaultTableModel model = (DefaultTableModel)rules.getModel();
Expand Down

0 comments on commit 2625c7a

Please sign in to comment.