Skip to content

Commit

Permalink
fixed match and replace
Browse files Browse the repository at this point in the history
  • Loading branch information
aress31 committed Dec 23, 2023
1 parent aa6fd6d commit fb32673
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
4 changes: 0 additions & 4 deletions src/main/java/burp/MyBurpExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,5 @@ public void initialize(MontoyaApi montoyaApi) {

montoyaApi.http().registerHttpHandler(mainTabGroup.getParametersPanel());
logging.logToOutput("HTTPListener registered");

// TODO: Complete the implementation of this feature.
// montoyaApi.userInterface().registerHttpRequestEditorProvider(mainTabGroup.getParametersPanel());
// logging.logToOutput("'MessageEditorTabFactory' registered");
}
}
51 changes: 34 additions & 17 deletions src/main/java/swurg/gui/views/ParametersPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.awt.event.ItemEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import burp.api.montoya.http.message.requests.HttpRequest;

Expand All @@ -24,6 +26,7 @@
import burp.api.montoya.http.handler.RequestToBeSentAction;
import burp.api.montoya.http.handler.ResponseReceivedAction;
import burp.api.montoya.http.message.params.HttpParameter;
import burp.api.montoya.http.message.params.ParsedHttpParameter;
import burp.api.montoya.core.Annotations;
import burp.api.montoya.core.ToolType;

Expand Down Expand Up @@ -154,37 +157,51 @@ private JPanel createEastPanel() {

@Override
public RequestToBeSentAction handleHttpRequestToBeSent(HttpRequestToBeSent httpRequestToBeSent) {
Annotations annotations = httpRequestToBeSent.annotations();
if (!httpRequestToBeSent.hasParameters()) {
return RequestToBeSentAction.continueWith(httpRequestToBeSent);
}

return toolsInScope.stream()
ToolType matchingTool = toolsInScope.stream()
.filter(toolInScope -> httpRequestToBeSent.toolSource().isFromTool(toolInScope))
.findFirst()
.map(toolInScope -> RequestToBeSentAction.continueWith(updateRequestParameters(httpRequestToBeSent),
annotations))
.orElse(RequestToBeSentAction.continueWith(httpRequestToBeSent, annotations));
.orElse(null);

if (matchingTool != null) {
HttpRequest updatedHttpRequest = updateHttpRequestToBeSent(httpRequestToBeSent,
this.parametersTableModel.getHttpParameters());
return RequestToBeSentAction.continueWith(updatedHttpRequest);
}

return RequestToBeSentAction.continueWith(httpRequestToBeSent);
}

private HttpRequest updateRequestParameters(HttpRequestToBeSent httpRequestToBeSent) {
private HttpRequest updateHttpRequestToBeSent(HttpRequestToBeSent httpRequestToBeSent,
Set<MyHttpParameter> tableParameters) {
List<ParsedHttpParameter> parsedParametersToBeSent = httpRequestToBeSent.parameters();
List<HttpParameter> updatedParameters = new ArrayList<>();

httpRequestToBeSent.parameters().forEach(requestTobeSentParameter -> {
this.parametersTableModel.getHttpParameters().stream()
.filter(tableParameter -> shouldProcessParameter(requestTobeSentParameter, tableParameter))
.forEach(tableParameter -> {
updatedParameters.add(HttpParameter.parameter(requestTobeSentParameter.name(),
parsedParametersToBeSent.forEach(parsedParameterToBeSent -> {
HttpParameter parameterToBeSent = HttpParameter.parameter(
parsedParameterToBeSent.name(),
parsedParameterToBeSent.value(),
parsedParameterToBeSent.type());

tableParameters.stream()
.filter(tableHttpParameter -> parameterToBeSent.equals(tableHttpParameter.getHttpParameter())
&& tableHttpParameter.getEditedValue() != null)
.findFirst()
.ifPresent(tableParameter -> {
HttpParameter updatedParameter = HttpParameter.parameter(
parameterToBeSent.name(),
tableParameter.getEditedValue(),
requestTobeSentParameter.type()));
parameterToBeSent.type());
updatedParameters.add(updatedParameter);
});
});

return httpRequestToBeSent.withUpdatedParameters(updatedParameters);
}

private boolean shouldProcessParameter(HttpParameter httpParameterToBeSent, MyHttpParameter httpParameter) {
return httpParameterToBeSent.equals(httpParameter.getHttpParameter())
&& !httpParameterToBeSent.value().equals(httpParameter.getEditedValue());
}

@Override
public ResponseReceivedAction handleHttpResponseReceived(HttpResponseReceived responseReceived) {
return ResponseReceivedAction.continueWith(responseReceived);
Expand Down

0 comments on commit fb32673

Please sign in to comment.