Skip to content

Commit

Permalink
Fix LogEntry to store both the final request and response.
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreyD97 committed Sep 29, 2022
1 parent 176812d commit 9e22898
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 205 deletions.
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ repositories {
dependencies {
compileOnly 'net.portswigger.burp.extender:burp-extender-api:2.3'
// compileOnly 'net.portswigger.burp.extender:montoya-api:0.9.5'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'

implementation 'org.swinglabs:swingx:1.6.1'
implementation 'com.github.CoreyD97:BurpExtenderUtilities:e800fd2d'
implementation 'com.google.code.gson:gson:2.8.2'
Expand All @@ -22,11 +25,13 @@ dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.17.0'
}

jar{
jar {
baseName = project.name
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

from {
(configurations.runtimeClasspath).collect { it.isDirectory() ? it : zipTree(it) }
}{
} {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ protected Void doInBackground() throws Exception {
JsonObject jsonEntry = new JsonObject();
if (includeRequest) {
jsonEntry.addProperty("request",
encoder.encodeToString(entry.requestResponse.getRequest()));
encoder.encodeToString(entry.getRequest()));
}

if (includeResponse) {
jsonEntry.addProperty("response",
encoder.encodeToString(entry.requestResponse.getResponse()));
encoder.encodeToString(entry.getResponse()));
}
jsonEntries.add(jsonEntry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ public void write(JsonWriter writer, List<LogEntry> logEntries) throws IOExcepti

final String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
writer.name("startedDateTime").value(simpleDateFormat.format(logEntry.requestDateTime));
writer.name("startedDateTime").value(simpleDateFormat.format(logEntry.getRequestDateTime()));

long time = logEntry.responseDateTime.getTime() - logEntry.requestDateTime.getTime();
long time = logEntry.getResponseDateTime().getTime() - logEntry.getRequestDateTime().getTime();
time = time < 0 ? 0 : time;
writer.name("time").value(time);
writer.name("request").beginObject();
writer.name("method").value(logEntry.method);
writer.name("url").value(logEntry.url.toString());
writer.name("httpVersion").value(logEntry.requestHttpVersion);
writer.name("origin").value(logEntry.origin);
writer.name("method").value(logEntry.getMethod());
writer.name("url").value(logEntry.getUrl().toString());
writer.name("httpVersion").value(logEntry.getRequestHttpVersion());
writer.name("origin").value(logEntry.getOrigin());

writer.name("cookies").beginArray();
if (logEntry.hasCookieParam) {
List<IParameter> cookies = getRequestParametersByType(logEntry.requestResponse.getRequest(),
if (logEntry.isHasCookieParam()) {
List<IParameter> cookies = getRequestParametersByType(logEntry.getRequest(),
IParameter.PARAM_COOKIE);
for (IParameter cookie : cookies) {
writer.beginObject();
Expand All @@ -78,7 +78,7 @@ public void write(JsonWriter writer, List<LogEntry> logEntries) throws IOExcepti
writer.endArray(); // end request cookies array

writer.name("headers").beginArray();
for (String headerString : logEntry.requestHeaders) {
for (String headerString : logEntry.getRequestHeaders()) {
if (headerString.contains(":")) {
writer.beginObject();
String headerArray[] = headerString.split(":", 2);
Expand All @@ -90,8 +90,8 @@ public void write(JsonWriter writer, List<LogEntry> logEntries) throws IOExcepti
writer.endArray(); // end request headers array

writer.name("queryString").beginArray();
if (logEntry.url.getQuery() != null) {
List<IParameter> queryParams = getRequestParametersByType(logEntry.requestResponse.getRequest(),
if (logEntry.getUrl().getQuery() != null) {
List<IParameter> queryParams = getRequestParametersByType(logEntry.getRequest(),
IParameter.PARAM_URL);
for (IParameter queryParam : queryParams) {
writer.beginObject();
Expand All @@ -102,10 +102,10 @@ public void write(JsonWriter writer, List<LogEntry> logEntries) throws IOExcepti
}
writer.endArray(); // end request queryString array

if (logEntry.hasBodyParam) {
if (logEntry.isHasBodyParam()) {
writer.name("postData").beginObject();
writer.name("mimeType").value(logEntry.requestContentType);
List<IParameter> bodyParams = getRequestBodyParameters(logEntry.requestResponse.getRequest());
writer.name("mimeType").value(logEntry.getRequestContentType());
List<IParameter> bodyParams = getRequestBodyParameters(logEntry.getRequest());
writer.name("params").beginArray();
for (IParameter bodyParam : bodyParams) {
writer.beginObject();
Expand All @@ -118,19 +118,19 @@ public void write(JsonWriter writer, List<LogEntry> logEntries) throws IOExcepti
writer.endObject(); // end postData object
}

writer.name("headersSize").value(logEntry.requestResponse.getRequest().length - logEntry.requestBodyLength);
writer.name("bodySize").value(logEntry.requestBodyLength);
writer.name("headersSize").value(logEntry.getRequest().length - logEntry.getRequestBodyLength());
writer.name("bodySize").value(logEntry.getRequestBodyLength());

writer.endObject(); // end request object

writer.name("response").beginObject();
writer.name("status").value(logEntry.responseStatus);
writer.name("statusText").value(logEntry.responseStatusText);
writer.name("httpVersion").value(logEntry.responseHttpVersion);
writer.name("status").value(logEntry.getResponseStatus());
writer.name("statusText").value(logEntry.getResponseStatusText());
writer.name("httpVersion").value(logEntry.getResponseHttpVersion());

writer.name("cookies").beginArray();
if (logEntry.hasSetCookies) {
List<ICookie> cookies = getResponseCookies(logEntry.requestResponse.getResponse());
if (logEntry.isHasSetCookies()) {
List<ICookie> cookies = getResponseCookies(logEntry.getResponse());

for (ICookie cookie : cookies) {
writer.beginObject();
Expand All @@ -144,8 +144,8 @@ public void write(JsonWriter writer, List<LogEntry> logEntries) throws IOExcepti
writer.endArray(); // end response cookies array

writer.name("headers").beginArray();
if (logEntry.responseHeaders != null) {
for (String headerString : logEntry.responseHeaders) {
if (logEntry.getResponseHeaders() != null) {
for (String headerString : logEntry.getResponseHeaders()) {
if (headerString.contains(":")) {
writer.beginObject();
String headerArray[] = headerString.split(":", 2);
Expand All @@ -158,18 +158,18 @@ public void write(JsonWriter writer, List<LogEntry> logEntries) throws IOExcepti
writer.endArray(); // end response headers array

writer.name("redirectURL").value(String.valueOf(logEntry.getValueByKey(LogEntryField.REDIRECT_URL)));
if (logEntry.requestResponse.getResponse() != null) {
writer.name("headersSize").value(logEntry.requestResponse.getResponse().length - logEntry.responseBodyLength);
writer.name("bodySize").value(logEntry.responseBodyLength);
if (logEntry.getResponse() != null) {
writer.name("headersSize").value(logEntry.getResponse().length - logEntry.getResponseBodyLength());
writer.name("bodySize").value(logEntry.getResponseBodyLength());
} else {
writer.name("headersSize").value(0);
writer.name("bodySize").value(0);
}


writer.name("content").beginObject(); // start content object
writer.name("size").value(logEntry.responseBodyLength);
writer.name("mimeType").value(logEntry.responseMimeType);
writer.name("size").value(logEntry.getResponseBodyLength());
writer.name("mimeType").value(logEntry.getResponseMimeType());
writer.name("text").value(String.valueOf(logEntry.getValueByKey(LogEntryField.RESPONSE_BODY)));
writer.endObject(); //end content object

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ public void beginSearch(final Pattern pattern, final boolean inScopeOnly, final

private GrepResults processEntry(LogEntry entry, Pattern pattern, final boolean searchRequests, final boolean searchResponses) {
GrepResults grepResults = null;
if (entry.requestResponse != null) {
if (entry != null) {
grepResults = new GrepResults(entry);
if (entry.requestResponse.getRequest() != null && searchRequests) {
processMatches(grepResults, pattern, entry.requestResponse.getRequest(), true);
if (entry.getRequest() != null && searchRequests) {
processMatches(grepResults, pattern, entry.getRequest(), true);
}
if (entry.requestResponse.getResponse() != null && searchResponses) {
processMatches(grepResults, pattern, entry.requestResponse.getResponse(), false);
if (entry.getResponse() != null && searchResponses) {
processMatches(grepResults, pattern, entry.getResponse(), false);
}
}
return grepResults;
Expand All @@ -128,7 +128,7 @@ private Runnable createProcessThread(final LogEntry logEntry, final Pattern patt
return () -> {
if (Thread.currentThread().isInterrupted()) return;
GrepResults grepResults = null;
if (!inScopeOnly || LoggerPlusPlus.callbacks.isInScope(logEntry.url)) {
if (!inScopeOnly || LoggerPlusPlus.callbacks.isInScope(logEntry.getUrl())) {
grepResults = processEntry(logEntry, pattern, searchRequests, searchResponses);
}
for (GrepperListener listener : this.listeners) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.nccgroup.loggerplusplus.grepper;

import burp.IHttpRequestResponse;
import burp.IHttpRequestResponseWithMarkers;
import com.coreyd97.BurpExtenderUtilities.HistoryField;
import com.coreyd97.BurpExtenderUtilities.PanelBuilder;
import com.coreyd97.BurpExtenderUtilities.Preferences;
import com.nccgroup.loggerplusplus.logentry.LogEntry;
import com.nccgroup.loggerplusplus.logview.entryviewer.RequestViewerController;
import com.nccgroup.loggerplusplus.util.Globals;

Expand Down Expand Up @@ -83,7 +82,7 @@ public void actionPerformed(ActionEvent e) {
selectedMatch = (GrepResults.Match) selectedPath.getPath()[2];
}

IHttpRequestResponse requestResponse = grepResultEntry.getLogEntry().getRequestResponse();
LogEntry requestResponse = grepResultEntry.getLogEntry();
List<GrepResults.Match> matches;

if (selectedMatch != null) {
Expand All @@ -92,10 +91,10 @@ public void actionPerformed(ActionEvent e) {
matches = grepResultEntry.getMatches();
}

IHttpRequestResponseWithMarkers markedRequestResponse = controller.addMarkers(requestResponse, matches);
requestViewerController.setDisplayedEntity(markedRequestResponse);
requestViewerController.setDisplayedEntity(requestResponse);

//TODO Setup message editor to support highlighting. Code is ready, waiting on API support.
// IHttpRequestResponseWithMarkers markedRequestResponse = controller.addMarkers(requestResponse, matches);
//https://forum.portswigger.net/thread/eeditor-custom-highlighting-991b1a7e?CategoryId=burp-extensions
});

Expand Down
Loading

0 comments on commit 9e22898

Please sign in to comment.