2024-05-06 12:56:56 +08:00
|
|
|
package hae.instances.editor;
|
|
|
|
|
|
|
|
|
|
import burp.api.montoya.MontoyaApi;
|
2024-05-09 13:32:22 +08:00
|
|
|
import burp.api.montoya.core.ByteArray;
|
|
|
|
|
import burp.api.montoya.core.Range;
|
2024-05-06 12:56:56 +08:00
|
|
|
import burp.api.montoya.http.message.HttpRequestResponse;
|
|
|
|
|
import burp.api.montoya.http.message.requests.HttpRequest;
|
|
|
|
|
import burp.api.montoya.ui.Selection;
|
2024-05-12 19:02:38 +08:00
|
|
|
import burp.api.montoya.ui.editor.extension.EditorCreationContext;
|
|
|
|
|
import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpRequestEditor;
|
|
|
|
|
import burp.api.montoya.ui.editor.extension.HttpRequestEditorProvider;
|
2024-08-23 22:03:31 +08:00
|
|
|
import hae.Config;
|
2024-07-23 09:21:30 +08:00
|
|
|
import hae.component.board.table.Datatable;
|
2024-05-06 12:56:56 +08:00
|
|
|
import hae.instances.http.utils.MessageProcessor;
|
2024-05-24 15:00:49 +08:00
|
|
|
import hae.utils.ConfigLoader;
|
2024-08-12 10:34:26 +08:00
|
|
|
import hae.utils.http.HttpUtils;
|
2024-05-23 12:00:13 +08:00
|
|
|
import hae.utils.string.StringProcessor;
|
2024-05-06 12:56:56 +08:00
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class RequestEditor implements HttpRequestEditorProvider {
|
|
|
|
|
private final MontoyaApi api;
|
2024-05-23 12:00:13 +08:00
|
|
|
private final ConfigLoader configLoader;
|
2024-05-06 12:56:56 +08:00
|
|
|
|
2024-05-23 12:00:13 +08:00
|
|
|
public RequestEditor(MontoyaApi api, ConfigLoader configLoader) {
|
2024-05-06 12:56:56 +08:00
|
|
|
this.api = api;
|
2024-05-23 12:00:13 +08:00
|
|
|
this.configLoader = configLoader;
|
2024-05-06 12:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ExtensionProvidedHttpRequestEditor provideHttpRequestEditor(EditorCreationContext editorCreationContext) {
|
2024-05-23 12:00:13 +08:00
|
|
|
return new Editor(api, configLoader, editorCreationContext);
|
2024-05-06 12:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static class Editor implements ExtensionProvidedHttpRequestEditor {
|
|
|
|
|
private final MontoyaApi api;
|
2024-05-23 12:00:13 +08:00
|
|
|
private final ConfigLoader configLoader;
|
2024-08-12 10:34:26 +08:00
|
|
|
private final HttpUtils httpUtils;
|
2024-05-06 12:56:56 +08:00
|
|
|
private final EditorCreationContext creationContext;
|
|
|
|
|
private final MessageProcessor messageProcessor;
|
|
|
|
|
private HttpRequestResponse requestResponse;
|
2024-05-23 12:00:13 +08:00
|
|
|
private List<Map<String, String>> dataList;
|
2024-05-06 12:56:56 +08:00
|
|
|
|
2024-05-12 19:02:38 +08:00
|
|
|
private final JTabbedPane jTabbedPane = new JTabbedPane();
|
2024-05-06 12:56:56 +08:00
|
|
|
|
2024-05-23 12:00:13 +08:00
|
|
|
public Editor(MontoyaApi api, ConfigLoader configLoader, EditorCreationContext creationContext) {
|
2024-05-06 12:56:56 +08:00
|
|
|
this.api = api;
|
2024-05-23 12:00:13 +08:00
|
|
|
this.configLoader = configLoader;
|
2024-08-12 10:34:26 +08:00
|
|
|
this.httpUtils = new HttpUtils(api, configLoader);
|
2024-05-06 12:56:56 +08:00
|
|
|
this.creationContext = creationContext;
|
|
|
|
|
this.messageProcessor = new MessageProcessor(api);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public HttpRequest getRequest() {
|
|
|
|
|
return requestResponse.request();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setRequestResponse(HttpRequestResponse requestResponse) {
|
|
|
|
|
this.requestResponse = requestResponse;
|
2024-07-23 09:21:30 +08:00
|
|
|
generateTabbedPaneFromResultMap(api, configLoader, jTabbedPane, this.dataList);
|
2024-05-06 12:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public synchronized boolean isEnabledFor(HttpRequestResponse requestResponse) {
|
|
|
|
|
HttpRequest request = requestResponse.request();
|
2024-05-23 12:00:13 +08:00
|
|
|
if (request != null) {
|
|
|
|
|
try {
|
|
|
|
|
String host = StringProcessor.getHostByUrl(request.url());
|
|
|
|
|
if (!host.isEmpty()) {
|
2024-07-23 09:21:30 +08:00
|
|
|
String toolType = creationContext.toolSource().toolType().toolName();
|
2024-08-12 10:34:26 +08:00
|
|
|
boolean matches = httpUtils.verifyHttpRequestResponse(requestResponse, toolType);
|
2024-05-23 12:00:13 +08:00
|
|
|
|
2024-08-12 10:34:26 +08:00
|
|
|
if (!matches) {
|
2024-05-23 12:00:13 +08:00
|
|
|
this.dataList = messageProcessor.processRequest("", request, false);
|
|
|
|
|
return isListHasData(this.dataList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
|
}
|
2024-05-06 12:56:56 +08:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String caption() {
|
|
|
|
|
return "MarkInfo";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Component uiComponent() {
|
|
|
|
|
return jTabbedPane;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Selection selectedData() {
|
|
|
|
|
return new Selection() {
|
|
|
|
|
@Override
|
|
|
|
|
public ByteArray contents() {
|
2024-05-09 13:32:22 +08:00
|
|
|
Datatable dataTable = (Datatable) jTabbedPane.getSelectedComponent();
|
|
|
|
|
return ByteArray.byteArray(dataTable.getSelectedDataAtTable(dataTable.getDataTable()));
|
2024-05-06 12:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Range offsets() {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isModified() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 12:00:13 +08:00
|
|
|
public static boolean isListHasData(List<Map<String, String>> dataList) {
|
|
|
|
|
if (dataList != null && !dataList.isEmpty()) {
|
|
|
|
|
Map<String, String> dataMap = dataList.get(0);
|
|
|
|
|
return dataMap != null && !dataMap.isEmpty();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 09:21:30 +08:00
|
|
|
public static void generateTabbedPaneFromResultMap(MontoyaApi api, ConfigLoader configLoader, JTabbedPane tabbedPane, List<Map<String, String>> result) {
|
2024-05-09 13:32:22 +08:00
|
|
|
tabbedPane.removeAll();
|
2024-05-23 12:00:13 +08:00
|
|
|
if (result != null && !result.isEmpty()) {
|
2024-05-06 12:56:56 +08:00
|
|
|
Map<String, String> dataMap = result.get(0);
|
2024-05-23 12:00:13 +08:00
|
|
|
if (dataMap != null && !dataMap.isEmpty()) {
|
2024-05-12 19:02:38 +08:00
|
|
|
dataMap.keySet().forEach(i -> {
|
2024-08-23 22:03:31 +08:00
|
|
|
String[] extractData = dataMap.get(i).split(Config.boundary);
|
2024-07-23 09:21:30 +08:00
|
|
|
Datatable dataPanel = new Datatable(api, configLoader, i, Arrays.asList(extractData));
|
2024-05-06 12:56:56 +08:00
|
|
|
tabbedPane.addTab(i, dataPanel);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|