Skip to content

Commit

Permalink
Same tab request modification and menu cleanup
Browse files Browse the repository at this point in the history
-Change converter to modify request without adding a new tab
-Change right click menu option to appear on editable request messages
only
  • Loading branch information
egru committed Jun 5, 2015
1 parent ad21406 commit 21b0848
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
3 changes: 1 addition & 2 deletions ContentTypeConverter/src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ public class BurpExtender implements IBurpExtender
@Override
public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks)
{

IExtensionHelpers helpers = callbacks.getHelpers();

callbacks.setExtensionName("Content-Type Converter");

callbacks.registerContextMenuFactory(new Menu(callbacks, helpers));
callbacks.registerContextMenuFactory(new Menu(helpers));

}
}
52 changes: 31 additions & 21 deletions ContentTypeConverter/src/main/java/burp/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class Menu implements IContextMenuFactory {
private final IBurpExtenderCallbacks m_callbacks;
private final IExtensionHelpers m_helpers;

public Menu(IBurpExtenderCallbacks callbacks, IExtensionHelpers helpers) {
m_callbacks = callbacks;
public Menu(IExtensionHelpers helpers) {
m_helpers = helpers;
}

public List<JMenuItem> createMenuItems(final IContextMenuInvocation invocation) {
JMenuItem sendXMLToRepeater = new JMenuItem("Convert to XML and Send to Repeater");
JMenuItem sendJSONToRepeater = new JMenuItem("Convert to JSON and Send to Repeater");
List<JMenuItem> menus = new ArrayList();

if (invocation.getToolFlag() != IBurpExtenderCallbacks.TOOL_INTRUDER && invocation.getInvocationContext() != IContextMenuInvocation.CONTEXT_MESSAGE_EDITOR_REQUEST){
return menus;
}

JMenuItem sendXMLToRepeater = new JMenuItem("Convert to XML");
JMenuItem sendJSONToRepeater = new JMenuItem("Convert to JSON");
sendXMLToRepeater.addMouseListener(new MouseListener() {

public void mouseClicked(MouseEvent arg0) {
Expand All @@ -35,19 +38,21 @@ public void mouseExited(MouseEvent arg0) {


public void mousePressed(MouseEvent arg0) {
IHttpRequestResponse[] selectedMessages = invocation.getSelectedMessages();
for (IHttpRequestResponse iReqResp : selectedMessages) {
IHttpService httpService = iReqResp.getHttpService();
try {
m_callbacks.sendToRepeater(httpService.getHost(), httpService.getPort(), (httpService.getProtocol().equals("https")), Utilities.convertToXML(m_helpers, iReqResp),null);
} catch (Exception e) {
e.printStackTrace();
}
}

}


public void mouseReleased(MouseEvent arg0) {
IHttpRequestResponse iReqResp = invocation.getSelectedMessages()[0];
try {
byte[] request = Utilities.convertToXML(m_helpers, iReqResp);
if (request != null) {

iReqResp.setRequest(request);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});

Expand All @@ -67,20 +72,25 @@ public void mouseExited(MouseEvent arg0) {


public void mousePressed(MouseEvent arg0) {
IHttpRequestResponse[] selectedMessages = invocation.getSelectedMessages();
for (IHttpRequestResponse iReqResp : selectedMessages) {
IHttpService httpService = iReqResp.getHttpService();
m_callbacks.sendToRepeater(httpService.getHost(), httpService.getPort(), (httpService.getProtocol().equals("https")), Utilities.convertToJSON(m_helpers, iReqResp),null);

}
}


public void mouseReleased(MouseEvent arg0) {
IHttpRequestResponse iReqResp = invocation.getSelectedMessages()[0];
try {
byte[] request = Utilities.convertToJSON(m_helpers, iReqResp);
if (request != null) {

iReqResp.setRequest(request);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});

List<JMenuItem> menus = new ArrayList();

menus.add(sendXMLToRepeater);
menus.add(sendJSONToRepeater);
return menus;
Expand Down
18 changes: 8 additions & 10 deletions ContentTypeConverter/src/main/java/burp/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.json.XML;
import org.w3c.dom.*;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
Expand All @@ -16,15 +18,14 @@
import java.io.Writer;
import java.net.URLDecoder;
import java.util.*;
import javax.xml.parsers.*;

public class Utilities {

public static byte[] convertToXML(IExtensionHelpers helpers, IHttpRequestResponse requestResponse) throws Exception {

byte[] request = requestResponse.getRequest();

if (helpers.analyzeRequest(request).getMethod() == "GET"){
if (Objects.equals(helpers.analyzeRequest(request).getMethod(), "GET")){
request = helpers.toggleRequestMethod(request);
}

Expand All @@ -34,7 +35,7 @@ public static byte[] convertToXML(IExtensionHelpers helpers, IHttpRequestRespons

byte content_type = requestInfo.getContentType();

String body = new String(request, bodyOffset, request.length - bodyOffset);
String body = new String(request, bodyOffset, request.length - bodyOffset, "UTF-8");

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc = new Document() {
Expand Down Expand Up @@ -342,7 +343,7 @@ public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws
}

if (!success) {
return request;
return null;
} else {

List<String> headers;
Expand All @@ -357,7 +358,7 @@ public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws

headers.add("Content-Type: application/xml;charset=UTF-8");

return helpers.buildHttpMessage(headers, prettyPrint(doc).getBytes());
return helpers.buildHttpMessage(headers,prettyPrint(doc).getBytes());

}

Expand All @@ -367,7 +368,7 @@ public static byte[] convertToJSON(IExtensionHelpers helpers, IHttpRequestRespon

byte[] request = requestResponse.getRequest();

if (helpers.analyzeRequest(request).getMethod() == "GET"){
if (Objects.equals(helpers.analyzeRequest(request).getMethod(), "GET")){
request = helpers.toggleRequestMethod(request);
}

Expand Down Expand Up @@ -423,7 +424,7 @@ public static byte[] convertToJSON(IExtensionHelpers helpers, IHttpRequestRespon
}

private static Map<String,String> splitQuery(String body) throws UnsupportedEncodingException {
Map<String, String> query_pairs = new LinkedHashMap<String, String>();
Map<String, String> query_pairs = new LinkedHashMap<>();
List<String> pairs = Arrays.asList(body.split("&"));

for (String pair : pairs) {
Expand All @@ -446,7 +447,4 @@ public static String prettyPrint(Document xml) throws Exception {
tf.transform(new DOMSource(xml), new StreamResult(out));
return(out.toString());
}



}

0 comments on commit 21b0848

Please sign in to comment.