Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public void initialize(MontoyaApi api) {
api.extension().setName(extensionName);
api.userInterface().registerContextMenuItemsProvider(new CstcContextMenuItemsProvider(api, view));
api.http().registerHttpHandler(new CstcHttpHandler(view));
api.proxy().registerRequestHandler(new CstcProxyRequestHandler(view));
api.proxy().registerResponseHandler(new CstcProxyResponseHandler(view));
api.userInterface().registerSuiteTab(extensionName, view);
api.userInterface().registerHttpRequestEditorProvider(new MyHttpRequestEditorProvider(view));
api.userInterface().registerHttpRequestEditorProvider(new MyHttpRequestEditorProviderFormatting(view));
Expand All @@ -40,8 +42,10 @@ public void initialize(MontoyaApi api) {
private void restoreRecipe(PersistedObject persistence) {
try {
this.view.getFormatRecipePanel().restoreState(persistence.getString(BurpOperation.FORMAT + "Recipe"));
this.view.getIncomingRecipePanel().restoreState(persistence.getString(BurpOperation.INCOMING + "Recipe"));
this.view.getOutgoingRecipePanel().restoreState(persistence.getString(BurpOperation.OUTGOING + "Recipe"));
this.view.getIncomingHttpResponseRecipePanel().restoreState(persistence.getString(BurpOperation.INCOMING_HTTP_RESPONSE + "Recipe"));
this.view.getIncomingProxyRequestRecipePanel().restoreState(persistence.getString(BurpOperation.INCOMING_PROXY_REQUEST + "Recipe"));
this.view.getOutgoingHttpRequestRecipePanel().restoreState(persistence.getString(BurpOperation.OUTGOING_HTTP_REQUEST + "Recipe"));
this.view.getOutgoingProxyResponseRecipePanel().restoreState(persistence.getString(BurpOperation.OUTGOING_PROXY_RESPONSE + "Recipe"));
} catch (Exception e) {
Logger.getInstance().log(
"Could not restore the recipe for one or multiple panels. If this is the first time using CSTC in a project, you can ignore this message.");
Expand Down
38 changes: 28 additions & 10 deletions src/main/java/burp/CstcContextMenuItemsProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,45 @@ public CstcContextMenuItemsProvider(MontoyaApi api, View view)
public List<Component> provideMenuItems(ContextMenuEvent event) {

List<Component> menuItems = new ArrayList<>();
JMenuItem incomingMenu = new JMenuItem("Send to CSTC (Incoming)");
JMenuItem outgoingMenu = new JMenuItem("Send to CSTC (Outgoing)");
JMenuItem incomingReqFormatMenu = new JMenuItem("Send request to CSTC (Formatting)");
JMenuItem incomingResFormatMenu = new JMenuItem("Send response to CSTC (Formatting)");
JMenuItem incomingHttpResponseMenu = new JMenuItem("Send to Incoming HTTP Responses");
JMenuItem incomingProxyRequestMenu = new JMenuItem("Send to Incoming Proxy Requests");
JMenuItem outgoingHttpRequestMenu = new JMenuItem("Send to Outgoing HTTP Requests");
JMenuItem outgoingProxyResponseMenu = new JMenuItem("Send to Outgoing Proxy Responses");
JMenuItem incomingReqFormatMenu = new JMenuItem("Send request to Formatting");
JMenuItem incomingResFormatMenu = new JMenuItem("Send response to Formatting");

menuItems.add(outgoingMenu);
menuItems.add(incomingMenu);
menuItems.add(outgoingHttpRequestMenu);
menuItems.add(outgoingProxyResponseMenu);
menuItems.add(incomingHttpResponseMenu);
menuItems.add(incomingProxyRequestMenu);
menuItems.add(incomingReqFormatMenu);
menuItems.add(incomingResFormatMenu);

incomingMenu.addActionListener(new ActionListener() {
incomingHttpResponseMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
view.getIncomingRecipePanel().setInput(event.messageEditorRequestResponse().isPresent() ? event.messageEditorRequestResponse().get().requestResponse() : event.selectedRequestResponses().get(0));
view.getIncomingHttpResponseRecipePanel().setInput(event.messageEditorRequestResponse().isPresent() ? event.messageEditorRequestResponse().get().requestResponse() : event.selectedRequestResponses().get(0));
}
});

incomingProxyRequestMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
view.getIncomingProxyRequestRecipePanel().setInput(event.messageEditorRequestResponse().isPresent() ? event.messageEditorRequestResponse().get().requestResponse() : event.selectedRequestResponses().get(0));
}
});

outgoingMenu.addActionListener(new ActionListener() {
outgoingHttpRequestMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
view.getOutgoingHttpRequestRecipePanel().setInput(event.messageEditorRequestResponse().isPresent() ? event.messageEditorRequestResponse().get().requestResponse() : event.selectedRequestResponses().get(0));
}
});

outgoingProxyResponseMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
view.getOutgoingRecipePanel().setInput(event.messageEditorRequestResponse().isPresent() ? event.messageEditorRequestResponse().get().requestResponse() : event.selectedRequestResponses().get(0));
view.getOutgoingProxyResponseRecipePanel().setInput(event.messageEditorRequestResponse().isPresent() ? event.messageEditorRequestResponse().get().requestResponse() : event.selectedRequestResponses().get(0));
}
});

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/burp/CstcHttpHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class CstcHttpHandler implements HttpHandler {

@Override
public RequestToBeSentAction handleHttpRequestToBeSent(HttpRequestToBeSent requestToBeSent) {
if (BurpUtils.getInstance().getFilterState().shouldProcess(FilterState.BurpOperation.OUTGOING, requestToBeSent.toolSource())) {
if (BurpUtils.getInstance().getFilterState().shouldProcess(FilterState.BurpOperation.OUTGOING_HTTP_REQUEST, requestToBeSent.toolSource().toolType())) {
ByteArray request = requestToBeSent.toByteArray();
ByteArray modifiedRequest = view.getOutgoingRecipePanel().bake(request, MessageType.REQUEST);
ByteArray modifiedRequest = view.getOutgoingHttpRequestRecipePanel().bake(request, MessageType.REQUEST);
return continueWith(HttpRequest.httpRequest(modifiedRequest).withService(requestToBeSent.httpService()));
}
else{
Expand All @@ -37,9 +37,9 @@ public RequestToBeSentAction handleHttpRequestToBeSent(HttpRequestToBeSent reque

@Override
public ResponseReceivedAction handleHttpResponseReceived(HttpResponseReceived responseReceived) {
if (BurpUtils.getInstance().getFilterState().shouldProcess(FilterState.BurpOperation.INCOMING, responseReceived.toolSource())) {
if (BurpUtils.getInstance().getFilterState().shouldProcess(FilterState.BurpOperation.INCOMING_HTTP_RESPONSE, responseReceived.toolSource().toolType())) {
ByteArray response = responseReceived.toByteArray();
ByteArray modifiedResponse = view.getIncomingRecipePanel().bake(response, MessageType.RESPONSE);
ByteArray modifiedResponse = view.getIncomingHttpResponseRecipePanel().bake(response, MessageType.RESPONSE);
return continueWith(HttpResponse.httpResponse(modifiedResponse));
}
else{
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/burp/CstcProxyRequestHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package burp;

import burp.api.montoya.core.ByteArray;
import burp.api.montoya.core.ToolType;
import burp.api.montoya.http.message.requests.HttpRequest;
import burp.api.montoya.proxy.http.InterceptedRequest;
import burp.api.montoya.proxy.http.ProxyRequestHandler;
import burp.api.montoya.proxy.http.ProxyRequestReceivedAction;
import burp.api.montoya.proxy.http.ProxyRequestToBeSentAction;
import de.usd.cstchef.Utils.MessageType;
import de.usd.cstchef.view.View;
import de.usd.cstchef.view.filter.FilterState;

import static burp.api.montoya.proxy.http.ProxyRequestReceivedAction.continueWith;

public class CstcProxyRequestHandler implements ProxyRequestHandler {

private View view;

public CstcProxyRequestHandler(View view) {
this.view = view;
}

@Override
public ProxyRequestReceivedAction handleRequestReceived(InterceptedRequest interceptedRequest) {
if (BurpUtils.getInstance().getFilterState().shouldProcess(FilterState.BurpOperation.INCOMING_PROXY_REQUEST, ToolType.PROXY)) {
ByteArray request = interceptedRequest.toByteArray();
ByteArray modifiedRequest = view.getIncomingProxyRequestRecipePanel().bake(request, MessageType.REQUEST);
return continueWith(HttpRequest.httpRequest(modifiedRequest).withService(interceptedRequest.httpService()));
}
else{
return continueWith(interceptedRequest);
}
}

@Override
public ProxyRequestToBeSentAction handleRequestToBeSent(InterceptedRequest interceptedRequest) {
return ProxyRequestToBeSentAction.continueWith(interceptedRequest);
}

}
41 changes: 41 additions & 0 deletions src/main/java/burp/CstcProxyResponseHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package burp;

import burp.api.montoya.core.ByteArray;
import burp.api.montoya.core.ToolType;
import burp.api.montoya.http.message.responses.HttpResponse;
import burp.api.montoya.proxy.http.InterceptedResponse;
import burp.api.montoya.proxy.http.ProxyResponseHandler;
import burp.api.montoya.proxy.http.ProxyResponseReceivedAction;
import burp.api.montoya.proxy.http.ProxyResponseToBeSentAction;
import de.usd.cstchef.Utils.MessageType;
import de.usd.cstchef.view.View;
import de.usd.cstchef.view.filter.FilterState;

import static burp.api.montoya.proxy.http.ProxyResponseToBeSentAction.continueWith;

public class CstcProxyResponseHandler implements ProxyResponseHandler {

private View view;

public CstcProxyResponseHandler(View view) {
this.view = view;
}

@Override
public ProxyResponseReceivedAction handleResponseReceived(InterceptedResponse interceptedResponse) {
return ProxyResponseReceivedAction.continueWith(interceptedResponse);
}

@Override
public ProxyResponseToBeSentAction handleResponseToBeSent(InterceptedResponse interceptedResponse) {
if (BurpUtils.getInstance().getFilterState().shouldProcess(FilterState.BurpOperation.OUTGOING_PROXY_RESPONSE, ToolType.PROXY)) {
ByteArray response = interceptedResponse.toByteArray();
ByteArray modifiedResponse = view.getOutgoingProxyResponseRecipePanel().bake(response, MessageType.RESPONSE);
return continueWith(HttpResponse.httpResponse(modifiedResponse));
}
else{
return continueWith(interceptedResponse);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public HttpRequest getRequest()
@Override
public void setRequestResponse(HttpRequestResponse requestResponse)
{
ByteArray result = view.getOutgoingRecipePanel().bake(requestResponse.request().toByteArray(), MessageType.REQUEST);
ByteArray result = view.getOutgoingHttpRequestRecipePanel().bake(requestResponse.request().toByteArray(), MessageType.REQUEST);
this.requestEditor.setContents(result);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/usd/cstchef/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public static Class<? extends Operation>[] getOperationsDevIncoming() {

public static Class<? extends Operation>[] getOperations(BurpOperation operation) {
//return BurpUtils.inBurp() ? Utils.getOperationsDev() : Utils.getOperationsDev();
if(operation == BurpOperation.INCOMING) {
if(operation == BurpOperation.INCOMING_HTTP_RESPONSE) {
return getOperationsDevIncoming();
}
else {
Expand Down
40 changes: 36 additions & 4 deletions src/main/java/de/usd/cstchef/view/RecipePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ public void actionPerformed(ActionEvent e) {
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (result == JOptionPane.OK_OPTION) {
BurpUtils.getInstance().getFilterState().setFilterMask(
RequestFilterDialog.getInstance().getFilterMask(BurpOperation.INCOMING),
RequestFilterDialog.getInstance().getFilterMask(BurpOperation.OUTGOING));
RequestFilterDialog.getInstance().getFilterMask(BurpOperation.INCOMING_HTTP_RESPONSE),
RequestFilterDialog.getInstance().getFilterMask(BurpOperation.INCOMING_PROXY_REQUEST),
RequestFilterDialog.getInstance().getFilterMask(BurpOperation.OUTGOING_HTTP_REQUEST),
RequestFilterDialog.getInstance().getFilterMask(BurpOperation.OUTGOING_PROXY_RESPONSE));
}
BurpUtils.getInstance().getView().preventRaceConditionOnVariables();
BurpUtils.getInstance().getView().updateInactiveWarnings();
Expand Down Expand Up @@ -399,7 +401,22 @@ public void actionPerformed(ActionEvent e) {
}

public void disableAutobakeIfFilterActive() {
for(Boolean b : BurpUtils.getInstance().getFilterState().getIncomingFilterSettings().values()) {
for(Boolean b : BurpUtils.getInstance().getFilterState().getIncomingHttpResponseFilterSettings().values()) {
if(b) {
this.autoBake = false;
this.bakeCheckBox.setSelected(false);
this.bakeButton.setEnabled(true);
this.bakeCheckBox.setEnabled(false);
this.bakeCheckBox.setToolTipText("Auto bake is disabled if Filter is active.");
return;
}
else if(!this.bakeCheckBox.isEnabled() && !b) {
this.bakeCheckBox.setEnabled(true);
this.bakeCheckBox.setToolTipText("");
}
}

for(Boolean b : BurpUtils.getInstance().getFilterState().getIncomingProxyRequestFilterSettings().values()) {
if(b) {
this.autoBake = false;
this.bakeCheckBox.setSelected(false);
Expand All @@ -414,7 +431,22 @@ else if(!this.bakeCheckBox.isEnabled() && !b) {
}
}

for(Boolean b : BurpUtils.getInstance().getFilterState().getOutgoingFilterSettings().values()) {
for(Boolean b : BurpUtils.getInstance().getFilterState().getOutgoingHttpRequestFilterSettings().values()) {
if(b) {
this.autoBake = false;
this.bakeCheckBox.setSelected(false);
this.bakeButton.setEnabled(true);
this.bakeCheckBox.setEnabled(false);
this.bakeCheckBox.setToolTipText("Auto bake is disabled if Filter is active.");
return;
}
else if(!this.bakeCheckBox.isEnabled() && !b) {
this.bakeCheckBox.setEnabled(true);
this.bakeCheckBox.setToolTipText("");
}
}

for(Boolean b : BurpUtils.getInstance().getFilterState().getOutgoingProxyResponseFilterSettings().values()) {
if(b) {
this.autoBake = false;
this.bakeCheckBox.setSelected(false);
Expand Down
39 changes: 33 additions & 6 deletions src/main/java/de/usd/cstchef/view/RequestFilterDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public static RequestFilterDialog getInstance() {
private RequestFilterDialog() {
this.setLayout(new GridLayout(0, 3));

JPanel incomingPanel = createPanel(BurpOperation.INCOMING);
JPanel outgoingPanel = createPanel(BurpOperation.OUTGOING);
JPanel incomingHttpResponsePanel = createHttpPanel(BurpOperation.INCOMING_HTTP_RESPONSE);
JPanel incomingProxyRequestPanel = createProxyPanel(BurpOperation.INCOMING_PROXY_REQUEST);
JPanel outgoingHttpRequestPanel = createHttpPanel(BurpOperation.OUTGOING_HTTP_REQUEST);
JPanel outgoingProxyResponsePanel = createProxyPanel(BurpOperation.OUTGOING_PROXY_RESPONSE);

JPanel labelPanel = new JPanel();
labelPanel.setLayout(new GridLayout(7, 0));
Expand All @@ -43,12 +45,14 @@ private RequestFilterDialog() {

this.removeAll();
this.add(labelPanel);
this.add("Outgoing", outgoingPanel);
this.add("Incoming", incomingPanel);
this.add("Outgoing HTTP Request", outgoingHttpRequestPanel);
this.add("Incoming HTTP Response", incomingHttpResponsePanel);
this.add("Incoming Proxy Request", incomingProxyRequestPanel);
this.add("Outgoing Proxy Response", outgoingProxyResponsePanel);

}

private JPanel createPanel(BurpOperation operation) {
private JPanel createHttpPanel(BurpOperation operation) {
if (BurpUtils.getInstance().getFilterState().getFilterMask(operation).isEmpty()) {
BurpUtils.getInstance().getFilterState().getFilterMask(operation).put(new Filter(ToolType.PROXY, ToolType.PROXY.ordinal()), false);
BurpUtils.getInstance().getFilterState().getFilterMask(operation).put(new Filter(ToolType.REPEATER, ToolType.REPEATER.ordinal()), false);
Expand All @@ -60,7 +64,7 @@ private JPanel createPanel(BurpOperation operation) {

JPanel panel = new JPanel();
panel.add(new JLabel(operation.toString()));
for (Map.Entry<Filter, Boolean> entry : BurpUtils.getInstance().getFilterState().getFilterMask(operation).entrySet()) {
for (Map.Entry<Filter, Boolean> entry : BurpUtils.getInstance().getFilterState().getFilterMask(operation).entrySet()) {
Filter filter = entry.getKey();
boolean selected = entry.getValue();

Expand All @@ -78,6 +82,29 @@ public void actionPerformed(ActionEvent e) {
panel.setLayout(new GridLayout(7, 0));
return panel;
}

private JPanel createProxyPanel(BurpOperation operation) {
if (BurpUtils.getInstance().getFilterState().getFilterMask(operation).isEmpty()) {
BurpUtils.getInstance().getFilterState().getFilterMask(operation).put(new Filter(ToolType.PROXY, ToolType.PROXY.ordinal()), false);
}
JPanel panel = new JPanel();
for (Map.Entry<Filter, Boolean> entry : BurpUtils.getInstance().getFilterState().getFilterMask(operation).entrySet()) {
Filter filter = entry.getKey();
boolean selected = entry.getValue();

JCheckBox box = new JCheckBox();
box.setSelected(selected);
box.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
BurpUtils.getInstance().getFilterState().getFilterMask(operation).put(filter, box.isSelected());
}
});
panel.add(box);
}
panel.add(new JLabel(operation.toString()));
return panel;
}

public void updateFilterSettings(){
RequestFilterDialog.instance = new RequestFilterDialog();
Expand Down
Loading