From c624322af6d9d76d6593d823d3230b208e0f178e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Ram=C3=ADrez=20Mart=C3=ADnez?= Date: Thu, 13 Apr 2023 02:37:57 -0500 Subject: [PATCH] Refactor to remove static methods Removed static methods for getting ExtensionHelpers and Callbacks to make code more clear about dependencies. --- pom.xml | 4 +- src/main/java/burp/BurpExtender.java | 151 +++++++++--------- src/main/java/burp/Parameter.java | 16 +- src/main/java/burp/pocs/AjaxPoc.java | 11 +- src/main/java/burp/pocs/HtmlPoc.java | 14 +- src/main/java/burp/pocs/Pocs.java | 20 +-- .../burp/tab/MessageEditorController.java | 8 +- src/main/java/burp/tab/POCTypesComboBox.java | 8 +- src/main/java/burp/tab/PocCreatorTab.java | 27 ++-- .../java/burp/tab/buttons/CopyPOCButton.java | 7 +- .../java/burp/tab/buttons/SavePOCButton.java | 11 +- 11 files changed, 141 insertions(+), 136 deletions(-) diff --git a/pom.xml b/pom.xml index fad7c21..4f79bae 100644 --- a/pom.xml +++ b/pom.xml @@ -19,15 +19,15 @@ net.portswigger.burp.extender burp-extender-api 2.3 + provided - maven-compiler-plugin - 3.8.1 + 3.11.0 diff --git a/src/main/java/burp/BurpExtender.java b/src/main/java/burp/BurpExtender.java index e3c3c97..5aaf419 100644 --- a/src/main/java/burp/BurpExtender.java +++ b/src/main/java/burp/BurpExtender.java @@ -7,6 +7,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -21,80 +22,78 @@ */ public class BurpExtender implements IBurpExtender, IContextMenuFactory, ActionListener { - private static IBurpExtenderCallbacks burpExtenderCallbacks; - private PocTabManager pocTabManager; - private IContextMenuInvocation icMenuInvocation; - private int tabCount; - private final LinkedList menuItems; - - /**Initialize all variables needed*/ - public BurpExtender() { - this.menuItems = new LinkedList<>(); - this.tabCount = 1; - } - - @Override - public void registerExtenderCallbacks(IBurpExtenderCallbacks ibec) { - BurpExtender.burpExtenderCallbacks = ibec; - this.pocTabManager = new PocTabManager(); - ibec.registerContextMenuFactory(this); - ibec.setExtensionName("CSRF PoC Creator"); - BurpExtender.burpExtenderCallbacks.addSuiteTab(new TabImpl("CSRF PoC", this.pocTabManager)); - // add menus - Iterator pocKeys = Pocs.getPocKeys(); - while (pocKeys.hasNext()) { - String key = pocKeys.next(); - JMenuItem item = new JMenuItem(key); - item.addActionListener(BurpExtender.this); - this.menuItems.add(item); - } - BurpExtender.burpExtenderCallbacks.printOutput("Burp csrf-poc-creator plugin for Burp Suite Free loaded!"); - BurpExtender.burpExtenderCallbacks.printOutput("Created by @rammarj"); - } - /** - * Creates the menu items shown in burp suite - * @param icmi the context menu invocation - * @return List of menu items - */ - @Override - public List createMenuItems(IContextMenuInvocation icmi) { - this.icMenuInvocation = icmi; - byte invocation_context = icmi.getInvocationContext(); - if (invocation_context == IContextMenuInvocation.CONTEXT_MESSAGE_VIEWER_REQUEST - || invocation_context == IContextMenuInvocation.CONTEXT_PROXY_HISTORY - || invocation_context == IContextMenuInvocation.CONTEXT_MESSAGE_EDITOR_REQUEST) { - return menuItems; - } - return null; - } - - /**This method is executed when the "send to csrf ..." was clicked - * @param e event argument - */ - @Override - public void actionPerformed(ActionEvent e) { - IHttpRequestResponse[] selectedMessages = this.icMenuInvocation.getSelectedMessages(); - for (IHttpRequestResponse ihrr : selectedMessages) { - try { - String actionCommand = e.getActionCommand(); - IPoc poc = Pocs.getPoc(actionCommand); - byte[] pocContent = poc.getPoc(ihrr); - - PocCreatorTab pocCreatorTab = new PocCreatorTab(ihrr, pocContent); - pocCreatorTab.setSelectedItem(actionCommand); - this.pocTabManager.addTab(String.valueOf((this.tabCount++)), pocCreatorTab); - } catch (Exception ex) { - JOptionPane.showMessageDialog(this.pocTabManager, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); - } - } - } - - /** - * Get the extender callback for this plugin - * @return the extender callbacks - */ - public static IBurpExtenderCallbacks getBurpExtenderCallbacks() { - return burpExtenderCallbacks; - } - + private IBurpExtenderCallbacks burpExtenderCallbacks; + private PocTabManager pocTabManager; + private IContextMenuInvocation icMenuInvocation; + private int tabCount; + private Pocs pocs; + private List menuItems; + + /** Initialize all variables needed */ + public BurpExtender() { + this.tabCount = 1; + this.menuItems = new ArrayList<>(); + } + + @Override + public void registerExtenderCallbacks(IBurpExtenderCallbacks ibec) { + this.burpExtenderCallbacks = ibec; + this.pocTabManager = new PocTabManager(); + this.pocs = new Pocs(this.burpExtenderCallbacks.getHelpers()); + ibec.registerContextMenuFactory(this); + ibec.setExtensionName("CSRF PoC Creator"); + this.burpExtenderCallbacks.addSuiteTab(new TabImpl("CSRF PoC", this.pocTabManager)); + // add menus + Iterator pocKeys = this.pocs.getPocKeys(); + while (pocKeys.hasNext()) { + String key = pocKeys.next(); + JMenuItem item = new JMenuItem(key); + item.addActionListener(BurpExtender.this); + this.menuItems.add(item); + } + this.burpExtenderCallbacks.printOutput("Burp csrf-poc-creator plugin for Burp Suite Free loaded!"); + this.burpExtenderCallbacks.printOutput("Created by @rammarj"); + } + + /** + * Creates the menu items shown in burp suite + * + * @param icmi the context menu invocation + * @return List of menu items + */ + @Override + public List createMenuItems(IContextMenuInvocation icmi) { + this.icMenuInvocation = icmi; + byte invocation_context = icmi.getInvocationContext(); + if (invocation_context == IContextMenuInvocation.CONTEXT_MESSAGE_VIEWER_REQUEST + || invocation_context == IContextMenuInvocation.CONTEXT_PROXY_HISTORY + || invocation_context == IContextMenuInvocation.CONTEXT_MESSAGE_EDITOR_REQUEST) { + return menuItems; + } + return null; + } + + /** + * This method is executed when the "send to csrf ..." was clicked + * + * @param e event argument + */ + @Override + public void actionPerformed(ActionEvent e) { + IHttpRequestResponse[] selectedMessages = this.icMenuInvocation.getSelectedMessages(); + for (IHttpRequestResponse ihrr : selectedMessages) { + try { + String selectedPOC = e.getActionCommand(); + IPoc poc = this.pocs.getPoc(selectedPOC); + byte[] pocContent = poc.getPoc(ihrr); + + PocCreatorTab pocCreatorTab = new PocCreatorTab(this.burpExtenderCallbacks, ihrr, this.pocs, pocContent); + pocCreatorTab.setSelectedItem(selectedPOC); + this.pocTabManager.addTab(String.valueOf(this.tabCount++), pocCreatorTab); + } catch (Exception ex) { + JOptionPane.showMessageDialog(this.pocTabManager, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); + } + } + } + } diff --git a/src/main/java/burp/Parameter.java b/src/main/java/burp/Parameter.java index cedab58..0772633 100644 --- a/src/main/java/burp/Parameter.java +++ b/src/main/java/burp/Parameter.java @@ -159,19 +159,5 @@ else switch (type) { } return a.toString(); } - - /** - * Constructs a parameter from a string. - * @param t the parameter as a string. - * @return a {@link Parameter} object. - */ - public static Parameter build(String t){ - Parameter parameter = new Parameter(); - String[] split = t.split("="); - if (split.length>=2) { - parameter.setName(split[0]); - parameter.setValue(split[1]); - } - return parameter; - } + } diff --git a/src/main/java/burp/pocs/AjaxPoc.java b/src/main/java/burp/pocs/AjaxPoc.java index 0d57654..a54b2b1 100644 --- a/src/main/java/burp/pocs/AjaxPoc.java +++ b/src/main/java/burp/pocs/AjaxPoc.java @@ -14,10 +14,15 @@ * @author Joaquin R. Martinez */ public class AjaxPoc implements IPoc { + + private IExtensionHelpers helpers; + + public AjaxPoc(IExtensionHelpers helpers) { + this.helpers = helpers; + } @Override public byte[] getPoc(final IHttpRequestResponse request) { - IExtensionHelpers iexHelpers = BurpExtender.getBurpExtenderCallbacks().getHelpers(); String lineSeparator = System.lineSeparator(); StringBuilder pocString = new StringBuilder(); pocString.append("").append(lineSeparator); @@ -25,7 +30,7 @@ public byte[] getPoc(final IHttpRequestResponse request) { pocString.append("").append(lineSeparator).append("