From ca773f368b0908544ddcaacdc0674ba354598c32 Mon Sep 17 00:00:00 2001 From: gh0stkey <24655118+gh0stkey@users.noreply.github.com> Date: Thu, 9 May 2024 13:32:22 +0800 Subject: [PATCH] Version: 3.0.1 Update --- src/main/java/hae/Config.java | 2 + src/main/java/hae/HaE.java | 2 +- .../java/hae/component/board/Datatable.java | 68 ++++++++++--------- .../hae/instances/editor/RequestEditor.java | 15 ++-- .../hae/instances/editor/ResponseEditor.java | 9 +-- .../hae/instances/editor/WebSocketEditor.java | 5 +- .../instances/http/utils/RegularMatcher.java | 4 ++ 7 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/main/java/hae/Config.java b/src/main/java/hae/Config.java index 7ae59d9..aba0efe 100644 --- a/src/main/java/hae/Config.java +++ b/src/main/java/hae/Config.java @@ -13,9 +13,11 @@ public class Config { "any header", "any body", "response", + "response line", "response header", "response body", "request", + "request line", "request header", "request body" }; diff --git a/src/main/java/hae/HaE.java b/src/main/java/hae/HaE.java index f50cc22..eeb3ce2 100644 --- a/src/main/java/hae/HaE.java +++ b/src/main/java/hae/HaE.java @@ -16,7 +16,7 @@ public class HaE implements BurpExtension { @Override public void initialize(MontoyaApi api) { // 设置扩展名称 - String version = "3.0"; + String version = "3.0.1"; api.extension().setName(String.format("HaE (%s) - Highlighter and Extractor", version)); // 加载扩展后输出的项目信息 diff --git a/src/main/java/hae/component/board/Datatable.java b/src/main/java/hae/component/board/Datatable.java index 1b90776..c3ca75b 100644 --- a/src/main/java/hae/component/board/Datatable.java +++ b/src/main/java/hae/component/board/Datatable.java @@ -2,6 +2,7 @@ import burp.api.montoya.MontoyaApi; import hae.component.board.message.MessageTableModel; +import hae.instances.editor.RequestEditor; import jregex.Pattern; import jregex.REFlags; @@ -30,7 +31,6 @@ public Datatable(MontoyaApi api, String tabName, List dataList) { this.api = api; this.tabName = tabName; - String[] columnNames = {"#", "Information"}; dataTableModel = new DefaultTableModel(columnNames, 0); @@ -114,19 +114,6 @@ public void changedUpdate(DocumentEvent e) { optionsPanel.add(Box.createHorizontalStrut(5)); optionsPanel.add(searchField); - dataTable.setTransferHandler(new TransferHandler() { - @Override - public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException { - if (comp instanceof JTable) { - StringSelection stringSelection = new StringSelection(getSelectedData( - (JTable) comp)); - clip.setContents(stringSelection, null); - } else { - super.exportToClipboard(comp, clip, action); - } - } - }); - add(scrollPane, BorderLayout.CENTER); add(optionsPanel, BorderLayout.SOUTH); } @@ -186,26 +173,20 @@ public boolean include(Entry entry) { } } - public static String getSelectedData(JTable table) { - int[] selectRows = table.getSelectedRows(); - StringBuilder selectData = new StringBuilder(); - for (int row : selectRows) { - selectData.append(table.getValueAt(row, 1).toString()).append("\n"); - } - - // 便于单行复制,去除最后一个换行符 - if (!selectData.isEmpty()){ - selectData.deleteCharAt(selectData.length() - 1); - } - - return selectData.toString(); - } - - public JTable getDataTable() { - return this.dataTable; - } - public void setTableListener(MessageTableModel messagePanel) { + // 表格复制功能 + dataTable.setTransferHandler(new TransferHandler() { + @Override + public void exportToClipboard(JComponent comp, Clipboard clip, int action) throws IllegalStateException { + if (comp instanceof JTable) { + StringSelection stringSelection = new StringSelection(getSelectedDataAtTable((JTable) comp)); + clip.setContents(stringSelection, null); + } else { + super.exportToClipboard(comp, clip, action); + } + } + }); + dataTable.setDefaultEditor(Object.class, null); // 表格内容双击事件 @@ -222,5 +203,26 @@ public void mouseClicked(MouseEvent e) { } }); } + + public String getSelectedDataAtTable(JTable table) { + int[] selectRows = table.getSelectedRows(); + StringBuilder selectData = new StringBuilder(); + + for (int row : selectRows) { + selectData.append(table.getValueAt(row, 1).toString()).append("\n"); + } + + // 便于单行复制,去除最后一个换行符 + if (!selectData.isEmpty()){ + selectData.deleteCharAt(selectData.length() - 1); + return selectData.toString(); + } else { + return ""; + } + } + + public JTable getDataTable() { + return this.dataTable; + } } diff --git a/src/main/java/hae/instances/editor/RequestEditor.java b/src/main/java/hae/instances/editor/RequestEditor.java index fc0bd5d..2fd175d 100644 --- a/src/main/java/hae/instances/editor/RequestEditor.java +++ b/src/main/java/hae/instances/editor/RequestEditor.java @@ -1,11 +1,11 @@ package hae.instances.editor; import burp.api.montoya.MontoyaApi; +import burp.api.montoya.core.ByteArray; +import burp.api.montoya.core.Range; import burp.api.montoya.ui.editor.extension.EditorCreationContext; import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpRequestEditor; import burp.api.montoya.ui.editor.extension.HttpRequestEditorProvider; -import burp.api.montoya.core.ByteArray; -import burp.api.montoya.core.Range; import burp.api.montoya.http.message.HttpRequestResponse; import burp.api.montoya.http.message.requests.HttpRequest; import burp.api.montoya.ui.Selection; @@ -60,7 +60,7 @@ public synchronized boolean isEnabledFor(HttpRequestResponse requestResponse) { HttpRequest request = requestResponse.request(); if (request != null && !request.bodyToString().equals("Loading...")) { List> result = messageProcessor.processRequest("", request, false); - jTabbedPane = generateTabbedPaneFromResultMap(api, result); + generateTabbedPaneFromResultMap(api, jTabbedPane, result); return jTabbedPane.getTabCount() > 0; } return false; @@ -81,7 +81,8 @@ public Selection selectedData() { return new Selection() { @Override public ByteArray contents() { - return ByteArray.byteArray(Datatable.getSelectedData(((Datatable) jTabbedPane.getSelectedComponent()).getDataTable())); + Datatable dataTable = (Datatable) jTabbedPane.getSelectedComponent(); + return ByteArray.byteArray(dataTable.getSelectedDataAtTable(dataTable.getDataTable())); } @Override @@ -97,8 +98,8 @@ public boolean isModified() { } } - public static JTabbedPane generateTabbedPaneFromResultMap(MontoyaApi api, List> result) { - JTabbedPane tabbedPane = new JTabbedPane(); + public static void generateTabbedPaneFromResultMap(MontoyaApi api, JTabbedPane tabbedPane, List> result) { + tabbedPane.removeAll(); if (result != null && !result.isEmpty() && result.size() > 0) { Map dataMap = result.get(0); if (dataMap != null && !dataMap.isEmpty() && dataMap.size() > 0) { @@ -109,7 +110,5 @@ public static JTabbedPane generateTabbedPaneFromResultMap(MontoyaApi api, List> result = messageProcessor.processResponse("", request, false); - jTabbedPane = RequestEditor.generateTabbedPaneFromResultMap(api, result); + RequestEditor.generateTabbedPaneFromResultMap(api, jTabbedPane, result); return jTabbedPane.getTabCount() > 0; } return false; @@ -80,7 +80,8 @@ public Selection selectedData() { return new Selection() { @Override public ByteArray contents() { - return ByteArray.byteArray(Datatable.getSelectedData(((Datatable) jTabbedPane.getSelectedComponent()).getDataTable())); + Datatable dataTable = (Datatable) jTabbedPane.getSelectedComponent(); + return ByteArray.byteArray(dataTable.getSelectedDataAtTable(dataTable.getDataTable())); } @Override diff --git a/src/main/java/hae/instances/editor/WebSocketEditor.java b/src/main/java/hae/instances/editor/WebSocketEditor.java index e8a384a..143e75d 100644 --- a/src/main/java/hae/instances/editor/WebSocketEditor.java +++ b/src/main/java/hae/instances/editor/WebSocketEditor.java @@ -55,7 +55,7 @@ public boolean isEnabledFor(WebSocketMessage webSocketMessage) { String websocketMessage = webSocketMessage.payload().toString(); if (!websocketMessage.isEmpty()) { List> result = messageProcessor.processMessage("", websocketMessage, false); - jTabbedPane = RequestEditor.generateTabbedPaneFromResultMap(api, result); + RequestEditor.generateTabbedPaneFromResultMap(api, jTabbedPane, result); return jTabbedPane.getTabCount() > 0; } return false; @@ -76,7 +76,8 @@ public Selection selectedData() { return new Selection() { @Override public ByteArray contents() { - return ByteArray.byteArray(Datatable.getSelectedData(((Datatable) jTabbedPane.getSelectedComponent()).getDataTable())); + Datatable dataTable = (Datatable) jTabbedPane.getSelectedComponent(); + return ByteArray.byteArray(dataTable.getSelectedDataAtTable(dataTable.getDataTable())); } @Override diff --git a/src/main/java/hae/instances/http/utils/RegularMatcher.java b/src/main/java/hae/instances/http/utils/RegularMatcher.java index da2993c..44d6bc5 100644 --- a/src/main/java/hae/instances/http/utils/RegularMatcher.java +++ b/src/main/java/hae/instances/http/utils/RegularMatcher.java @@ -69,6 +69,10 @@ public Map> match(String host, String type, String m case "response body": matchContent = body; break; + case "request line": + case "response line": + matchContent = message.split("\\r?\\n", 2)[0]; + break; default: break; }