Skip to content

Commit

Permalink
Refactor UI component creation
Browse files Browse the repository at this point in the history
This change adds new classes for user interface generation
to be more understandable for developers.
  • Loading branch information
rammarj committed Apr 12, 2023
1 parent 446cca2 commit 4ea7c66
Show file tree
Hide file tree
Showing 14 changed files with 313 additions and 242 deletions.
10 changes: 5 additions & 5 deletions src/main/java/burp/BurpExtender.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package burp;

import burp.burptab.ITabImpl;
import burp.burptab.PocCreatorTab;
import burp.burptab.PocTabManager;
import burp.pocs.Pocs;
import burp.tab.TabImpl;
import burp.tab.PocCreatorTab;
import burp.tab.PocTabManager;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
Expand Down Expand Up @@ -38,8 +39,7 @@ public void registerExtenderCallbacks(IBurpExtenderCallbacks ibec) {
this.pocTabManager = new PocTabManager();
ibec.registerContextMenuFactory(this);
ibec.setExtensionName("CSRF PoC Creator");
BurpExtender.burpExtenderCallbacks.addSuiteTab(new ITabImpl("CSRF PoC", this.pocTabManager));
Pocs.initialize();
BurpExtender.burpExtenderCallbacks.addSuiteTab(new TabImpl("CSRF PoC", this.pocTabManager));
// add menus
Iterator<String> pocKeys = Pocs.getPocKeys();
while (pocKeys.hasNext()) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/burp/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public Header(String name, String value) {
* @param header the string to parse (name:value)
* @return The header object created
*/
public static Header build(String header){
if(header == null)
throw new NullPointerException("header must not be null");
public static Header parse(String header){
String[] split = header.split(":");
String name = split[0].trim(), value="";
if (split.length > 1) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/burp/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Util {
public static String escape(String escape){
return escape.replace("\\", "\\\\").replace("\"", "\\\"");
}

/**
* Generates a random string (for Multipart requests)
* @param lenght the char number of the random string
Expand Down Expand Up @@ -55,9 +56,9 @@ public static String joinParameters(List<Parameter> p) {
* @param headers the string to build
* @return a list of Header objects
*/
public static List<Header> parseHeaderList(List<String> headers){
public static List<Header> parseHeaders(List<String> headers){
List<Header> a = new LinkedList<>();
headers.stream().map(next -> Header.build(next)).forEach(build -> {
headers.stream().map(next -> Header.parse(next)).forEach(build -> {
a.add(build);
});
return a;
Expand Down
173 changes: 0 additions & 173 deletions src/main/java/burp/burptab/PocCreatorTab.java

This file was deleted.

10 changes: 5 additions & 5 deletions src/main/java/burp/pocs/AjaxPoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ public byte[] getPoc(final IHttpRequestResponse request) {
pocString.append(" xhr.open(\"").append(method).append("\", \"");

if ("GET".equals(method)) {
pocString.append(request.getHttpService()).append("\", true);").append(lineSeparator);
pocString.append(requestInfo.getUrl()).append("\", true);").append(lineSeparator);
pocString.append(" xhr.send();\n");
} else {
pocString.append(requestInfo.getUrl().toString()).append("\", true);").append(lineSeparator);
String body = iexHelpers.bytesToString(request.getRequest()).substring(requestInfo.getBodyOffset());
body = Util.escape(body);
String accept = "xt/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
String accept = "*/*";
String content = "text/plain";
for (Parameter next : Util.parseHeaderList(requestInfo.getHeaders())) {
if ("Accept".equals(next.getName())) {
for (Parameter next : Util.parseHeaders(requestInfo.getHeaders())) {
if ("Accept".equalsIgnoreCase(next.getName())) {
accept = next.getValue();
}
if ("Content-Type".equals(next.getName())) {
if ("Content-Type".equalsIgnoreCase(next.getName())) {
content = next.getValue();
}
}
Expand Down
72 changes: 33 additions & 39 deletions src/main/java/burp/pocs/Pocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,40 @@

/**
* Contains all types of PoC's supported by this plugin.
*
* @author Joaquin R. Martinez <[email protected]>
*/
public class Pocs {

private static final Map<String, IPoc> POCS = new HashMap<>() ;
private static Pocs poc = null;

/**
* Inaccesible constructor.
*/
private Pocs() {
Pocs.POCS.put("Ajax",new AjaxPoc());
Pocs.POCS.put("HTML",new HtmlPoc());
// Add more kind of PoC's
}

/**
* Initializes the types of pocs supported.
*/
public static void initialize(){
if(poc == null){
Pocs.poc = new Pocs();
}
}

/**
* Get the {@link IPoc} object by its key.
* @param key the key of the {@link IPoc}.
* @return the {@link IPoc} object.
*/
public static IPoc getPoc(String key) {
return Pocs.POCS.get(key);
}

/**
* Get the {@link IPoc} as a {@link Enumeration}.
* @return an {@link Iterator} with the keys of all {@link IPoc} objects.
*/
public static Iterator<String> getPocKeys(){
return Pocs.POCS.keySet().iterator();
}


private static final Map<String, IPoc> POCS = new HashMap<>();
static Pocs poc = new Pocs();

/**
* Inaccesible constructor.
*/
private Pocs() {
Pocs.POCS.put("Ajax", new AjaxPoc());
Pocs.POCS.put("HTML", new HtmlPoc());
// Add more kind of PoC's
}

/**
* Get the {@link IPoc} object by its key.
*
* @param key the key of the {@link IPoc}.
* @return the {@link IPoc} object.
*/
public static IPoc getPoc(String key) {
return Pocs.POCS.get(key);
}

/**
* Get the {@link IPoc} as a {@link Enumeration}.
*
* @return an {@link Iterator} with the keys of all {@link IPoc} objects.
*/
public static Iterator<String> getPocKeys() {
return Pocs.POCS.keySet().iterator();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

package burp.burptab;
package burp.tab;

import java.awt.Color;
import java.awt.Component;
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/burp/tab/MessageEditorController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package burp.tab;

import burp.BurpExtender;
import burp.IHttpRequestResponse;
import burp.IHttpService;
import burp.IHttpServiceImpl;
import burp.IMessageEditor;
import burp.IMessageEditorController;
import burp.IRequestInfo;

public class MessageEditorController implements IMessageEditorController {

private IHttpRequestResponse request;
private IMessageEditor messageEditor;

public MessageEditorController(IHttpRequestResponse request, IMessageEditor messageEditor) {
this.request = request;
this.messageEditor = messageEditor;
}

@Override
public IHttpService getHttpService() {
IRequestInfo analyzeRequest = BurpExtender.getBurpExtenderCallbacks().getHelpers().analyzeRequest(this.request);
return new IHttpServiceImpl(analyzeRequest);
}

@Override
public byte[] getRequest() {
return messageEditor.getMessage();
}

@Override
public byte[] getResponse() {
return this.request.getResponse();
}
}
Loading

0 comments on commit 4ea7c66

Please sign in to comment.