2021-06-10 22:59:27 +08:00
|
|
|
|
package burp;
|
|
|
|
|
|
|
|
|
|
|
|
import burp.action.*;
|
|
|
|
|
|
import burp.ui.MainUI;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
|
import java.awt.*;
|
2021-09-07 22:09:42 +08:00
|
|
|
|
import java.nio.charset.StandardCharsets;
|
2021-06-10 22:59:27 +08:00
|
|
|
|
import java.io.PrintWriter;
|
2021-10-21 23:42:15 +08:00
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
import java.util.List;
|
2021-06-10 22:59:27 +08:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* @author EvilChen
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEditorTabFactory, ITab {
|
2021-09-07 22:09:42 +08:00
|
|
|
|
private final MainUI main = new MainUI();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
private static PrintWriter stdout;
|
|
|
|
|
|
private IBurpExtenderCallbacks callbacks;
|
|
|
|
|
|
private static IExtensionHelpers helpers;
|
|
|
|
|
|
GetColorKey gck = new GetColorKey();
|
|
|
|
|
|
UpgradeColor uc = new UpgradeColor();
|
2021-10-21 23:42:15 +08:00
|
|
|
|
ProcessMessage pm = new ProcessMessage();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.callbacks = callbacks;
|
|
|
|
|
|
BurpExtender.helpers = callbacks.getHelpers();
|
|
|
|
|
|
|
2022-01-11 14:46:25 +08:00
|
|
|
|
String version = "2.1.3";
|
2021-06-10 22:59:27 +08:00
|
|
|
|
callbacks.setExtensionName(String.format("HaE (%s) - Highlighter and Extractor", version));
|
|
|
|
|
|
// 定义输出
|
|
|
|
|
|
stdout = new PrintWriter(callbacks.getStdout(), true);
|
|
|
|
|
|
stdout.println("@Core Author: EvilChen");
|
2021-09-12 15:23:54 +08:00
|
|
|
|
stdout.println("@UI Author: 0chencc");
|
2021-06-10 22:59:27 +08:00
|
|
|
|
stdout.println("@Github: https://github.com/gh0stkey/HaE");
|
2022-01-11 14:46:25 +08:00
|
|
|
|
stdout.println("@Team: OverSpace Security Team");
|
2021-06-10 22:59:27 +08:00
|
|
|
|
// UI
|
2021-09-07 22:09:42 +08:00
|
|
|
|
SwingUtilities.invokeLater(this::initialize);
|
2021-06-10 22:59:27 +08:00
|
|
|
|
|
|
|
|
|
|
callbacks.registerHttpListener(BurpExtender.this);
|
|
|
|
|
|
callbacks.registerMessageEditorTabFactory(BurpExtender.this);
|
|
|
|
|
|
}
|
2022-01-11 14:46:25 +08:00
|
|
|
|
|
2021-06-10 22:59:27 +08:00
|
|
|
|
private void initialize(){
|
|
|
|
|
|
callbacks.customizeUiComponent(main);
|
|
|
|
|
|
callbacks.addSuiteTab(BurpExtender.this);
|
|
|
|
|
|
}
|
2022-01-11 14:46:25 +08:00
|
|
|
|
|
2021-06-10 22:59:27 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
public String getTabCaption(){
|
|
|
|
|
|
return "HaE";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Component getUiComponent() {
|
|
|
|
|
|
return main;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 使用processHttpMessage用来做Highlighter
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void processHttpMessage(int toolFlag, boolean messageIsRequest, IHttpRequestResponse messageInfo) {
|
|
|
|
|
|
// 判断是否是响应,且该代码作用域为:REPEATER、INTRUDER、PROXY(分别对应toolFlag 64、32、4)
|
|
|
|
|
|
if (toolFlag == 64 || toolFlag == 32 || toolFlag == 4) {
|
2021-10-21 23:42:15 +08:00
|
|
|
|
byte[] content;
|
2021-06-10 22:59:27 +08:00
|
|
|
|
if (messageIsRequest) {
|
2021-10-21 23:42:15 +08:00
|
|
|
|
content = messageInfo.getRequest();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
} else {
|
2021-10-21 23:42:15 +08:00
|
|
|
|
content = messageInfo.getResponse();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
2022-01-11 14:46:25 +08:00
|
|
|
|
|
2021-10-21 23:42:15 +08:00
|
|
|
|
String c = new String(content, StandardCharsets.UTF_8).intern();
|
2022-01-11 14:46:25 +08:00
|
|
|
|
List<String> result = pm.processMessageByContent(helpers, content, messageIsRequest, true);
|
2021-10-21 23:42:15 +08:00
|
|
|
|
if (result != null && !result.isEmpty() && result.size() > 0) {
|
|
|
|
|
|
String originalColor = messageInfo.getHighlight();
|
|
|
|
|
|
String originalComment = messageInfo.getComment();
|
|
|
|
|
|
List<String> colorList = new ArrayList<>();
|
|
|
|
|
|
if (originalColor != null) {
|
|
|
|
|
|
colorList.add(originalColor);
|
|
|
|
|
|
}
|
|
|
|
|
|
colorList.add(result.get(0));
|
2021-09-07 22:09:42 +08:00
|
|
|
|
String color = uc.getEndColor(gck.getColorKeys(colorList));
|
2021-10-21 23:42:15 +08:00
|
|
|
|
|
2021-06-10 22:59:27 +08:00
|
|
|
|
messageInfo.setHighlight(color);
|
2021-10-21 23:42:15 +08:00
|
|
|
|
String addComment = String.join(", ", result.get(1));
|
|
|
|
|
|
String resComment = originalComment != null ? String.format("%s, %s", originalComment, addComment) : addComment;
|
2021-09-12 15:23:54 +08:00
|
|
|
|
|
2021-10-21 23:42:15 +08:00
|
|
|
|
messageInfo.setComment(resComment);
|
2021-09-12 15:23:54 +08:00
|
|
|
|
}
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-11 14:46:25 +08:00
|
|
|
|
|
2021-06-10 22:59:27 +08:00
|
|
|
|
class MarkInfoTab implements IMessageEditorTab {
|
2021-09-07 22:09:42 +08:00
|
|
|
|
private final ITextEditor markInfoText;
|
2021-06-10 22:59:27 +08:00
|
|
|
|
private byte[] currentMessage;
|
|
|
|
|
|
private final IMessageEditorController controller;
|
|
|
|
|
|
private byte[] extractRequestContent;
|
|
|
|
|
|
private byte[] extractResponseContent;
|
|
|
|
|
|
|
|
|
|
|
|
public MarkInfoTab(IMessageEditorController controller, boolean editable) {
|
|
|
|
|
|
this.controller = controller;
|
2022-01-11 14:46:25 +08:00
|
|
|
|
this.markInfoText = callbacks.createTextEditor();
|
|
|
|
|
|
this.markInfoText.setEditable(editable);
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getTabCaption() {
|
|
|
|
|
|
return "MarkInfo";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Component getUiComponent() {
|
2022-01-11 14:46:25 +08:00
|
|
|
|
return this.markInfoText.getComponent();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean isEnabled(byte[] content, boolean isRequest) {
|
2021-10-21 23:42:15 +08:00
|
|
|
|
String c = new String(content, StandardCharsets.UTF_8).intern();
|
2022-01-11 14:46:25 +08:00
|
|
|
|
List<String> result = pm.processMessageByContent(helpers, content, isRequest, false);
|
2021-10-21 23:42:15 +08:00
|
|
|
|
if (result != null && !result.isEmpty()) {
|
|
|
|
|
|
if (isRequest) {
|
2022-01-11 14:46:25 +08:00
|
|
|
|
this.extractRequestContent = result.get(0).getBytes();
|
2021-10-21 23:42:15 +08:00
|
|
|
|
} else {
|
2022-01-11 14:46:25 +08:00
|
|
|
|
this.extractResponseContent = result.get(0).getBytes();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
2021-10-21 23:42:15 +08:00
|
|
|
|
return true;
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public byte[] getMessage() {
|
2022-01-11 14:46:25 +08:00
|
|
|
|
return this.currentMessage;
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean isModified() {
|
2022-01-11 14:46:25 +08:00
|
|
|
|
return this.markInfoText.isTextModified();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public byte[] getSelectedData() {
|
2022-01-11 14:46:25 +08:00
|
|
|
|
return this.markInfoText.getSelectedText();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 使用setMessage用来做Extractor
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void setMessage(byte[] content, boolean isRequest) {
|
2021-09-07 22:09:42 +08:00
|
|
|
|
String c = new String(content, StandardCharsets.UTF_8).intern();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
if (content.length > 0) {
|
|
|
|
|
|
if (isRequest) {
|
2022-01-11 14:46:25 +08:00
|
|
|
|
this.markInfoText.setText(this.extractRequestContent);
|
2021-06-10 22:59:27 +08:00
|
|
|
|
} else {
|
2022-01-11 14:46:25 +08:00
|
|
|
|
this.markInfoText.setText(this.extractResponseContent);
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-01-11 14:46:25 +08:00
|
|
|
|
this.currentMessage = content;
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public IMessageEditorTab createNewInstance(IMessageEditorController controller, boolean editable) {
|
2021-09-07 22:09:42 +08:00
|
|
|
|
return new MarkInfoTab(controller, editable);
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|