From 4da3d3f42d05d7eb39168a6fd8328f7e16ba595d Mon Sep 17 00:00:00 2001 From: gh0stkey <24655118+gh0stkey@users.noreply.github.com> Date: Sun, 12 May 2024 19:02:38 +0800 Subject: [PATCH] Version: 3.0.2 Update --- src/main/java/hae/Config.java | 10 ++--- src/main/java/hae/HaE.java | 2 +- src/main/java/hae/cache/CachePool.java | 3 +- src/main/java/hae/component/Main.java | 8 ++-- .../java/hae/component/board/Databoard.java | 29 +++++++------- .../java/hae/component/board/Datatable.java | 17 ++++---- .../board/message/MessageRenderer.java | 15 ++++--- .../board/message/MessageTableModel.java | 39 ++++++++++--------- .../java/hae/component/config/Config.java | 8 ++-- src/main/java/hae/component/rule/Rule.java | 33 ++++++++-------- src/main/java/hae/component/rule/Rules.java | 6 +-- .../hae/instances/editor/RequestEditor.java | 13 +++---- .../hae/instances/editor/ResponseEditor.java | 7 ++-- .../hae/instances/editor/WebSocketEditor.java | 6 ++- .../instances/http/HttpMessageHandler.java | 15 ++++--- .../http/utils/MessageProcessor.java | 10 ++++- .../instances/http/utils/RegularMatcher.java | 4 +- .../java/hae/utils/config/ConfigLoader.java | 26 ++++++------- .../java/hae/utils/rule/RuleProcessor.java | 11 +++--- .../java/hae/utils/string/HashCalculator.java | 2 +- 20 files changed, 137 insertions(+), 127 deletions(-) diff --git a/src/main/java/hae/Config.java b/src/main/java/hae/Config.java index aba0efe..e5e7c1b 100644 --- a/src/main/java/hae/Config.java +++ b/src/main/java/hae/Config.java @@ -8,7 +8,7 @@ public class Config { public static String suffix = "3g2|3gp|7z|aac|abw|aif|aifc|aiff|apk|arc|au|avi|azw|bat|bin|bmp|bz|bz2|cmd|cmx|cod|com|csh|css|csv|dll|doc|docx|ear|eot|epub|exe|flac|flv|gif|gz|ico|ics|ief|jar|jfif|jpe|jpeg|jpg|less|m3u|mid|midi|mjs|mkv|mov|mp2|mp3|mp4|mpa|mpe|mpeg|mpg|mpkg|mpp|mpv2|odp|ods|odt|oga|ogg|ogv|ogx|otf|pbm|pdf|pgm|png|pnm|ppm|ppt|pptx|ra|ram|rar|ras|rgb|rmi|rtf|scss|sh|snd|svg|swf|tar|tif|tiff|ttf|vsd|war|wav|weba|webm|webp|wmv|woff|woff2|xbm|xls|xlsx|xpm|xul|xwd|zip"; - public static String[] scope = new String[] { + public static String[] scope = new String[]{ "any", "any header", "any body", @@ -23,21 +23,21 @@ public class Config { }; public static String[] ruleFields = { - "Loaded", "Name", "F-Regex", "S-Regex", "Format", "Color", "Scope", "Engine", "Sensitive" + "Loaded", "Name", "F-Regex", "S-Regex", "Format", "Color", "Scope", "Engine", "Sensitive" }; - public static Object[][] ruleTemplate = new Object[][] { + public static Object[][] ruleTemplate = new Object[][]{ { false, "New Name", "(First Regex)", "(Second Regex)", "{0}", "gray", "any", "nfa", false } }; - public static String[] engine = new String[] { + public static String[] engine = new String[]{ "nfa", "dfa" }; - public static String[] color = new String[] { + public static String[] color = new String[]{ "red", "orange", "yellow", diff --git a/src/main/java/hae/HaE.java b/src/main/java/hae/HaE.java index eeb3ce2..3c5e534 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.1"; + String version = "3.0.2"; api.extension().setName(String.format("HaE (%s) - Highlighter and Extractor", version)); // 加载扩展后输出的项目信息 diff --git a/src/main/java/hae/cache/CachePool.java b/src/main/java/hae/cache/CachePool.java index 68c09cb..c071c2c 100644 --- a/src/main/java/hae/cache/CachePool.java +++ b/src/main/java/hae/cache/CachePool.java @@ -1,6 +1,7 @@ package hae.cache; -import java.util.*; +import java.util.HashMap; +import java.util.Map; public class CachePool { private static final Map>> cache = new HashMap<>(); diff --git a/src/main/java/hae/component/Main.java b/src/main/java/hae/component/Main.java index a07a397..03e0142 100644 --- a/src/main/java/hae/component/Main.java +++ b/src/main/java/hae/component/Main.java @@ -28,10 +28,10 @@ public Main(MontoyaApi api, ConfigLoader configLoader, MessageTableModel message private void initComponents() { setLayout(new GridBagLayout()); - ((GridBagLayout)getLayout()).columnWidths = new int[] {0, 0}; - ((GridBagLayout)getLayout()).rowHeights = new int[] {0, 0}; - ((GridBagLayout)getLayout()).columnWeights = new double[] {1.0, 1.0E-4}; - ((GridBagLayout)getLayout()).rowWeights = new double[] {1.0, 1.0E-4}; + ((GridBagLayout) getLayout()).columnWidths = new int[]{0, 0}; + ((GridBagLayout) getLayout()).rowHeights = new int[]{0, 0}; + ((GridBagLayout) getLayout()).columnWeights = new double[]{1.0, 1.0E-4}; + ((GridBagLayout) getLayout()).rowWeights = new double[]{1.0, 1.0E-4}; JTabbedPane mainTabbedPane = new JTabbedPane(); diff --git a/src/main/java/hae/component/board/Databoard.java b/src/main/java/hae/component/board/Databoard.java index f7d8aab..370bfe3 100644 --- a/src/main/java/hae/component/board/Databoard.java +++ b/src/main/java/hae/component/board/Databoard.java @@ -3,20 +3,21 @@ import burp.api.montoya.MontoyaApi; import hae.Config; import hae.component.board.message.MessageTableModel; -import hae.utils.string.StringProcessor; -import hae.utils.config.ConfigLoader; import hae.component.board.message.MessageTableModel.MessageTable; +import hae.utils.config.ConfigLoader; +import hae.utils.string.StringProcessor; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import javax.swing.event.*; +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; import java.awt.*; import java.awt.event.*; import java.util.List; -import javax.swing.*; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; public class Databoard extends JPanel { private final MontoyaApi api; @@ -28,8 +29,8 @@ public class Databoard extends JPanel { private MessageTable messageTable; private static Boolean isMatchHost = false; - private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(); - private JComboBox hostComboBox = new JComboBox(comboBoxModel); + private final DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(); + private final JComboBox hostComboBox = new JComboBox(comboBoxModel); public Databoard(MontoyaApi api, ConfigLoader configLoader, MessageTableModel messageTableModel) { this.api = api; @@ -41,10 +42,10 @@ public Databoard(MontoyaApi api, ConfigLoader configLoader, MessageTableModel me private void initComponents() { setLayout(new GridBagLayout()); - ((GridBagLayout)getLayout()).columnWidths = new int[] {25, 0, 0, 0,20, 0}; - ((GridBagLayout)getLayout()).rowHeights = new int[] {0, 65, 20, 0}; - ((GridBagLayout)getLayout()).columnWeights = new double[] {0.0, 0.0, 1.0, 0.0, 0.0, 1.0E-4}; - ((GridBagLayout)getLayout()).rowWeights = new double[] {0.0, 1.0, 0.0, 1.0E-4}; + ((GridBagLayout) getLayout()).columnWidths = new int[]{25, 0, 0, 0, 20, 0}; + ((GridBagLayout) getLayout()).rowHeights = new int[]{0, 65, 20, 0}; + ((GridBagLayout) getLayout()).columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, 1.0E-4}; + ((GridBagLayout) getLayout()).rowWeights = new double[]{0.0, 1.0, 0.0, 1.0E-4}; JLabel hostLabel = new JLabel("Host:"); @@ -81,7 +82,7 @@ public void componentResized(ComponentEvent e) { new Insets(8, 0, 5, 5), 0, 0)); add(hostTextField, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 0, 5, 5), 0, 0)); - add(actionButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, + add(actionButton, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(8, 0, 5, 5), 0, 0)); add(splitPane, new GridBagConstraints(1, 1, 3, 3, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, @@ -196,7 +197,7 @@ private void populateTabbedPaneByHost(String selectedHost) { Map> selectedDataMap; dataTabbedPane.removeAll(); - dataTabbedPane.setPreferredSize(new Dimension(500,0)); + dataTabbedPane.setPreferredSize(new Dimension(500, 0)); dataTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); splitPane.setLeftComponent(dataTabbedPane); diff --git a/src/main/java/hae/component/board/Datatable.java b/src/main/java/hae/component/board/Datatable.java index c3ca75b..0f60cb7 100644 --- a/src/main/java/hae/component/board/Datatable.java +++ b/src/main/java/hae/component/board/Datatable.java @@ -2,21 +2,24 @@ import burp.api.montoya.MontoyaApi; import hae.component.board.message.MessageTableModel; -import hae.instances.editor.RequestEditor; import jregex.Pattern; import jregex.REFlags; +import javax.swing.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableRowSorter; import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.*; +import java.util.Comparator; import java.util.List; -import javax.swing.*; -import java.awt.datatransfer.*; -import javax.swing.event.*; -import javax.swing.table.*; public class Datatable extends JPanel { private final MontoyaApi api; @@ -213,7 +216,7 @@ public String getSelectedDataAtTable(JTable table) { } // 便于单行复制,去除最后一个换行符 - if (!selectData.isEmpty()){ + if (!selectData.isEmpty()) { selectData.deleteCharAt(selectData.length() - 1); return selectData.toString(); } else { diff --git a/src/main/java/hae/component/board/message/MessageRenderer.java b/src/main/java/hae/component/board/message/MessageRenderer.java index 7cf95fc..a613b0f 100644 --- a/src/main/java/hae/component/board/message/MessageRenderer.java +++ b/src/main/java/hae/component/board/message/MessageRenderer.java @@ -1,18 +1,17 @@ package hae.component.board.message; -import java.awt.Color; -import java.awt.Component; +import javax.swing.*; +import javax.swing.table.DefaultTableCellRenderer; +import java.awt.*; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.swing.JTable; -import javax.swing.table.DefaultTableCellRenderer; public class MessageRenderer extends DefaultTableCellRenderer { - private List log; - private Map colorMap = new HashMap<>(); - private JTable table; // 保存对表格的引用 + private final List log; + private final Map colorMap = new HashMap<>(); + private final JTable table; // 保存对表格的引用 public MessageRenderer(List log, JTable table) { this.log = log; @@ -42,7 +41,7 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole if (isSelected) { // 通过更改RGB颜色来达成阴影效果 - component.setBackground(new Color(color.getRed()-0x20, color.getGreen()-0x20, color.getBlue()-0x20)); + component.setBackground(new Color(color.getRed() - 0x20, color.getGreen() - 0x20, color.getBlue() - 0x20)); } else { // 否则使用原始颜色 component.setBackground(color); diff --git a/src/main/java/hae/component/board/message/MessageTableModel.java b/src/main/java/hae/component/board/message/MessageTableModel.java index 148aa11..b2559a5 100644 --- a/src/main/java/hae/component/board/message/MessageTableModel.java +++ b/src/main/java/hae/component/board/message/MessageTableModel.java @@ -14,18 +14,14 @@ import hae.utils.string.HashCalculator; import hae.utils.string.StringProcessor; -import java.nio.charset.StandardCharsets; -import java.text.MessageFormat; -import java.util.*; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JTable; -import javax.swing.SwingWorker; +import javax.swing.*; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; +import java.nio.charset.StandardCharsets; +import java.text.MessageFormat; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -37,7 +33,7 @@ public class MessageTableModel extends AbstractTableModel { private final JTabbedPane messageTab; private final JSplitPane splitPane; private final List log = new ArrayList(); - private LinkedList filteredLog; + private final LinkedList filteredLog; public MessageTableModel(MontoyaApi api) { this.filteredLog = new LinkedList<>(); @@ -74,6 +70,7 @@ public int compare(String s1, String s2) { int index2 = getIndex(s2); return Integer.compare(index1, index2); } + private int getIndex(String color) { for (int i = 0; i < Config.color.length; i++) { if (Config.color[i].equals(color)) { @@ -96,7 +93,7 @@ private int getIndex(String color) { } public void add(HttpRequestResponse messageInfo, String comment, String color) { - synchronized(log) { + synchronized (log) { HttpRequest httpRequest = messageInfo.request(); String url = httpRequest.url(); String method = httpRequest.method(); @@ -120,7 +117,7 @@ public void add(HttpRequestResponse messageInfo, String comment, String color) { byte[] resByteB = reqResMessage.response().toByteArray().getBytes(); try { // 通过URL、请求和响应报文、匹配数据内容,多维度进行对比 - if ((entry.getUrl().toString().equals(url.toString()) || (Arrays.equals(reqByteB, reqByteA) || Arrays.equals(resByteB, resByteA))) && (areMapsEqual(getCacheData(reqByteB), getCacheData(reqByteA)) && areMapsEqual(getCacheData(resByteB), getCacheData(resByteA)))) { + if ((entry.getUrl().equals(url) || (Arrays.equals(reqByteB, reqByteA) || Arrays.equals(resByteB, resByteA))) && (areMapsEqual(getCacheData(reqByteB), getCacheData(reqByteA)) && areMapsEqual(getCacheData(resByteB), getCacheData(resByteA)))) { isDuplicate = true; break; } @@ -243,6 +240,14 @@ public void applyMessageFilter(String tableName, String filterText) { case "response body": isMatch = matchingString(format, filterText, responseBody); break; + case "request line": + String requestLine = requestString.split("\\r?\\n", 2)[0]; + isMatch = matchingString(format, filterText, requestLine); + break; + case "response line": + String responseLine = responseString.split("\\r?\\n", 2)[0]; + isMatch = matchingString(format, filterText, responseLine); + break; default: break; } @@ -334,13 +339,11 @@ private boolean areInnerMapsEqual(Map innerMap1, Map "Method"; case 1 -> "URL"; diff --git a/src/main/java/hae/component/config/Config.java b/src/main/java/hae/component/config/Config.java index 2459729..bf889d8 100644 --- a/src/main/java/hae/component/config/Config.java +++ b/src/main/java/hae/component/config/Config.java @@ -23,10 +23,10 @@ public Config(MontoyaApi api, ConfigLoader configLoader, Rules rules) { private void initComponents() { setLayout(new GridBagLayout()); - ((GridBagLayout) getLayout()).columnWidths = new int[] {0, 0, 0, 0, 0}; - ((GridBagLayout) getLayout()).rowHeights = new int[] {0, 0, 0}; - ((GridBagLayout) getLayout()).columnWeights = new double[] {0.0, 1.0, 0.0, 0.0, 1.0E-4}; - ((GridBagLayout) getLayout()).rowWeights = new double[] {0.0, 0.0, 1.0E-4}; + ((GridBagLayout) getLayout()).columnWidths = new int[]{0, 0, 0, 0, 0}; + ((GridBagLayout) getLayout()).rowHeights = new int[]{0, 0, 0}; + ((GridBagLayout) getLayout()).columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, 1.0E-4}; + ((GridBagLayout) getLayout()).rowWeights = new double[]{0.0, 0.0, 1.0E-4}; JLabel rulesFilePathLabel = new JLabel("Rules Path:"); JTextField rulesFilePathTextField = new JTextField(); diff --git a/src/main/java/hae/component/rule/Rule.java b/src/main/java/hae/component/rule/Rule.java index 9b17f6d..20b6338 100644 --- a/src/main/java/hae/component/rule/Rule.java +++ b/src/main/java/hae/component/rule/Rule.java @@ -1,18 +1,17 @@ package hae.component.rule; import burp.api.montoya.MontoyaApi; +import hae.Config; +import hae.utils.config.ConfigLoader; +import hae.utils.rule.RuleProcessor; import javax.swing.*; import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableRowSorter; import java.awt.*; import java.awt.event.ActionEvent; -import javax.swing.table.TableRowSorter; import java.util.Vector; -import hae.Config; -import hae.utils.config.ConfigLoader; -import hae.utils.rule.RuleProcessor; - import static javax.swing.JOptionPane.YES_OPTION; public class Rule extends JPanel { @@ -32,10 +31,10 @@ public Rule(MontoyaApi api, ConfigLoader configLoader, Object[][] data, JTabbedP private void initComponents(Object[][] data) { setLayout(new GridBagLayout()); - ((GridBagLayout)getLayout()).columnWidths = new int[] {0, 0, 0}; - ((GridBagLayout)getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0}; - ((GridBagLayout)getLayout()).columnWeights = new double[] {0.0, 1.0, 1.0E-4}; - ((GridBagLayout)getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 1.0, 1.0E-4}; + ((GridBagLayout) getLayout()).columnWidths = new int[]{0, 0, 0}; + ((GridBagLayout) getLayout()).rowHeights = new int[]{0, 0, 0, 0, 0}; + ((GridBagLayout) getLayout()).columnWeights = new double[]{0.0, 1.0, 1.0E-4}; + ((GridBagLayout) getLayout()).rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 1.0E-4}; JButton addButton = new JButton("Add"); JButton editButton = new JButton("Edit"); @@ -74,7 +73,7 @@ public boolean isCellEditable(int row, int column) { model.setDataVector(data, Config.ruleFields); model.addTableModelListener(e -> { - if (e.getColumn() == 0 && ruleTable.getSelectedRow() != -1){ + if (e.getColumn() == 0 && ruleTable.getSelectedRow() != -1) { int select = ruleTable.convertRowIndexToModel(ruleTable.getSelectedRow()); ruleProcessor.changeRule(model.getDataVector().get(select), select, tabbedPane.getTitleAt(tabbedPane.getSelectedIndex())); } @@ -117,8 +116,8 @@ private void ruleAddActionPerformed(ActionEvent e, JTable ruleTable, JTabbedPane } } - private void ruleEditActionPerformed(ActionEvent e, JTable ruleTable, JTabbedPane tabbedPane){ - if (ruleTable.getSelectedRowCount() >= 1){ + private void ruleEditActionPerformed(ActionEvent e, JTable ruleTable, JTabbedPane tabbedPane) { + if (ruleTable.getSelectedRowCount() >= 1) { DefaultTableModel model = (DefaultTableModel) ruleTable.getModel(); Display ruleDisplay = new Display(); @@ -129,12 +128,12 @@ private void ruleEditActionPerformed(ActionEvent e, JTable ruleTable, JTabbedPan ruleDisplay.colorComboBox.setSelectedItem(ruleTable.getValueAt(ruleTable.getSelectedRow(), 5).toString()); ruleDisplay.scopeComboBox.setSelectedItem(ruleTable.getValueAt(ruleTable.getSelectedRow(), 6).toString()); ruleDisplay.engineComboBox.setSelectedItem(ruleTable.getValueAt(ruleTable.getSelectedRow(), 7).toString()); - ruleDisplay.sensitiveComboBox.setSelectedItem(ruleTable.getValueAt(ruleTable.getSelectedRow(),8)); + ruleDisplay.sensitiveComboBox.setSelectedItem(ruleTable.getValueAt(ruleTable.getSelectedRow(), 8)); ruleDisplay.formatTextField.setEnabled(ruleDisplay.engineComboBox.getSelectedItem().toString().equals("nfa")); int showState = JOptionPane.showConfirmDialog(null, ruleDisplay, "Edit Rule", JOptionPane.OK_OPTION); - if (showState == 0){ + if (showState == 0) { int select = ruleTable.convertRowIndexToModel(ruleTable.getSelectedRow()); model.setValueAt(ruleDisplay.ruleNameTextField.getText(), select, 1); model.setValueAt(ruleDisplay.firstRegexTextField.getText(), select, 2); @@ -150,9 +149,9 @@ private void ruleEditActionPerformed(ActionEvent e, JTable ruleTable, JTabbedPan } } - private void ruleRemoveActionPerformed(ActionEvent e, JTable ruleTable, JTabbedPane tabbedPane){ - if (ruleTable.getSelectedRowCount() >= 1){ - if (JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this rule?", "Info", JOptionPane.OK_OPTION) == 0){ + private void ruleRemoveActionPerformed(ActionEvent e, JTable ruleTable, JTabbedPane tabbedPane) { + if (ruleTable.getSelectedRowCount() >= 1) { + if (JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this rule?", "Info", JOptionPane.OK_OPTION) == 0) { DefaultTableModel model = (DefaultTableModel) ruleTable.getModel(); int select = ruleTable.convertRowIndexToModel(ruleTable.getSelectedRow()); diff --git a/src/main/java/hae/component/rule/Rules.java b/src/main/java/hae/component/rule/Rules.java index a4e3110..e800358 100644 --- a/src/main/java/hae/component/rule/Rules.java +++ b/src/main/java/hae/component/rule/Rules.java @@ -103,7 +103,7 @@ public void reloadRuleGroup() { removeAll(); this.configLoader = new ConfigLoader(api); - Config.globalRules.keySet().forEach(i-> addTab(i, new Rule(api, configLoader, hae.Config.globalRules.get(i), this))); + Config.globalRules.keySet().forEach(i -> addTab(i, new Rule(api, configLoader, hae.Config.globalRules.get(i), this))); addTab("...", null); } @@ -120,7 +120,7 @@ private void deleteRuleGroupActionPerformed(ActionEvent e) { } } - private Action renameTitleActionPerformed = new AbstractAction() { + private final Action renameTitleActionPerformed = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { String title = ruleGroupNameTextField.getText(); @@ -136,7 +136,7 @@ public void actionPerformed(ActionEvent e) { } }; - private Action cancelActionPerformed = new AbstractAction() { + private final Action cancelActionPerformed = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (selectedIndex >= 0) { diff --git a/src/main/java/hae/instances/editor/RequestEditor.java b/src/main/java/hae/instances/editor/RequestEditor.java index 2fd175d..a08a6a4 100644 --- a/src/main/java/hae/instances/editor/RequestEditor.java +++ b/src/main/java/hae/instances/editor/RequestEditor.java @@ -3,12 +3,12 @@ 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.http.message.HttpRequestResponse; import burp.api.montoya.http.message.requests.HttpRequest; import burp.api.montoya.ui.Selection; +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 hae.component.board.Datatable; import hae.instances.http.utils.MessageProcessor; @@ -36,10 +36,9 @@ private static class Editor implements ExtensionProvidedHttpRequestEditor { private final MessageProcessor messageProcessor; private HttpRequestResponse requestResponse; - private JTabbedPane jTabbedPane = new JTabbedPane(); + private final JTabbedPane jTabbedPane = new JTabbedPane(); - public Editor(MontoyaApi api, EditorCreationContext creationContext) - { + public Editor(MontoyaApi api, EditorCreationContext creationContext) { this.api = api; this.creationContext = creationContext; this.messageProcessor = new MessageProcessor(api); @@ -103,7 +102,7 @@ public static void generateTabbedPaneFromResultMap(MontoyaApi api, JTabbedPane t if (result != null && !result.isEmpty() && result.size() > 0) { Map dataMap = result.get(0); if (dataMap != null && !dataMap.isEmpty() && dataMap.size() > 0) { - dataMap.keySet().forEach(i->{ + dataMap.keySet().forEach(i -> { String[] extractData = dataMap.get(i).split("\n"); Datatable dataPanel = new Datatable(api, i, Arrays.asList(extractData)); tabbedPane.addTab(i, dataPanel); diff --git a/src/main/java/hae/instances/editor/ResponseEditor.java b/src/main/java/hae/instances/editor/ResponseEditor.java index 2055d9f..1f3716a 100644 --- a/src/main/java/hae/instances/editor/ResponseEditor.java +++ b/src/main/java/hae/instances/editor/ResponseEditor.java @@ -5,10 +5,10 @@ import burp.api.montoya.core.Range; import burp.api.montoya.http.message.HttpRequestResponse; import burp.api.montoya.http.message.responses.HttpResponse; +import burp.api.montoya.ui.Selection; import burp.api.montoya.ui.editor.extension.EditorCreationContext; import burp.api.montoya.ui.editor.extension.ExtensionProvidedHttpResponseEditor; import burp.api.montoya.ui.editor.extension.HttpResponseEditorProvider; -import burp.api.montoya.ui.Selection; import hae.component.board.Datatable; import hae.instances.http.utils.MessageProcessor; @@ -35,10 +35,9 @@ private static class Editor implements ExtensionProvidedHttpResponseEditor { private final MessageProcessor messageProcessor; private HttpRequestResponse requestResponse; - private JTabbedPane jTabbedPane = new JTabbedPane(); + private final JTabbedPane jTabbedPane = new JTabbedPane(); - public Editor(MontoyaApi api, EditorCreationContext creationContext) - { + public Editor(MontoyaApi api, EditorCreationContext creationContext) { this.api = api; this.creationContext = creationContext; this.messageProcessor = new MessageProcessor(api); diff --git a/src/main/java/hae/instances/editor/WebSocketEditor.java b/src/main/java/hae/instances/editor/WebSocketEditor.java index 143e75d..39a439b 100644 --- a/src/main/java/hae/instances/editor/WebSocketEditor.java +++ b/src/main/java/hae/instances/editor/WebSocketEditor.java @@ -5,7 +5,9 @@ import burp.api.montoya.core.Range; import burp.api.montoya.ui.Selection; import burp.api.montoya.ui.contextmenu.WebSocketMessage; -import burp.api.montoya.ui.editor.extension.*; +import burp.api.montoya.ui.editor.extension.EditorCreationContext; +import burp.api.montoya.ui.editor.extension.ExtensionProvidedWebSocketMessageEditor; +import burp.api.montoya.ui.editor.extension.WebSocketMessageEditorProvider; import hae.component.board.Datatable; import hae.instances.http.utils.MessageProcessor; @@ -32,7 +34,7 @@ private static class Editor implements ExtensionProvidedWebSocketMessageEditor { private final MessageProcessor messageProcessor; private ByteArray message; - private JTabbedPane jTabbedPane = new JTabbedPane(); + private final JTabbedPane jTabbedPane = new JTabbedPane(); public Editor(MontoyaApi api, EditorCreationContext creationContext) { this.api = api; diff --git a/src/main/java/hae/instances/http/HttpMessageHandler.java b/src/main/java/hae/instances/http/HttpMessageHandler.java index 22a3153..b44def3 100644 --- a/src/main/java/hae/instances/http/HttpMessageHandler.java +++ b/src/main/java/hae/instances/http/HttpMessageHandler.java @@ -11,16 +11,19 @@ import hae.instances.http.utils.MessageProcessor; import hae.utils.string.StringProcessor; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; public class HttpMessageHandler implements HttpHandler { private final MontoyaApi api; - private MessageTableModel messageTableModel; + private final MessageTableModel messageTableModel; private final MessageProcessor messageProcessor; - private String host; // Montoya API对HTTP消息的处理分为了请求和响应,因此此处设置高亮和标记需要使用全局变量的方式,以此兼顾请求和响应 // 同时采用 ThreadLocal 来保证多线程并发的情况下全局变量的安全性 + private final ThreadLocal host = ThreadLocal.withInitial(() -> ""); private final ThreadLocal> colorList = ThreadLocal.withInitial(ArrayList::new); private final ThreadLocal> commentList = ThreadLocal.withInitial(ArrayList::new); private final ThreadLocal matches = ThreadLocal.withInitial(() -> false); @@ -41,13 +44,13 @@ public RequestToBeSentAction handleHttpRequestToBeSent(HttpRequestToBeSent httpR httpRequest.set(httpRequestToBeSent); - host = StringProcessor.getHostByUrl(httpRequestToBeSent.url()); + host.set(StringProcessor.getHostByUrl(httpRequestToBeSent.url())); List suffixList = Arrays.asList(Config.suffix.split("\\|")); matches.set(suffixList.contains(httpRequestToBeSent.fileExtension())); if (!matches.get()) { - List> result = messageProcessor.processRequest(host, httpRequestToBeSent, true); + List> result = messageProcessor.processRequest(host.get(), httpRequestToBeSent, true); setColorAndCommentList(result); } @@ -59,7 +62,7 @@ public ResponseReceivedAction handleHttpResponseReceived(HttpResponseReceived ht Annotations annotations = httpResponseReceived.annotations(); if (!matches.get()) { - List> result = messageProcessor.processResponse(host, httpResponseReceived, true); + List> result = messageProcessor.processResponse(host.get(), httpResponseReceived, true); setColorAndCommentList(result); // 设置高亮颜色和注释 if (!colorList.get().isEmpty() && !commentList.get().isEmpty()) { diff --git a/src/main/java/hae/instances/http/utils/MessageProcessor.java b/src/main/java/hae/instances/http/utils/MessageProcessor.java index 0cfe727..84e7578 100644 --- a/src/main/java/hae/instances/http/utils/MessageProcessor.java +++ b/src/main/java/hae/instances/http/utils/MessageProcessor.java @@ -24,6 +24,7 @@ public MessageProcessor(MontoyaApi api) { public List> processMessage(String host, String message, boolean flag) { Map> obj = null; + try { obj = regularMatcher.match(host, "any", message, message, message); } catch (Exception ignored) { @@ -34,6 +35,7 @@ public List> processMessage(String host, String message, boo public List> processResponse(String host, HttpResponse httpResponse, boolean flag) { Map> obj = null; + try { String response = new String(httpResponse.toByteArray().getBytes(), StandardCharsets.UTF_8); String body = new String(httpResponse.body().getBytes(), StandardCharsets.UTF_8); @@ -57,6 +59,7 @@ public List> processRequest(String host, HttpRequest httpReq String header = httpRequest.headers().stream() .map(HttpHeader::toString) .collect(Collectors.joining("\n")); + obj = regularMatcher.match(host, "request", request, header, body); } catch (Exception ignored) { } @@ -99,6 +102,7 @@ private Map extractDataFromMap(Map> String data = tempMap.get("data").toString(); extractedData.put(key, data); }); + return extractedData; } @@ -114,10 +118,11 @@ private List> extractColorsAndComments(Map> result = new ArrayList<>(); result.add(colorList); result.add(commentList); + return result; } - public List retrieveColorIndices(List colors){ + public List retrieveColorIndices(List colors) { List indices = new ArrayList<>(); String[] colorArray = Config.color; int size = colorArray.length; @@ -129,6 +134,7 @@ public List retrieveColorIndices(List colors){ } } } + return indices; } @@ -154,7 +160,7 @@ private void upgradeColors(List colorList) { HashSet tmpList = new HashSet(stack); if (stack.size() == tmpList.size()) { stack.sort(Comparator.comparingInt(Integer::intValue)); - if(stack.get(0) < 0) { + if (stack.get(0) < 0) { finalColor = colorArray[0]; } else { finalColor = colorArray[stack.get(0)]; diff --git a/src/main/java/hae/instances/http/utils/RegularMatcher.java b/src/main/java/hae/instances/http/utils/RegularMatcher.java index 44d6bc5..11e410e 100644 --- a/src/main/java/hae/instances/http/utils/RegularMatcher.java +++ b/src/main/java/hae/instances/http/utils/RegularMatcher.java @@ -202,8 +202,8 @@ private List getFormatString(Matcher matcher, String format) { while (matcher.find()) { if (!matcher.group(1).isEmpty()) { Object[] params = indexList.stream().map(i -> { - if (!matcher.group(i+1).isEmpty()) { - return matcher.group(i+1); + if (!matcher.group(i + 1).isEmpty()) { + return matcher.group(i + 1); } return ""; }).toArray(); diff --git a/src/main/java/hae/utils/config/ConfigLoader.java b/src/main/java/hae/utils/config/ConfigLoader.java index df7d1ba..b62a72f 100644 --- a/src/main/java/hae/utils/config/ConfigLoader.java +++ b/src/main/java/hae/utils/config/ConfigLoader.java @@ -1,15 +1,5 @@ package hae.utils.config; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.ArrayList; - import burp.api.montoya.MontoyaApi; import burp.api.montoya.http.message.HttpRequestResponse; import burp.api.montoya.http.message.requests.HttpRequest; @@ -18,6 +8,12 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.representer.Representer; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.*; + public class ConfigLoader { private final MontoyaApi api; private final Yaml yaml; @@ -32,7 +28,7 @@ public ConfigLoader(MontoyaApi api) { this.yaml = new Yaml(representer, dop); String configPath = determineConfigPath(); - this.configFilePath = String.format("%s/%s", configPath, "Config.yml"); + this.configFilePath = String.format("%s/%s", configPath, "Config.yml"); this.rulesFilePath = String.format("%s/%s", configPath, "Rules.yml"); // 构造函数,初始化配置 @@ -104,7 +100,7 @@ public String getExcludeSuffix() { if (r.containsKey("excludeSuffix")) { return r.get("excludeSuffix").toString(); } - }catch (Exception ignored) { + } catch (Exception ignored) { } return Config.suffix; @@ -147,16 +143,16 @@ public Map getRules() { } return rules; - } catch (Exception ignored){ + } catch (Exception ignored) { } return rules; } public void setExcludeSuffix(String excludeSuffix) { - Map r = new LinkedHashMap<>(); + Map r = new LinkedHashMap<>(); r.put("excludeSuffix", excludeSuffix); - try{ + try { Writer ws = new OutputStreamWriter(Files.newOutputStream(Paths.get(configFilePath)), StandardCharsets.UTF_8); yaml.dump(r, ws); ws.close(); diff --git a/src/main/java/hae/utils/rule/RuleProcessor.java b/src/main/java/hae/utils/rule/RuleProcessor.java index 0912098..f8769b9 100644 --- a/src/main/java/hae/utils/rule/RuleProcessor.java +++ b/src/main/java/hae/utils/rule/RuleProcessor.java @@ -2,11 +2,11 @@ import burp.api.montoya.MontoyaApi; import hae.Config; +import hae.utils.config.ConfigLoader; import hae.utils.rule.model.Group; import hae.utils.rule.model.Info; -import hae.utils.config.ConfigLoader; -import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.representer.Representer; import java.io.File; @@ -72,13 +72,14 @@ public void changeRule(Vector data, int select, String type) { public void addRule(Vector data, String type) { ArrayList x = new ArrayList<>(Arrays.asList(Config.globalRules.get(type))); x.add(data.toArray()); - Config.globalRules.put(type,x.toArray(new Object[x.size()][])); + Config.globalRules.put(type, x.toArray(new Object[x.size()][])); this.rulesFormatAndSave(); } - public void removeRule(int select,String type) { + + public void removeRule(int select, String type) { ArrayList x = new ArrayList<>(Arrays.asList(Config.globalRules.get(type))); x.remove(select); - Config.globalRules.put(type,x.toArray(new Object[x.size()][])); + Config.globalRules.put(type, x.toArray(new Object[x.size()][])); this.rulesFormatAndSave(); } diff --git a/src/main/java/hae/utils/string/HashCalculator.java b/src/main/java/hae/utils/string/HashCalculator.java index ef5b833..e69d3b6 100644 --- a/src/main/java/hae/utils/string/HashCalculator.java +++ b/src/main/java/hae/utils/string/HashCalculator.java @@ -3,7 +3,7 @@ import java.security.MessageDigest; public class HashCalculator { - public static String calculateHash(byte[] bytes){ + public static String calculateHash(byte[] bytes) { MessageDigest digest; try { digest = MessageDigest.getInstance("MD5");