Skip to content

Commit 91e56de

Browse files
author
wstrei
committed
Added debugging functionality
1 parent 8c8a826 commit 91e56de

File tree

12 files changed

+411
-438
lines changed

12 files changed

+411
-438
lines changed

.idea/artifacts/Burp_Extractor_jar.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 255 additions & 430 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Burp_Extractor.iml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,32 @@
77
</content>
88
<orderEntry type="inheritedJdk" />
99
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library>
12+
<CLASSES>
13+
<root url="jar://$MODULE_DIR$/lib/slf4j-log4j13-1.0.1.jar!/" />
14+
</CLASSES>
15+
<JAVADOC />
16+
<SOURCES />
17+
</library>
18+
</orderEntry>
19+
<orderEntry type="module-library" exported="">
20+
<library>
21+
<CLASSES>
22+
<root url="jar://$MODULE_DIR$/lib/log4j-core-2.11.0.jar!/" />
23+
</CLASSES>
24+
<JAVADOC />
25+
<SOURCES />
26+
</library>
27+
</orderEntry>
28+
<orderEntry type="module-library" exported="">
29+
<library>
30+
<CLASSES>
31+
<root url="jar://$MODULE_DIR$/lib/log4j-api-2.11.0.jar!/" />
32+
</CLASSES>
33+
<JAVADOC />
34+
<SOURCES />
35+
</library>
36+
</orderEntry>
1037
</component>
1138
</module>

images/contextMenu.PNG

14.3 KB
Loading

images/regexSelection.PNG

-66.1 KB
Loading
-2.06 KB
Loading

images/walkthrough.gif

-138 KB
Loading
1.77 MB
Binary file not shown.

src/burp/Extractor.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77

