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.util.Arrays;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* @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;
|
|
|
|
|
|
MatchHTTP mh = new MatchHTTP();
|
|
|
|
|
|
ExtractContent ec = new ExtractContent();
|
|
|
|
|
|
DoAction da = new DoAction();
|
|
|
|
|
|
GetColorKey gck = new GetColorKey();
|
|
|
|
|
|
UpgradeColor uc = new UpgradeColor();
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.callbacks = callbacks;
|
|
|
|
|
|
BurpExtender.helpers = callbacks.getHelpers();
|
|
|
|
|
|
|
2021-09-12 15:23:54 +08:00
|
|
|
|
String version = "2.1";
|
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");
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void initialize(){
|
|
|
|
|
|
callbacks.customizeUiComponent(main);
|
|
|
|
|
|
callbacks.addSuiteTab(BurpExtender.this);
|
|
|
|
|
|
}
|
|
|
|
|
|
@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) {
|
|
|
|
|
|
Map<String, Map<String, Object>> obj;
|
|
|
|
|
|
// 流量清洗
|
2021-07-13 15:10:25 +08:00
|
|
|
|
String urlString = helpers.analyzeRequest(messageInfo.getHttpService(), messageInfo.getRequest()).getUrl().toString();
|
2021-06-10 22:59:27 +08:00
|
|
|
|
urlString = urlString.indexOf("?") > 0 ? urlString.substring(0, urlString.indexOf("?")) : urlString;
|
|
|
|
|
|
|
|
|
|
|
|
// 正则判断
|
|
|
|
|
|
if (mh.matchSuffix(urlString)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (messageIsRequest) {
|
2021-07-13 15:10:25 +08:00
|
|
|
|
byte[] byteRequest = messageInfo.getRequest();
|
2021-07-06 18:33:11 +08:00
|
|
|
|
// 获取报文头
|
2021-07-13 15:10:25 +08:00
|
|
|
|
List<String> requestTmpHeaders = helpers.analyzeRequest(messageInfo.getHttpService(), byteRequest).getHeaders();
|
2021-07-06 18:33:11 +08:00
|
|
|
|
String requestHeaders = String.join("\n", requestTmpHeaders);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取报文主体
|
2021-07-13 15:10:25 +08:00
|
|
|
|
int requestBodyOffset = helpers.analyzeRequest(messageInfo.getHttpService(), byteRequest).getBodyOffset();
|
2021-07-06 18:33:11 +08:00
|
|
|
|
byte[] requestBody = Arrays.copyOfRange(byteRequest, requestBodyOffset, byteRequest.length);
|
|
|
|
|
|
|
2021-07-13 15:10:25 +08:00
|
|
|
|
obj = ec.matchRegex(byteRequest, requestHeaders, requestBody, "request");
|
2021-06-10 22:59:27 +08:00
|
|
|
|
} else {
|
2021-07-13 15:10:25 +08:00
|
|
|
|
byte[] byteResponse = messageInfo.getResponse();
|
|
|
|
|
|
|
2021-07-06 18:33:11 +08:00
|
|
|
|
// 获取报文头
|
2021-07-13 15:10:25 +08:00
|
|
|
|
List<String> responseTmpHeaders = helpers.analyzeRequest(messageInfo.getHttpService(), byteResponse).getHeaders();
|
2021-07-06 18:33:11 +08:00
|
|
|
|
String responseHeaders = String.join("\n", responseTmpHeaders);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取报文主体
|
2021-07-13 15:10:25 +08:00
|
|
|
|
int responseBodyOffset = helpers.analyzeResponse(byteResponse).getBodyOffset();
|
2021-07-06 18:33:11 +08:00
|
|
|
|
byte[] responseBody = Arrays.copyOfRange(byteResponse, responseBodyOffset, byteResponse.length);
|
|
|
|
|
|
|
2021-07-13 15:10:25 +08:00
|
|
|
|
obj = ec.matchRegex(byteResponse, responseHeaders, responseBody, "response");
|
2021-06-10 22:59:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-09-12 15:23:54 +08:00
|
|
|
|
List<List<String>> resultList = da.highlightAndComment(obj);
|
|
|
|
|
|
List<String> colorList = resultList.get(0);
|
|
|
|
|
|
stdout.println(colorList);
|
|
|
|
|
|
List<String> commentList = resultList.get(1);
|
2021-06-10 22:59:27 +08:00
|
|
|
|
if (colorList.size() != 0) {
|
2021-09-07 22:09:42 +08:00
|
|
|
|
String color = uc.getEndColor(gck.getColorKeys(colorList));
|
2021-06-10 22:59:27 +08:00
|
|
|
|
messageInfo.setHighlight(color);
|
|
|
|
|
|
}
|
2021-09-12 15:23:54 +08:00
|
|
|
|
|
|
|
|
|
|
if (commentList.size() != 0) {
|
|
|
|
|
|
String originalComment = messageInfo.getComment();
|
|
|
|
|
|
messageInfo.setComment(String.join(", ", commentList));
|
|
|
|
|
|
}
|
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;
|
|
|
|
|
|
markInfoText = callbacks.createTextEditor();
|
|
|
|
|
|
markInfoText.setEditable(editable);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getTabCaption() {
|
|
|
|
|
|
return "MarkInfo";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public Component getUiComponent() {
|
|
|
|
|
|
return markInfoText.getComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean isEnabled(byte[] content, boolean isRequest) {
|
2021-06-11 12:36:30 +08:00
|
|
|
|
Map<String, Map<String, Object>> obj;
|
|
|
|
|
|
|
|
|
|
|
|
if (isRequest) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 流量清洗
|
|
|
|
|
|
String urlString = helpers.analyzeRequest(controller.getHttpService(), controller.getRequest()).getUrl().toString();
|
|
|
|
|
|
urlString = urlString.indexOf("?") > 0 ? urlString.substring(0, urlString.indexOf("?")) : urlString;
|
|
|
|
|
|
// 正则判断
|
|
|
|
|
|
if (mh.matchSuffix(urlString)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
2021-06-10 22:59:27 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2021-07-13 15:10:25 +08:00
|
|
|
|
IRequestInfo iRequestInfo = helpers.analyzeRequest(controller.getHttpService(), content);
|
2021-06-10 22:59:27 +08:00
|
|
|
|
|
2021-06-11 12:36:30 +08:00
|
|
|
|
// 获取报文头
|
2021-07-13 15:10:25 +08:00
|
|
|
|
List<String> requestTmpHeaders = iRequestInfo.getHeaders();
|
2021-07-06 18:33:11 +08:00
|
|
|
|
String requestHeaders = String.join("\n", requestTmpHeaders);
|
2021-06-11 12:36:30 +08:00
|
|
|
|
// 获取报文主体
|
2021-07-13 15:10:25 +08:00
|
|
|
|
int requestBodyOffset = iRequestInfo.getBodyOffset();
|
|
|
|
|
|
byte[] requestBody = Arrays.copyOfRange(content, requestBodyOffset, content.length);
|
2021-06-10 22:59:27 +08:00
|
|
|
|
|
2021-07-06 18:33:11 +08:00
|
|
|
|
obj = ec.matchRegex(content, requestHeaders, requestBody, "request");
|
2021-06-11 12:36:30 +08:00
|
|
|
|
if (obj.size() > 0) {
|
2021-06-10 22:59:27 +08:00
|
|
|
|
String result = da.extractString(obj);
|
|
|
|
|
|
extractRequestContent = result.getBytes();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2021-07-13 15:10:25 +08:00
|
|
|
|
IResponseInfo iResponseInfo = helpers.analyzeResponse(content);
|
2021-06-11 12:36:30 +08:00
|
|
|
|
// 获取报文头
|
2021-07-13 15:10:25 +08:00
|
|
|
|
List<String> responseTmpHeaders = iResponseInfo.getHeaders();
|
2021-07-06 18:33:11 +08:00
|
|
|
|
String responseHeaders = String.join("\n", responseTmpHeaders);
|
2021-06-11 12:36:30 +08:00
|
|
|
|
// 获取报文主体
|
2021-07-13 15:10:25 +08:00
|
|
|
|
int responseBodyOffset = iResponseInfo.getBodyOffset();
|
|
|
|
|
|
byte[] responseBody = Arrays.copyOfRange(content, responseBodyOffset, content.length);
|
2021-06-11 12:36:30 +08:00
|
|
|
|
|
2021-07-06 18:33:11 +08:00
|
|
|
|
obj = ec.matchRegex(content, responseHeaders, responseBody, "response");
|
2021-06-11 12:36:30 +08:00
|
|
|
|
if (obj.size() > 0) {
|
2021-06-10 22:59:27 +08:00
|
|
|
|
String result = da.extractString(obj);
|
|
|
|
|
|
extractResponseContent = result.getBytes();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public byte[] getMessage() {
|
|
|
|
|
|
return currentMessage;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public boolean isModified() {
|
|
|
|
|
|
return markInfoText.isTextModified();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public byte[] getSelectedData() {
|
|
|
|
|
|
return markInfoText.getSelectedText();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 使用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) {
|
|
|
|
|
|
markInfoText.setText(extractRequestContent);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
markInfoText.setText(extractResponseContent);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
currentMessage = content;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
}
|
|
|
|
|
|
}
|