Compare commits

...

9 Commits
2.5.1 ... 2.5.2

Author SHA1 Message Date
ᴋᴇʏ
e22596819b Version: 2.5.2 Update 2023-10-19 22:46:11 +08:00
ᴋᴇʏ
d2cd7a0d03 Version: 2.5.2 Update 2023-10-19 22:45:44 +08:00
ᴋᴇʏ
67afe1f650 Version: 2.5.2 Update 2023-10-19 22:44:34 +08:00
ᴋᴇʏ
0602346249 Version: 2.5.2 Update 2023-10-19 22:43:29 +08:00
ᴋᴇʏ
953b966961 Version: 2.5.2 Update 2023-10-19 22:42:54 +08:00
ᴋᴇʏ
4c23d62576 Version: 2.5.2 Update 2023-10-19 22:41:50 +08:00
ᴋᴇʏ
6e9b8c8f37 Version: 2.5.2 Update 2023-10-19 22:41:14 +08:00
ᴋᴇʏ
ed58d891d5 Version: 2.5.2 Update 2023-10-19 22:40:06 +08:00
ᴋᴇʏ
33f5cab037 Version: 2.5.2 Update 2023-10-19 22:38:50 +08:00
8 changed files with 104 additions and 76 deletions

View File

@@ -30,5 +30,4 @@ dependencies {
compile group: 'org.yaml', name: 'snakeyaml', version: '1.28' compile group: 'org.yaml', name: 'snakeyaml', version: '1.28'
compile 'net.sourceforge.jregex:jregex:1.2_01' compile 'net.sourceforge.jregex:jregex:1.2_01'
compile 'dk.brics.automaton:automaton:1.11-8' compile 'dk.brics.automaton:automaton:1.11-8'
compile 'com.squareup.okhttp:okhttp:2.7.5'
} }

View File

@@ -1,5 +1,6 @@
package burp; package burp;
import burp.config.ConfigLoader;
import burp.core.processor.ColorProcessor; import burp.core.processor.ColorProcessor;
import burp.core.processor.MessageProcessor; import burp.core.processor.MessageProcessor;
import burp.ui.MainUI; import burp.ui.MainUI;
@@ -19,10 +20,9 @@ import javax.swing.event.ChangeListener;
public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEditorTabFactory, ITab { public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEditorTabFactory, ITab {
private MainUI main; private MainUI main;
// stdout变成公开属性便于其他类调用输出调试信息
public static PrintWriter stdout; public static PrintWriter stdout;
private IBurpExtenderCallbacks callbacks; public static IBurpExtenderCallbacks callbacks;
private static IExtensionHelpers helpers; public static IExtensionHelpers helpers;
ColorProcessor colorProcessor = new ColorProcessor(); ColorProcessor colorProcessor = new ColorProcessor();
MessageProcessor messageProcessor = new MessageProcessor(); MessageProcessor messageProcessor = new MessageProcessor();
private MessagePanel messagePanel; private MessagePanel messagePanel;
@@ -30,10 +30,12 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
@Override @Override
public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks)
{ {
this.callbacks = callbacks; BurpExtender.callbacks = callbacks;
BurpExtender.helpers = callbacks.getHelpers(); BurpExtender.helpers = callbacks.getHelpers();
String version = "2.5.1"; new ConfigLoader();
String version = "2.5.2";
callbacks.setExtensionName(String.format("HaE (%s) - Highlighter and Extractor", version)); callbacks.setExtensionName(String.format("HaE (%s) - Highlighter and Extractor", version));
// 定义输出 // 定义输出
@@ -103,6 +105,7 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
} }
List<Map<String, String>> result = null; List<Map<String, String>> result = null;
try { try {
result = messageProcessor.processMessage(helpers, content, messageIsRequest, true, host); result = messageProcessor.processMessage(helpers, content, messageIsRequest, true, host);
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
@@ -155,7 +158,6 @@ public class BurpExtender implements IBurpExtender, IHttpListener, IMessageEdito
itemCounts.put(itemName, itemCounts.getOrDefault(itemName, 0) + count); itemCounts.put(itemName, itemCounts.getOrDefault(itemName, 0) + count);
} else { } else {
itemCounts.put(item, 0); itemCounts.put(item, 0);
BurpExtender.stdout.println(String.format("%s: %s", "A", item));
} }
} }

