Skip to content

Commit

Permalink
Working on adding more options, but reconnect hangs on hasNext()
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Oct 16, 2020
1 parent d3b529b commit 4795a47
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 33 deletions.
62 changes: 55 additions & 7 deletions src/burp/Multiplayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.rethinkdb.net.Result;

import java.net.URL;
import java.security.MessageDigest;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ExecutorService;
Expand All @@ -34,6 +35,8 @@ public class Multiplayer implements IHttpListener, OnEditCallback {

private Boolean ignoreScanner = true;
private Boolean sendToImpliesInProgress = true;
private Boolean overwriteDuplicates = false;
private Boolean uniqueQueryParameters = false;

private DefaultListModel<Pattern> ignoredURLPatterns = new DefaultListModel<>();

Expand Down Expand Up @@ -126,10 +129,17 @@ private void createDatabase() {

private void initalizeHistory() {
logger.debug("Initializing history ...");
Result<MultiplayerRequestResponse> result = http().run(dbConn, MultiplayerRequestResponse.class);
while (result.hasNext()) {
MultiplayerRequestResponse entry = result.next();
history.add(entry);
try {
Result<MultiplayerRequestResponse> result = http().run(dbConn, MultiplayerRequestResponse.class);
logger.debug("Got history ...");
while (result.hasNext()) {
MultiplayerRequestResponse entry = result.next();
logger.debug("Got entry: %s", entry);
history.add(entry);
}
logger.debug("Results done.");
} catch(Exception err) {
logger.error(err);
}
logger.debug("History initialized");
}
Expand Down Expand Up @@ -216,6 +226,22 @@ public void removeIgnoredURLPattern(Pattern pattern) {
public DefaultListModel<Pattern> getIgnoredURLPatterns() {
return ignoredURLPatterns;
}

public void setOverwriteDuplicates(Boolean overwriteDuplicates) {
this.overwriteDuplicates = overwriteDuplicates;
}

public Boolean getOverwriteDuplicates() {
return overwriteDuplicates;
}

public void setUniqueQueryParameters(Boolean uniqueQueryParameters) {
this.uniqueQueryParameters = uniqueQueryParameters;
}

public Boolean getUniqueQueryParameters() {
return uniqueQueryParameters;
}

// Burp HTTP Callback
@Override
Expand Down Expand Up @@ -260,8 +286,13 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequ
}
}
}

if (!reqRespExists(burpReqResp) || overwriteDuplicates) {
http().insert(reqRespToRethink(burpReqResp)).run(dbConn);
} else {
logger.debug("Ignore: duplicate request (overwrite: %s)", overwriteDuplicates);
}

http().insert(reqRespToRethink(burpReqResp)).run(dbConn);
}
}

Expand All @@ -270,7 +301,8 @@ public void reqRespRemove(String reqRespId) {
}

public Boolean reqRespExists(IHttpRequestResponse reqResp) {
return http().get(getReqRespID(reqResp)).run(dbConn) != null;
Result<Object> result = http().get(getReqRespID(reqResp)).run(dbConn);
return result.first() != null;
}

private MapObject reqRespToRethink(IHttpRequestResponse reqResp) {
Expand All @@ -293,11 +325,27 @@ private MapObject reqRespToRethink(IHttpRequestResponse reqResp) {
}

// Creates an ID for a req/resp object (METHOD>PROTOCOL>AUTHORITY>PATH)
// optionally include query as unique
private String getReqRespID(IHttpRequestResponse reqResp) {
IRequestInfo reqInfo = helpers.analyzeRequest(reqResp);
URL url = reqInfo.getUrl();
String urlParts = String.format("%s>%s>%s", url.getProtocol(), url.getAuthority(), url.getPath());
return String.format("%s>%s", reqInfo.getMethod(), urlParts);
if (uniqueQueryParameters) {
urlParts = String.format("%s>%s", urlParts, url.getQuery());
}
String rawID = String.format("%s>%s", reqInfo.getMethod(), urlParts);
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(rawID.getBytes());
StringBuilder builder = new StringBuilder();
for (byte data : md.digest()) {
builder.append(String.format("%02x", data));
}
return builder.toString();
} catch (Exception err) {
logger.error(err);
}
return "";
}

// Database Helpers
Expand Down
33 changes: 33 additions & 0 deletions src/burp/MultiplayerLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/
package burp;

import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
Expand All @@ -26,9 +30,13 @@ public class MultiplayerLogger {
));
public final IBurpExtenderCallbacks callbacks;
private String currentLevel = INFO;
private FileWriter logFile;

