Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle URL Params #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ public void actionPerformed(ActionEvent e){
int bulletSize = dialog.getByteSize();

if(bulletSize <= 0) return; // !!! EXIT HERE !!!

Optional<MessageEditorHttpRequestResponse> reqRespEditor = menuContext.getReqRespEditor();
String bullet = BulletFactory.bullet(bulletSize);
HttpRequest contextReq = menuContext.getReqResp().request();
Optional<HttpRequest> updatedReq = getRequest(contextReq, bullet);
String bullet = BulletFactory.bullet(bulletSize);
HttpRequest contextReq = menuContext.getReqResp().request();
Optional<HttpRequest> updatedReq = getRequest(contextReq, bullet);

if(updatedReq.isPresent()){
if(_isEditorEvent() && reqRespEditor.isPresent()) // if event came from an editor then replace the request
// if event came from an editor then replace the request
if(_isEditorEvent() && reqRespEditor.isPresent())
reqRespEditor.get().setRequest(updatedReq.orElse(null));
else // else if the event came from a viewer, then create a repeater tab
// else if the event came from a viewer, then create a repeater tab
else
api.repeater().sendToRepeater(updatedReq.orElse(null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public void actionPerformed(ActionEvent e){

//-------------------------------------------------------------------------
public HttpRequest getRequest(MessageEditorHttpRequestResponse reqRespEditor, String bullet){
// if selection replace selection with bullet
// if selection then replace selection with bullet
if(reqRespEditor.selectionOffsets().isPresent()) {
return RequestBuilder.build(reqRespEditor.requestResponse().request(), bullet,
reqRespEditor.selectionOffsets().get()
);
}
//else if caret insert bullet
//else if caret then insert bullet
else {
return RequestBuilder.build(
reqRespEditor.requestResponse().request(),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/model/InsertPntProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
////////////////////////////////////////
public class InsertPntProvider implements AuditInsertionPointProvider{

public InsertPntProvider(List<Integer> sizes, MontoyaApi api){
public InsertPntProvider(List<Integer> sizes, MontoyaApi montoyaApi){
bulletSizes = sizes;
this.api = api;
api = montoyaApi;
}

@Override
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/model/creators/RequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import burp.api.montoya.core.Range;
import burp.api.montoya.http.message.ContentType;
import burp.api.montoya.http.message.params.HttpParameter;
import burp.api.montoya.http.message.params.HttpParameterType;
import burp.api.montoya.http.message.params.ParsedHttpParameter;
import burp.api.montoya.http.message.requests.HttpRequest;

import java.util.ArrayList;
import java.util.List;

////////////////////////////////////////
// CLASS RequestBuilder
////////////////////////////////////////
Expand All @@ -26,19 +32,43 @@ public static HttpRequest build(HttpRequest request, String bullet, int caretPos
//-----------------------------------------------------------------------------
public static HttpRequest build(HttpRequest request, String bullet) {
ContentType type = request.contentType();


//todo: what should happen when there is a body and url parameters?
switch(type){
case URL_ENCODED -> {return addBodyParam(request, bullet);}
case JSON -> {return addJsonParam(request, bullet);}
case XML -> {return addXmlParam(request, bullet);}
case MULTIPART -> {return addMultiPartParam(request, bullet);}
case AMF -> {return padAmfWith(request, bullet);}
case UNKNOWN -> {return bestEffort(request, bullet);}
case NONE -> {return addUrlParam(request, bullet);}
default ->
throw new UnsupportedOperationException("Burp was unable to identify a content type");
}
}

//-----------------------------------------------------------------------------
private static HttpRequest addUrlParam(HttpRequest request, String bullet){
int paramLen = "bullet=".length();
HttpParameter urlParam = HttpParameter.urlParameter(
"bullet", bullet.substring(0, bullet.length() - paramLen + 1));

// extract all URL parameters as a list
List<ParsedHttpParameter> parsedParams = request.parameters(HttpParameterType.URL);

// remove the parameters from the request
request = request.withRemovedParameters(parsedParams);

// convert ParsedHttpParameter to HttpParameter
List<HttpParameter> params = new ArrayList<>(parsedParams.size() + 1);
parsedParams.forEach(p -> params.add(HttpParameter.urlParameter(p.name(), p.value())));

// append the `urlParam` to beginning of the list
params.add(0, urlParam);

return request.withAddedParameters(params);
}

//-----------------------------------------------------------------------------
private static HttpRequest addBodyParam(HttpRequest request, String bullet) {
String param = "bullet=";
Expand Down Expand Up @@ -130,6 +160,7 @@ private static HttpRequest padAmfWith(HttpRequest request, String bullet) {

//-----------------------------------------------------------------------------
private static HttpRequest bestEffort(HttpRequest request, String bullet) {
//todo: is this the best way to handle this?
String strBody = request.bodyToString();
return request.withBody(bullet.concat(strBody));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/view/BulletOptionsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public int getByteSize() {
private JPanel createOptionsPanel() {
JPanel optionsPanel = new JPanel();
optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS));
dropdown = createSizeDropdown();

dropdown = createSizeDropdown();
customSizeField = createCustomSizeField();
customSizeLabel = createCustomSizeLabel();

Expand Down
33 changes: 19 additions & 14 deletions src/main/java/view/FerretSuiteTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,37 +239,42 @@ private JScrollPane getTablePanel() {
};

// Create table model and table
JTable table = getjTable(data, columnNames);

// Set column widths based on percentage of total table width
final int totalWidth = 1000; // Assume a total table width of 1000 pixels
table.getColumnModel().getColumn(0).setPreferredWidth((int) (totalWidth * 0.15)); // 15%
table.getColumnModel().getColumn(1).setPreferredWidth((int) (totalWidth * 0.35)); // 35%
table.getColumnModel().getColumn(2).setPreferredWidth((int) (totalWidth * 0.50)); // 50%

// Wrap the table in a scroll pane and return it
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setPreferredSize(new Dimension(totalWidth, 400)); // Set preferred size for the scroll pane
return scrollPane;
}

//-----------------------------------------------------------------------------
private static JTable getjTable(Object[][] data, String[] columnNames){
DefaultTableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable(model) {
@Override
public Class<?> getColumnClass(int column) {
return String.class;
}

@Override
public boolean isCellEditable(int row, int column) {
return false; // Cells are not editable
}
};

// Enable row selection
table.setCellSelectionEnabled(true);
table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

// Set column widths based on percentage of total table width
final int totalWidth = 1000; // Assume a total table width of 1000 pixels
table.getColumnModel().getColumn(0).setPreferredWidth((int) (totalWidth * 0.15)); // 15%
table.getColumnModel().getColumn(1).setPreferredWidth((int) (totalWidth * 0.35)); // 35%
table.getColumnModel().getColumn(2).setPreferredWidth((int) (totalWidth * 0.50)); // 50%

// Wrap the table in a scroll pane and return it
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setPreferredSize(new Dimension(totalWidth, 400)); // Set preferred size for the scroll pane
return scrollPane;
return table;
}



}
////////////////////////////////////////
// END CLASS FerretSuiteTab
Expand Down