View File

@@ -1,5 +1,6 @@
package burp.config; package burp.config;
import burp.BurpExtender;
import burp.rule.utils.RuleTool; import burp.rule.utils.RuleTool;
import burp.rule.utils.YamlTool; import burp.rule.utils.YamlTool;
import java.io.*; import java.io.*;
@@ -19,7 +20,7 @@ import org.yaml.snakeyaml.Yaml;
public class ConfigLoader { public class ConfigLoader {
private static final Yaml yaml = YamlTool.newStandardYaml(); private static final Yaml yaml = YamlTool.newStandardYaml();
private static final String HaEConfigPath = String.format("%s/.config/HaE", System.getProperty("user.home")); private static final String HaEConfigPath = determineConfigPath();
private static final String RulesFilePath = String.format("%s/%s", HaEConfigPath, "Rules.yml"); private static final String RulesFilePath = String.format("%s/%s", HaEConfigPath, "Rules.yml");
private static final String ConfigFilePath = String.format("%s/%s", HaEConfigPath, "Config.yml"); private static final String ConfigFilePath = String.format("%s/%s", HaEConfigPath, "Config.yml");
@@ -31,44 +32,66 @@ public class ConfigLoader {
} }
File configFilePath = new File(ConfigFilePath); File configFilePath = new File(ConfigFilePath);
if (!(configFilePath.exists() && configFilePath.isFile())) { if (!(configFilePath.exists() && configFilePath.isFile())) {
initConfig(); initConfig();
}
File rulesFilePath = new File(RulesFilePath);
if (!(rulesFilePath.exists() && rulesFilePath.isFile())) {
initRules(); initRules();
} }
ConfigEntry.globalRules = ConfigLoader.getRules();
ConfigEntry.globalRules = getRules();
} }
public void initConfig() { private static String determineConfigPath() {
// 优先级1用户根目录
String userConfigPath = String.format("%s/.config/HaE", System.getProperty("user.home"));
if (isValidConfigPath(userConfigPath)) {
return userConfigPath;
}
// 优先级2Jar包所在目录
String jarPath = BurpExtender.callbacks.getExtensionFilename();
String jarDirectory = new File(jarPath).getParent();
String jarConfigPath = String.format("%s/.config/HaE", jarDirectory);
if (isValidConfigPath(jarConfigPath)) {
return jarConfigPath;
}
return userConfigPath;
}
private static boolean isValidConfigPath(String configPath) {
File configPathFile = new File(configPath);
return configPathFile.exists() && configPathFile.isDirectory();
}
public static void initConfig() {
Map<String, Object> r = new LinkedHashMap<>(); Map<String, Object> r = new LinkedHashMap<>();
r.put("rulesPath", RulesFilePath);
r.put("excludeSuffix", getExcludeSuffix()); r.put("excludeSuffix", getExcludeSuffix());
try { try {
Writer ws = new OutputStreamWriter(Files.newOutputStream(Paths.get(ConfigFilePath)), StandardCharsets.UTF_8); Writer ws = new OutputStreamWriter(Files.newOutputStream(Paths.get(ConfigFilePath)), StandardCharsets.UTF_8);
yaml.dump(r, ws); yaml.dump(r, ws);
ws.close();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} }
public void initRules() { public static void initRules() {
RuleTool rt = new RuleTool(RulesFilePath); RuleTool rt = new RuleTool(RulesFilePath);
rt.getRulesFromSite(); rt.getRulesFromSite();
} }
public static String getRulesFilePath() { public static String getRulesFilePath() {
try { return RulesFilePath;
Map<String, Object> r = YamlTool.loadYaml(ConfigFilePath);
return r.get("rulesPath").toString();
} catch (Exception e) {
e.printStackTrace();
return RulesFilePath;
}
} }
public String getExcludeSuffix(){ public static String getExcludeSuffix(){
String excludeSuffix = ""; String excludeSuffix = "";
File yamlSetting = new File(ConfigFilePath); File yamlSetting = new File(ConfigFilePath);
if (yamlSetting.exists() && yamlSetting.isFile()) { if (yamlSetting.exists() && yamlSetting.isFile()) {
try { try {
InputStream inorder = Files.newInputStream(Paths.get(ConfigFilePath)); InputStream inorder = Files.newInputStream(Paths.get(ConfigFilePath));
@@ -81,6 +104,7 @@ public class ConfigLoader {
} else { } else {
excludeSuffix = ConfigEntry.excludeSuffix; excludeSuffix = ConfigEntry.excludeSuffix;
} }
return excludeSuffix; return excludeSuffix;
} }
@@ -112,20 +136,18 @@ public class ConfigLoader {
resRule.put(groupFields.get("group").toString(), dataArray); resRule.put(groupFields.get("group").toString(), dataArray);
} }
} }
return resRule; return resRule;
} }
public void setExcludeSuffix(String excludeSuffix){ public static void setExcludeSuffix(String excludeSuffix){
Map<String,Object> r = new LinkedHashMap<>(); Map<String,Object> r = new LinkedHashMap<>();
r.put("rulesPath", getRulesFilePath());
r.put("excludeSuffix", excludeSuffix); r.put("excludeSuffix", excludeSuffix);
try{ try{
Writer ws = new OutputStreamWriter(Files.newOutputStream(Paths.get(RulesFilePath)), StandardCharsets.UTF_8); Writer ws = new OutputStreamWriter(Files.newOutputStream(Paths.get(RulesFilePath)), StandardCharsets.UTF_8);
yaml.dump(r, ws); yaml.dump(r, ws);
ws.close();
}catch (Exception ex){ }catch (Exception ex){
ex.printStackTrace(); ex.printStackTrace();
} }
} }
} }