public MultiplayerLogger(IBurpExtenderCallbacks callbacks) {
this.callbacks = callbacks;
try {
logFile = new FileWriter("/tmp/burp-multiplayer.log");
} catch(IOException ex) {}
}

public void setLevel(String level) {
Expand All @@ -49,29 +57,54 @@ public void debug(String format, Object ... args) {
if (currentLevelIndex() <= levels.indexOf(DEBUG)) {
callbacks.printOutput(String.format(format, args));
}
try {
logFile.write(String.format(format, args));
logFile.write("\n");
logFile.flush();
} catch (IOException ex) {}
}

public void info(String format, Object ... args) {
if (currentLevelIndex() <= levels.indexOf(INFO)) {
callbacks.printOutput(String.format(format, args));
}
try {
logFile.write(String.format(format, args));
logFile.write("\n");
logFile.flush();
} catch (IOException ex) {}
}

public void warn(String format, Object ... args) {
if (currentLevelIndex() <= levels.indexOf(WARN) ) {
callbacks.printOutput(String.format(format, args));
}
try {
logFile.write(String.format(format, args));
logFile.write("\n");
logFile.flush();
} catch (IOException ex) {}
}

public void error(String format, Object ... args) {
callbacks.printError(String.format(format, args));
try {
logFile.write(String.format(format, args));
logFile.write("\n");
logFile.flush();
} catch (IOException ex) {}
}

public void error(Exception err) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
err.printStackTrace(pw);
callbacks.printError(sw.toString());
try {
logFile.write(sw.toString());
logFile.write("\n");
logFile.flush();
} catch (IOException ex) {}
}

}
13 changes: 6 additions & 7 deletions src/burp/MultiplayerRequestResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static burp.HTTPHistory.Port;
import static burp.HTTPHistory.Protocol;
import static burp.HTTPHistory.StatusCode;
import static burp.HTTPHistory.columns;
import java.net.URL;
import java.time.Instant;
import java.time.ZoneId;
Expand Down Expand Up @@ -231,17 +230,17 @@ public Object getProperty(String propertyName) {
case Comment:
return this.getComment();
case Highlight:
String highlight = this.getHighlight();
if (highlight.isBlank() || highlight.isEmpty()) {
String highlightState = this.getHighlight();
if (highlightState.isBlank() || highlightState.isEmpty()) {
return None;
}
return highlight;
return highlightState;
case Assessment:
String assessment = this.getAssessment();
if (assessment.isBlank() || assessment.isEmpty()) {
String assessmentState = this.getAssessment();
if (assessmentState.isBlank() || assessmentState.isEmpty()) {
return New;
}
return assessment;
return assessmentState;
case DateTime:
return this.getDateTime();

Expand Down
6 changes: 2 additions & 4 deletions src/burp/gui/ConnectionPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
import burp.IBurpExtenderCallbacks;
import burp.Multiplayer;
import burp.MultiplayerLogger;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;
import javax.swing.JOptionPane;

/**
*
* @author moloch
*/
public class ConnectionPanel extends javax.swing.JPanel {
public final class ConnectionPanel extends javax.swing.JPanel {

private final Multiplayer multiplayer;
private List<Runnable> onConnectCallbacks = new ArrayList<Runnable>();
private List<Runnable> onConnectCallbacks = new ArrayList<>();
private final IBurpExtenderCallbacks callbacks;
private final MultiplayerLogger logger;

Expand Down
11 changes: 7 additions & 4 deletions src/burp/gui/OptionsPane.form
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<Component id="loggingLabel" alignment="0" max="32767" attributes="0"/>
</Group>
<Component id="overwriteDuplicatesCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="includeQueryParametersCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="uniqueQueryParametersCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
Expand Down Expand Up @@ -126,7 +126,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="overwriteDuplicatesCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="includeQueryParametersCheckBox" min="-2" max="-2" attributes="0"/>
<Component id="uniqueQueryParametersCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
<Component id="loggingLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
Expand Down Expand Up @@ -336,13 +336,16 @@
<Properties>
<Property name="text" type="java.lang.String" value="Always Overwrite Duplicates"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="overwriteDuplicatesCheckBoxActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="includeQueryParametersCheckBox">
<Component class="javax.swing.JCheckBox" name="uniqueQueryParametersCheckBox">
<Properties>
<Property name="text" type="java.lang.String" value="Include Query Parameters in Unqiueness"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="includeQueryParametersCheckBoxActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="uniqueQueryParametersCheckBoxActionPerformed"/>
</Events>
</Component>
</SubComponents>
Expand Down

0 comments on commit 4795a47

Please sign in to comment.