88
public class Extractor implements IHttpListener {
99
private ExtractorMainTab extractorMainTab;
10-
1110
private IExtensionHelpers helpers;
11+
private Logger logger;
1212

1313
public Extractor(ExtractorMainTab extractorMainTab, IBurpExtenderCallbacks callbacks) {
1414
this.extractorMainTab = extractorMainTab;
1515
this.helpers = callbacks.getHelpers();
16+
17+
this.logger = new Logger(new PrintWriter(callbacks.getStdout(), true));
18+
Logger.setLogLevel(Logger.INFO);
1619
}
1720

1821
@Override
1922
public void processHttpMessage(int toolFlag, boolean messageIsRequest, burp.IHttpRequestResponse messageInfo) {
2023
if (messageIsRequest) {
24+
logger.debug("Processing request...");
2125
byte[] requestBytes = messageInfo.getRequest();
2226
String request = this.helpers.bytesToString(requestBytes);
2327

@@ -31,12 +35,26 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, burp.IHtt
3135
if (extractorTab.requestIsInScope(url,
3236
messageInfo.getHttpService().getHost()) &&
3337
extractorTab.shouldModifyRequests()) {
38+
logger.debug("Request is in scope and Extractor tab is active.");
3439

3540
// Check if we have the necessary components to do replacement
3641
String requestSelectionRegex = extractorTab.getRequestSelectionRegex();
3742
extractedData = extractorTab.getDataToInsert();
3843
if (!extractedData.equals("") && !requestSelectionRegex.equals("")) {
44+
logger.debug("Performing replacement...");
45+
46+
// Only do this extra stuff if debugging is on
47+
if (Logger.getLogLevel() >= Logger.DEBUG) {
48+
Matcher matcher = Pattern.compile(requestSelectionRegex).matcher(request);
49+
if (matcher.find()) {
50+
logger.debug("Found a match for regex: " + requestSelectionRegex);
51+
} else {
52+
logger.debug("Did not find a match for regex: " + requestSelectionRegex);
53+
}
54+
}
55+
3956
request = request.replaceAll(requestSelectionRegex, "$1" + extractedData + "$3");
57+
logger.debug("Finished replacement.");
4058
edited = true;
4159
}
4260
}
@@ -46,6 +64,7 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, burp.IHtt
4664
}
4765
} else if (!messageIsRequest) {
4866

67+
logger.debug("Processing response...");
4968
byte[] responseBytes = messageInfo.getResponse();
5069
String response = this.helpers.bytesToString(responseBytes);
5170

@@ -56,6 +75,7 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, burp.IHtt
5675
URL url = this.helpers.analyzeRequest(messageInfo.getHttpService(), messageInfo.getRequest()).getUrl();
5776
if (extractorTab.responseIsInScope(url,
5877
messageInfo.getHttpService().getHost())) {
78+
logger.debug("Response is in scope.");
5979

6080
String regex = extractorTab.getResponseSelectionRegex();
6181

@@ -66,7 +86,10 @@ public void processHttpMessage(int toolFlag, boolean messageIsRequest, burp.IHtt
6686

6787
// If we find a match in this response, replace the current data
6888
if (matcher.find()) {
89+
logger.debug("Found a match for regex: " + regex);
6990
extractorTab.setDataToInsert(matcher.group(2));
91+
} else {
92+
logger.debug("Did not find a match for regex: " + regex);
7093
}
7194
}
7295
}

src/burp/ExtractorSelectorTab.java

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package burp;
22

33
import javax.swing.*;
4-
54
import javax.swing.table.DefaultTableModel;
65
import javax.swing.table.TableCellRenderer;
76
import javax.swing.table.TableModel;
@@ -20,6 +19,7 @@ public class ExtractorSelectorTab implements ITab {
2019
private ExtractorMainTab mainTab;
2120
private IBurpExtenderCallbacks callbacks;
2221
private int messageCount = 0;
22+
private boolean debugOn;
2323

2424
public ExtractorSelectorTab(ExtractorMainTab mainTab, IBurpExtenderCallbacks callbacks) {
2525
this.mainTab = mainTab;
@@ -33,14 +33,61 @@ public String getTabCaption() {
3333

3434
private void addButtonPanel(JPanel pane) {
3535
GridBagConstraints constraints = new GridBagConstraints();
36+
constraints.fill = GridBagConstraints.HORIZONTAL;
3637

3738
// Add set of buttons at top of response table
38-
// Add paste button
3939
JPanel upperButtonPanel = new JPanel();
4040
upperButtonPanel.setLayout(new GridBagLayout());
41-
JButton pasteButton = new JButton("Paste");
41+
42+
// Add debug button
43+
JButton debugButton = new JButton("Debug");
44+
debugButton.setBackground(Color.LIGHT_GRAY);
45+
this.debugOn = false;
4246
constraints.gridy = 0;
43-
constraints.fill = GridBagConstraints.HORIZONTAL;
47+
upperButtonPanel.add(debugButton, constraints);
48+
49+
debugButton.addMouseListener(new MouseListener() {
50+
@Override
51+
public void mouseClicked(MouseEvent e) {
52+
53+
}
54+
55+
@Override
56+
public void mousePressed(MouseEvent e) {
57+
58+
}
59+
60+
@Override
61+
public void mouseReleased(MouseEvent e) {
62+
// Change button state
63+
debugOn = !debugOn;
64+
65+
// Change button appearance
66+
if (debugOn) {
67+
debugButton.setBackground(Color.GRAY);
68+
Logger.setLogLevel(Logger.DEBUG);
69+
70+
71+
} else {
72+
debugButton.setBackground(Color.LIGHT_GRAY);
73+
Logger.setLogLevel(Logger.INFO);
74+
}
75+
}
76+
77+
@Override
78+
public void mouseEntered(MouseEvent e) {
79+
80+
}
81+
82+
@Override
83+
public void mouseExited(MouseEvent e) {
84+
85+
}
86+
});
87+
88+
// Add paste button
89+
JButton pasteButton = new JButton("Paste");
90+
constraints.gridy = 1;
4491
upperButtonPanel.add(pasteButton, constraints);
4592
pasteButton.addMouseListener(new MouseListener() {
4693
@Override
@@ -71,7 +118,7 @@ public void mouseExited(MouseEvent e) {
71118

72119
// Add remove button
73120
JButton removeButton = new JButton("Remove");
74-
constraints.gridy = 1;
121+
constraints.gridy = 2;
75122
upperButtonPanel.add(removeButton, constraints);
76123
removeButton.addMouseListener(new MouseListener() {
77124
@Override
@@ -104,7 +151,7 @@ public void mouseExited(MouseEvent e) {
104151

105152
// Add clear button
106153
JButton clearButton = new JButton("Clear");
107-
constraints.gridy = 2;
154+
constraints.gridy = 3;
108155
upperButtonPanel.add(clearButton, constraints);
109156
clearButton.addMouseListener(new MouseListener() {
110157
@Override

0 commit comments

Comments
 (0)