View File

@@ -9,11 +9,8 @@ import burp.config.ConfigLoader;
*/ */
public class MatchTool { public class MatchTool {
// 匹配后缀
ConfigLoader configLoader = new ConfigLoader();
public boolean matchUrlSuffix(String str) { public boolean matchUrlSuffix(String str) {
Pattern pattern = new Pattern(String.format("[\\w]+[\\.](%s)", configLoader.getExcludeSuffix()), REFlags.IGNORE_CASE); Pattern pattern = new Pattern(String.format("[\\w]+[\\.](%s)", ConfigLoader.getExcludeSuffix()), REFlags.IGNORE_CASE);
jregex.Matcher matcher = pattern.matcher(str); jregex.Matcher matcher = pattern.matcher(str);
return matcher.find(); return matcher.find();
} }

View File

@@ -1,9 +1,11 @@
package burp.rule.utils; package burp.rule.utils;
import com.squareup.okhttp.OkHttpClient; import burp.*;
import com.squareup.okhttp.Request; import burp.config.ConfigEntry;
import com.squareup.okhttp.Response; import burp.config.ConfigLoader;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.net.URL;
import java.util.Arrays;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
/** /**
@@ -17,19 +19,31 @@ public class RuleTool {
} }
public void getRulesFromSite() { public void getRulesFromSite() {
String url = "https://cdn.jsdelivr.net/gh/gh0stkey/HaE@gh-pages/Rules.yml"; // 以独立线程使用BurpSuite官方请求接口获取规则
OkHttpClient httpClient = new OkHttpClient(); Thread t = new Thread(()->{
Request httpRequest = new Request.Builder().url(url).get().build(); try {
URL url = new URL("https://cdn.jsdelivr.net/gh/gh0stkey/HaE@gh-pages/Rules.yml");
IHttpService iHttpService = BurpExtender.helpers.buildHttpService(url.getHost(), 443, true);
IHttpRequestResponse iHttpRequestResponse = BurpExtender.callbacks.makeHttpRequest(iHttpService, BurpExtender.helpers.buildHttpRequest(url));
byte[] responseByte = iHttpRequestResponse.getResponse();
IResponseInfo iResponseInfo = BurpExtender.helpers.analyzeResponse(responseByte);
int bodyOffset = iResponseInfo.getBodyOffset();
byte[] responseBodyByte = Arrays.copyOfRange(responseByte, bodyOffset, responseByte.length);
FileOutputStream fileOutputStream = new FileOutputStream(this.rulesFilePath);
fileOutputStream.write(responseBodyByte);
fileOutputStream.close();
JOptionPane.showMessageDialog(null, "Rules update successfully!", "Info",
JOptionPane.INFORMATION_MESSAGE);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e, "Error",
JOptionPane.ERROR_MESSAGE);
}
});
t.start();
try { try {
Response httpResponse = httpClient.newCall(httpRequest).execute(); t.join();
// 获取官方规则文件,在线更新写入 } catch (Exception e) {
FileOutputStream fileOutputStream = new FileOutputStream(this.rulesFilePath); e.printStackTrace();
fileOutputStream.write(httpResponse.body().bytes());
JOptionPane.showMessageDialog(null, "Rules updated successfully!", "Info",
JOptionPane.INFORMATION_MESSAGE);
} catch (Exception ignored) {
JOptionPane.showMessageDialog(null, "Please check your network!", "Error",
JOptionPane.ERROR_MESSAGE);
} }
} }
} }

View File

@@ -1,8 +1,9 @@
package burp.rule.utils; package burp.rule.utils;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Map; import java.util.Map;
import burp.BurpExtender;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -25,13 +26,11 @@ public class YamlTool {
public static Map<String, Object> loadYaml(String filePath) { public static Map<String, Object> loadYaml(String filePath) {
try { try {
InputStream inputStream = new FileInputStream(filePath); InputStream inputStream = Files.newInputStream(Paths.get(filePath));
Yaml yaml = newStandardYaml(); return newStandardYaml().load(inputStream);
return yaml.load(inputStream); } catch (Exception e) {
} catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} }
} }

View File

@@ -3,7 +3,6 @@ package burp.ui;
import burp.config.ConfigEntry; import burp.config.ConfigEntry;
import burp.config.ConfigLoader; import burp.config.ConfigLoader;
import burp.rule.RuleProcessor; import burp.rule.RuleProcessor;
import burp.rule.utils.RuleTool;
import burp.ui.board.Databoard; import burp.ui.board.Databoard;
import burp.ui.board.MessagePanel; import burp.ui.board.MessagePanel;
import burp.ui.rule.RulePane; import burp.ui.rule.RulePane;
@@ -21,7 +20,6 @@ import java.util.Map;
*/ */
public class MainUI extends JPanel { public class MainUI extends JPanel {
private final ConfigLoader loadConn = new ConfigLoader();
private MessagePanel messagePanel; private MessagePanel messagePanel;
public MainUI(MessagePanel messagePanel) { public MainUI(MessagePanel messagePanel) {
@@ -41,13 +39,9 @@ public class MainUI extends JPanel {
private void onlineUpdateActionPerformed(ActionEvent e) { private void onlineUpdateActionPerformed(ActionEvent e) {
// 添加提示框防止用户误触导致配置更新 // 添加提示框防止用户误触导致配置更新
int retCode = JOptionPane.showConfirmDialog(null, "Do you want to update config?", "Info", int retCode = JOptionPane.showConfirmDialog(null, "Do you want to update rules?", "Info", JOptionPane.YES_NO_OPTION);
JOptionPane.YES_NO_OPTION);
if (retCode == JOptionPane.YES_OPTION) { if (retCode == JOptionPane.YES_OPTION) {
String rulesFilePath = rulesPathTextField.getText(); ConfigLoader.initRules();
RuleTool rt = new RuleTool(rulesFilePath);
rt.getRulesFromSite();
new ConfigLoader();
reloadRule(); reloadRule();
} }
} }
@@ -61,7 +55,6 @@ public class MainUI extends JPanel {
i, i,
new RulePane(rules.get(i), ruleTabbedPane) new RulePane(rules.get(i), ruleTabbedPane)
) )
); );
ruleTabbedPane.addTab("...", new JLabel()); ruleTabbedPane.addTab("...", new JLabel());
ruleSwitch.setListen(true); ruleSwitch.setListen(true);
@@ -72,8 +65,7 @@ public class MainUI extends JPanel {
} }
private void excludeSuffixSaveActionPerformed(ActionEvent e) { private void excludeSuffixSaveActionPerformed(ActionEvent e) {
ConfigLoader loadCon = new ConfigLoader(); ConfigLoader.setExcludeSuffix(excludeSuffixTextField.getText());
loadCon.setExcludeSuffix(excludeSuffixTextField.getText());
} }
private void initComponents() { private void initComponents() {
JTabbedPane mainTabbedPane = new JTabbedPane(); JTabbedPane mainTabbedPane = new JTabbedPane();
@@ -154,7 +146,7 @@ public class MainUI extends JPanel {
ruleTabbedPane.addTab("...",new JLabel()); ruleTabbedPane.addTab("...",new JLabel());
rulesPathTextField.setText(ConfigLoader.getRulesFilePath()); rulesPathTextField.setText(ConfigLoader.getRulesFilePath());
excludeSuffixTextField.setText(loadConn.getExcludeSuffix()); excludeSuffixTextField.setText(ConfigLoader.getExcludeSuffix());
ruleSwitch = new TabTitleEditListener(ruleTabbedPane); ruleSwitch = new TabTitleEditListener(ruleTabbedPane);
ruleTabbedPane.addChangeListener(ruleSwitch); ruleTabbedPane.addChangeListener(ruleSwitch);
ruleTabbedPane.addMouseListener(ruleSwitch); ruleTabbedPane.addMouseListener(ruleSwitch);

View File

@@ -16,15 +16,16 @@ public class ColorRenderer extends DefaultTableCellRenderer {
public ColorRenderer(List<LogEntry> log, JTable table) { public ColorRenderer(List<LogEntry> log, JTable table) {
this.log = log; this.log = log;
this.colorMap.put("red", Color.RED); // 与BurpSuite的颜色保持一致
this.colorMap.put("orange", Color.ORANGE); this.colorMap.put("red", new Color(0xFF, 0x64, 0x64));
this.colorMap.put("yellow", Color.YELLOW); this.colorMap.put("orange", new Color(0xFF, 0xC8, 0x64));
this.colorMap.put("green", Color.GREEN); this.colorMap.put("yellow", new Color(0xFF, 0xFF, 0x64));
this.colorMap.put("cyan", Color.CYAN); this.colorMap.put("green", new Color(0x64, 0xFF, 0x64));
this.colorMap.put("blue", Color.BLUE); this.colorMap.put("cyan", new Color(0x64, 0xFF, 0xFF));
this.colorMap.put("pink", Color.PINK); this.colorMap.put("blue", new Color(0x64, 0x64, 0xFF));
this.colorMap.put("magenta", Color.MAGENTA); this.colorMap.put("pink", new Color(0xFF, 0xC8, 0xC8));
this.colorMap.put("gray", Color.GRAY); this.colorMap.put("magenta", new Color(0xFF, 0x64, 0xFF));
this.colorMap.put("gray", new Color(0xB4, 0xB4, 0xB4));
this.table = table; this.table = table;
} }
@@ -40,13 +41,15 @@ public class ColorRenderer extends DefaultTableCellRenderer {
Color color = colorMap.get(colorByLog); Color color = colorMap.get(colorByLog);
if (isSelected) { if (isSelected) {
// 如果行被选中,设置阴影颜色 // 通过更改RGB颜色来达成阴影效果
component.setBackground(new Color(173, 216, 230)); // Light Blue component.setBackground(new Color(color.getRed()-0x20, color.getGreen()-0x20, color.getBlue()-0x20));
} else { } else {
// 否则使用原始颜色 // 否则使用原始颜色
component.setBackground(color); component.setBackground(color);
} }
component.setForeground(Color.BLACK);
return component; return component;
} }