├── docs └── CXKCKubsej.png ├── settings.gradle ├── README.md ├── .vscode └── tasks.json └── src └── burp └── BurpExtender.java /docs/CXKCKubsej.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/honoki/burp-copy-regex-matches/HEAD/docs/CXKCKubsej.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/7.2/userguide/multi_project_builds.html 8 | */ 9 | 10 | rootProject.name = 'copy-regex-matches' -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Copy Regex Matches 2 | 3 | Copy Regex Matches is a Burp Suite plugin to copy regex matches from selected requests and/or responses to the clipboard. 4 | 5 | ## Install 6 | 7 | Download the [jar](./build/libs/copy-regex-matches-all.jar) from this repository and install in Burp Extender. 8 | 9 | ## How to use 10 | 11 | Select the requests you want to search through, right-click and go to Extensions > Regex Copy to choose whether to search through requests, responses, or both. 12 | 13 | ![](docs/CXKCKubsej.png) 14 | 15 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "gradle", 8 | "type": "shell", 9 | "command": "gradle bigjar", 10 | // "command": "gradlew.bat bigjar", // Wrapper on Windows 11 | // "command": "gradlew bigjar", // Wrapper on *nix 12 | "group": { 13 | "kind": "build", 14 | "isDefault": true 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/burp/BurpExtender.java: -------------------------------------------------------------------------------- 1 | package burp; 2 | 3 | import java.io.PrintWriter; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.regex.Matcher; 9 | import java.util.regex.Pattern; 10 | import java.util.regex.PatternSyntaxException; 11 | 12 | import javax.swing.JDialog; 13 | import javax.swing.JFrame; 14 | import javax.swing.JMenuItem; 15 | import javax.swing.JOptionPane; 16 | import java.awt.Frame; 17 | 18 | import java.awt.Toolkit; 19 | import java.awt.datatransfer.Clipboard; 20 | import java.awt.datatransfer.StringSelection; 21 | 22 | public class BurpExtender extends JDialog implements IBurpExtender, IExtensionStateListener, IContextMenuFactory { 23 | 24 | private IExtensionHelpers helpers; 25 | private PrintWriter stdout; 26 | 27 | @Override 28 | public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) { 29 | callbacks.setExtensionName("Regex Copy"); 30 | this.stdout = new PrintWriter(callbacks.getStdout(), true); 31 | this.helpers = callbacks.getHelpers(); 32 | 33 | stdout.println("Regex Copy extension initialized."); 34 | 35 | // unload resources when this extension is removed; 36 | callbacks.registerExtensionStateListener(this); 37 | 38 | // register the right-click menu: 39 | callbacks.registerContextMenuFactory(this); 40 | 41 | } 42 | 43 | private void copyRegex(IHttpRequestResponse[] selected, boolean reqs, boolean resps) { 44 | JFrame theFrame = BurpExtender.getBurpFrame(); 45 | String lookfor = JOptionPane.showInputDialog(theFrame, "Search for regex:"); 46 | 47 | ArrayList matches = new ArrayList(); 48 | 49 | try { 50 | for(IHttpRequestResponse req : selected) { 51 | if(reqs == (req.getRequest() == null) && resps == (req.getResponse() == null)) continue; 52 | String request = ""; 53 | String response = ""; 54 | if(reqs && req.getRequest() != null) request = helpers.bytesToString(req.getRequest()); 55 | if(resps && req.getResponse() != null) response = helpers.bytesToString(req.getResponse()); 56 | Matcher m = Pattern.compile(lookfor).matcher(request+response); 57 | while (m.find()) { 58 | matches.add( m.group() ); 59 | } 60 | } 61 | } catch (PatternSyntaxException err) { 62 | JOptionPane.showInputDialog(theFrame, "Invalid regex entered.\nSearch for regex:", lookfor); 63 | } 64 | 65 | String clippy = ""; 66 | for(String s : matches) { 67 | clippy += s + "\n"; 68 | } 69 | StringSelection selection = new StringSelection(clippy); 70 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 71 | clipboard.setContents(selection, selection); 72 | 73 | JOptionPane.showMessageDialog(theFrame, matches.size() + " matches copied to clipboard"); 74 | } 75 | 76 | @Override 77 | public List createMenuItems(IContextMenuInvocation invocation) { 78 | ArrayList menu = new ArrayList(); 79 | 80 | IHttpRequestResponse[] selection = invocation.getSelectedMessages(); 81 | if(selection.length < 1) { 82 | return null; 83 | } 84 | 85 | JMenuItem copyRegexReq = new JMenuItem("Copy regex matches (" + selection.length + " requests)"); 86 | JMenuItem copyRegexResp = new JMenuItem("Copy regex matches (" + selection.length + " responses)"); 87 | JMenuItem copyRegexBoth = new JMenuItem("Copy regex matches"); 88 | 89 | copyRegexReq.addActionListener(new ActionListener() { 90 | @Override 91 | public void actionPerformed(ActionEvent e) { 92 | copyRegex(selection, true, false); 93 | } 94 | }); 95 | 96 | copyRegexResp.addActionListener(new ActionListener() { 97 | @Override 98 | public void actionPerformed(ActionEvent e) { 99 | copyRegex(selection, false, true); 100 | } 101 | }); 102 | 103 | copyRegexBoth.addActionListener(new ActionListener() { 104 | @Override 105 | public void actionPerformed(ActionEvent e) { 106 | copyRegex(selection, true, true); 107 | } 108 | }); 109 | 110 | 111 | menu.add(copyRegexReq); 112 | menu.add(copyRegexResp); 113 | menu.add(copyRegexBoth); 114 | 115 | return menu; 116 | } 117 | 118 | @Override 119 | public void extensionUnloaded() { 120 | // do something 121 | } 122 | 123 | static JFrame getBurpFrame() 124 | { 125 | for(Frame f : Frame.getFrames()) 126 | { 127 | if(f.isVisible() && f.getTitle().startsWith(("Burp Suite"))) 128 | { 129 | return (JFrame) f; 130 | } 131 | } 132 | return null; 133 | } 134 | } --------------------------------------------------------------------------------