Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
URL decode support when doing replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
miroc committed Dec 17, 2016
1 parent 93d0a8d commit ba41021
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IContextMenuF
private JTextArea replaceStringField;
private JComboBox<String> replaceType;
private JTextField replaceNameStringField;
private JCheckBox replaceUrlDecodeCheckbox;
private int msgId = 0;
private int msgIdLogger = 0;

Expand Down Expand Up @@ -312,6 +313,11 @@ private void initGui() {
replaceButtonsPane.add(new JLabel("Replace/Header name:"));
replaceButtonsPane.add(replaceStringField);

replaceUrlDecodeCheckbox = new JCheckBox("", false);

replaceButtonsPane.add(new JLabel("URL decode:"));
replaceButtonsPane.add(replaceUrlDecodeCheckbox);

repCreateButton = new JButton("Add");
repCreateButton.setEnabled(false);
repFromSelectionButton = new JButton("From selection");
Expand Down Expand Up @@ -660,6 +666,10 @@ public JTextField getReplaceNameStringField() {
return replaceNameStringField;
}

public JCheckBox getReplaceUrlDecodeCheckbox() {
return replaceUrlDecodeCheckbox;
}

public MessagesTable getExtMessagesTable() {
return extMessagesTable;
}
Expand Down
2 changes: 2 additions & 0 deletions src/burp/ConfigListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ public void actionPerformed(ActionEvent actionEvent) {
extender.getExtractionTable().getSelectedRow());
Replace rep = new Replace(name, extender.getReplaceStringField().getText(),
extender.getReplaceType().getSelectedItem().toString(), ext);
rep.setUrlDecode(extender.getReplaceUrlDecodeCheckbox().isSelected());

ext.getRepRefSet().add(name);

// set rep messageId and reference to msg
Expand Down
22 changes: 12 additions & 10 deletions src/burp/Replace.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Replace {
public static String TYPE_ADD_LAST = "Add new header on last request";
public static String TYPE_REP_HEADER_LAST = "Replace header on last request";

private boolean urlDecode = false;
private String dataToPaste;
private String replaceStr;
private String id;
Expand Down Expand Up @@ -44,21 +45,13 @@ public void setReplaceStr(String replaceStr) {
this.replaceStr = replaceStr;
}

// public String replaceData(IHttpRequestResponse messageInfo, IExtensionHelpers helpers, PrintWriter stdout) {
public String replaceData(String request, IExtensionHelpers helpers) {
// String request = new String(messageInfo.getRequest());

if (type.equals(TYPE_REP_SEL) || type.equals(TYPE_REP_LAST)) {
request = request.replace(replaceStr, dataToPaste);
} else {
IRequestInfo rqInfo = helpers.analyzeRequest(request.getBytes());
List<String> headers = rqInfo.getHeaders();

//headers.add(replaceStr + ": " + dataToPaste);
// No ":" is added here, you should place it manually
//headers.add(replaceStr + dataToPaste);
// String urlDecodedDataToPaste = helpers.urlDecode(dataToPaste);

if (type.equals(TYPE_REP_HEADER_LAST)){
for (Iterator<String> iterator = headers.iterator(); iterator.hasNext();){
String header = iterator.next();
Expand All @@ -68,8 +61,9 @@ public String replaceData(String request, IExtensionHelpers helpers) {
}
}

// headers.add(replaceStr + urlDecodedDataToPaste);
headers.add(replaceStr + dataToPaste);
//headers.add(replaceStr + ": " + dataToPaste);
// No ":" is added here, you should place it manually
headers.add(replaceStr + (urlDecode ? helpers.urlDecode(dataToPaste) : dataToPaste));

String msgBody = request.substring(rqInfo.getBodyOffset());
request = new String(helpers.buildHttpMessage(headers, msgBody.getBytes()));
Expand Down Expand Up @@ -109,6 +103,14 @@ public Extraction getExt() {
return ext;
}

public boolean isUrlDecode() {
return urlDecode;
}

public void setUrlDecode(boolean urlDecode) {
this.urlDecode = urlDecode;
}

@Override
public String toString() {
return "'" + id + "', '" + type + "', '" + replaceStr + "', '" + msgId + "'";
Expand Down
3 changes: 2 additions & 1 deletion src/burp/ReplaceTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void changeSelection(int i, int i1, boolean b, boolean b1) {

extender.getReplaceNameStringField().setText(rep.getId());
extender.getReplaceStringField().setText(rep.getReplaceStr());
extender.getReplaceUrlDecodeCheckbox().setSelected(rep.isUrlDecode());

int j;
for (j = 0; j < extender.getReplaceType().getModel().getSize(); j++) {
Expand All @@ -40,4 +41,4 @@ public void setSelectionById(String id) {

changeSelection(model.getRowById(id), 0, false, false);
}
}
}

0 comments on commit ba41021

Please sign in to comment.