diff --git a/CHANGELOG.md b/CHANGELOG.md index c7561d7..dd9564a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,60 @@ # 更新日志 +## 2026-07-16 (v3.0.6) + +### 优化 + +- **指纹 URL 精确匹配开关** + + 被动指纹识别默认对任意路径的响应均跑正则匹配,会产生大量无意义的误匹配(如 `/druid/login.html` 命中 Swagger 规则)。 + + 新增开关「指纹 URL 匹配」(默认关闭),开启后规则的 `url` 字段不为空且不为 `"/"` 时,要求请求路径与规则 `url` 精确匹配才进行正则匹配;`url` 为空或 `"/"` 的规则不受影响,始终匹配。路径匹配自动清除查询参数和锚点,兼容完整 URL 格式。 + + 涉及文件: + - `Config.java` — 新增 `KEY_FINGERPRINT_URL_MATCH`,默认 `false` + - `RuleEngine.java` — 接口新增 `match(req, resp, requestPath)` 签名,旧签名保留为 default 方法兼容 + - `YamlRuleEngine.java` — 实现新签名,新增 `matchPath()` 方法 + - `CompositeRuleEngine.java` — 透传 `requestPath` + - `RequestPipeline.java` — 两处 `match()` 补传请求路径,`extractRequestPath()` 优先使用 Montoya `request.path()` + - `OtherTab.java` — 在「最大显示长度」下方新增开关 UI + - `messages_zh_CN.properties` / `messages_en_US.properties` — 开关文案 + +### 架构重构 + +- **YAML 配置统一为单一数据源 `YamlConfigStore`** + + 原先同一份 `Config_yaml.yaml` 被 `YamlConfigLoader`(运行时)与 `YamlConfigManager`(UI)两套实现分别持有,各自缓存、互不通知,UI 改规则后运行时常靠 mtime 巧合才刷新;`BurpExtender` 里还需要人肉 `invalidateCache()` 打补丁。 + + **改动**: + - 新增 `YamlConfigStore`:读(mtime 缓存)+ 写(index 级 CRUD)+ `mergeUpdate` + 变更监听,全局唯一 + - `BurpExtender` 创建并注入到 `FingerScan`、`YamlRuleEngine`、`IconHashRuleLoader` 与 UI 面板 + - 写盘成功后自动 `notifyListeners`,`IconHashRuleLoader` 索引与图标规则表自动重建 + - 删除 `YamlConfigLoader`、`YamlConfigManager` 及 `setOnReloadCallback` / `setOnRuleAddedCallback` + + 涉及文件: + - `YamlConfigStore.java`(新增) + - `BurpExtender.java`、`FingerScan.java` + - `YamlRuleEngine.java`、`IconHashRuleLoader.java` + - `FingerprintPanel.java`、`IconDataPanel.java` + - 删除 `YamlConfigLoader.java`、`YamlConfigManager.java` + +### Bug 修复 + +- **导入指纹规则会抹掉 `Icon_Hash_List`** + + 旧 `mergeUpdateYamlConfig` 合并后只写回 `Load_List` 与 `Bypass_List`,整文件覆盖导致已有 Icon Hash 规则丢失。 + + **修复**:`YamlConfigStore.mergeUpdate` 以完整旧配置为底合并,保留 `Icon_Hash_List` 及未知键;导入侧若含图标规则则按 name+hash 去重追加。 + +- **Gradle 产物版本与插件显示不一致 / 内置指纹库未打进 jar** + + `build.gradle` 仍为 `3.0.4`,而 `Constants`/`pom`/CHANGELOG 已是 `3.0.5`;`Config_yaml.yaml` 放在 `src/main/java/yaml/` 未进入 Gradle resources,首次安装无法释放默认指纹库。 + + **修复**: + - 版本号统一(本版起为 `3.0.6`:`Constants` / `build.gradle` / `extender/pom.xml`) + - `Config_yaml.yaml` 移至 `src/main/resources/` + - 内置 yaml 缺失时打 `Logger.error` 告警,不再静默 + ## 2026-06-04 (v3.0.5) ### Bug 修复 diff --git a/build.gradle b/build.gradle index f578e45..e4051e4 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'burp.tdou' -version = '3.0.4' +version = '3.0.6' java { sourceCompatibility = JavaVersion.VERSION_17 diff --git a/docs/superpowers/plans/2026-07-15-yaml-config-store.md b/docs/superpowers/plans/2026-07-15-yaml-config-store.md new file mode 100644 index 0000000..2601bdc --- /dev/null +++ b/docs/superpowers/plans/2026-07-15-yaml-config-store.md @@ -0,0 +1,896 @@ +# YamlConfigStore Unification Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Replace dual `YamlConfigLoader` + `YamlConfigManager` with a single injected `YamlConfigStore` so UI writes automatically refresh runtime rule indexes. + +**Architecture:** One `YamlConfigStore` owns all YAML read/write with mtime cache and change listeners. `BurpExtender` creates the only instance, injects it into `FingerScan`/engines, and registers one listener that reloads `IconHashRuleLoader`. Delete `YamlConfigManager` and `YamlConfigLoader`. + +**Tech Stack:** Java 17, SnakeYAML 2.6 (`SafeConstructor`), Burp Montoya API, Gradle shadowJar / Maven assembly, no existing unit-test framework (verify via compile + manual smoke). + +**Spec:** `docs/superpowers/specs/2026-07-15-yaml-config-store-design.md` + +## Global Constraints + +- Keep YAML schema keys: `Load_List`, `Bypass_List`, `Icon_Hash_List` (do not rename fields). +- Fingerprint CRUD is **index-based** (matches UI table rows); rule `id` is data only. +- Write path: write disk → invalidate cache → notify listeners (sync, same thread). +- Listener exceptions: catch per-listener, `Logger.error`, continue others. +- Failed writes: log error, **do not** notify listeners. +- No `System.out.println` in config code. +- Do not change `Config.extractDefaultYamlConfig` beyond what is already done. +- Plugin version remains `3.0.5` (`Constants.PLUGIN_VERSION`, `build.gradle`, `extender/pom.xml`). +- Temporary import/export `YamlConfigStore` instances must **not** register change listeners. + +--- + +## File Map + +| Action | Path | Responsibility | +|--------|------|----------------| +| Create | `extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigStore.java` | Single YAML data source | +| Delete | `extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigLoader.java` | Superseded | +| Delete | `extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java` | Superseded | +| Modify | `extender/src/main/java/burp/tdou/fingerscan/core/rule/YamlRuleEngine.java` | Depend on store | +| Modify | `extender/src/main/java/burp/tdou/fingerscan/core/iconhash/IconHashRuleLoader.java` | Depend on store | +| Modify | `extender/src/main/java/burp/tdou/fingerscan/ui/tab/FingerprintPanel.java` | Use store; drop reload callback | +| Modify | `extender/src/main/java/burp/tdou/fingerscan/ui/tab/IconDataPanel.java` | Use store; drop rule-added callback | +| Modify | `extender/src/main/java/burp/tdou/fingerscan/FingerScan.java` | Injected constructor | +| Modify | `extender/src/main/java/burp/BurpExtender.java` | Create/inject store; one listener | + +--- + +### Task 1: Create `YamlConfigStore` + +**Files:** +- Create: `extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigStore.java` +- Reference (do not keep): `extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigLoader.java` +- Reference (do not keep): `extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java` + +**Interfaces:** +- Produces: full `YamlConfigStore` public API used by later tasks (see step 2 code). + +- [ ] **Step 1: Create the class skeleton with fields, constructor, path helpers, cache invalidation, and listeners** + +Create `YamlConfigStore.java` with package `burp.tdou.fingerscan.config` and these imports: + +```java +package burp.tdou.fingerscan.config; + +import burp.tdou.common.log.Logger; +import org.yaml.snakeyaml.LoaderOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.SafeConstructor; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; +``` + +Class body (fields + lifecycle + listeners): + +```java +public class YamlConfigStore { + + private volatile String configFilePath; + private volatile Map cachedConfig; + private volatile long cachedLastModified = -1; + private volatile List> cachedEnabledRules; + private volatile List cachedScanPaths; + private volatile long cachedRulesLastModified = -1; + + private final List changeListeners = new CopyOnWriteArrayList<>(); + + public YamlConfigStore(String configFilePath) { + this.configFilePath = configFilePath != null ? configFilePath : getDefaultConfigPath(); + } + + public void setConfigFilePath(String newPath) { + if (newPath != null && !newPath.equals(this.configFilePath)) { + this.configFilePath = newPath; + invalidateCache(); + notifyListeners(); + Logger.debug("YamlConfigStore: config path updated to %s", newPath); + } + } + + public String getConfigFilePath() { + return configFilePath; + } + + private static String getDefaultConfigPath() { + String os = System.getProperty("os.name", "").toLowerCase(); + if (os.contains("mac")) { + return "/Applications/Burp Suite Professional.app/Contents/Resources/app/Config_yaml.yaml"; + } else if (os.contains("win")) { + String appData = System.getenv("APPDATA"); + return (appData != null ? appData : "") + "\\BurpSuite\\Config_yaml.yaml"; + } else { + return System.getProperty("user.home") + "/.BurpSuite/Config_yaml.yaml"; + } + } + + public void invalidateCache() { + cachedConfig = null; + cachedLastModified = -1; + cachedEnabledRules = null; + cachedScanPaths = null; + cachedRulesLastModified = -1; + } + + public void addChangeListener(Runnable listener) { + if (listener != null) { + changeListeners.add(listener); + } + } + + public void removeChangeListener(Runnable listener) { + changeListeners.remove(listener); + } + + private void notifyListeners() { + for (Runnable listener : changeListeners) { + try { + listener.run(); + } catch (Exception e) { + Logger.error("YamlConfigStore listener error: %s", e.getMessage()); + } + } + } + + // read/write methods added in next steps +} +``` + +- [ ] **Step 2: Implement read APIs (mtime cache)** + +Add these methods to `YamlConfigStore` (port from `YamlConfigLoader`, rename class references only): + +```java +@SuppressWarnings("unchecked") +public Map readConfig() { + String currentPath = burp.tdou.fingerscan.common.Config.get("yaml_config_path"); + if (currentPath != null && !currentPath.isEmpty() && !currentPath.equals(configFilePath)) { + setConfigFilePath(currentPath); + } + + File file = new File(configFilePath); + if (!file.exists()) { + Logger.debug("YAML config file not found: %s", configFilePath); + return new HashMap<>(); + } + + long lastModified = file.lastModified(); + if (cachedConfig != null && lastModified == cachedLastModified) { + return cachedConfig; + } + + try (InputStream is = new FileInputStream(file)) { + Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); + Map data = yaml.load(is); + cachedConfig = data != null ? data : new HashMap<>(); + cachedLastModified = lastModified; + cachedEnabledRules = null; + cachedScanPaths = null; + return cachedConfig; + } catch (Exception e) { + Logger.error("Failed to read YAML config: %s", e.getMessage()); + return cachedConfig != null ? cachedConfig : new HashMap<>(); + } +} + +@SuppressWarnings("unchecked") +public List> getFingerprintRules() { + Map config = readConfig(); + List> loadList = (List>) config.get("Load_List"); + return loadList != null ? loadList : new ArrayList<>(); +} + +@SuppressWarnings("unchecked") +public List> getEnabledRules() { + File file = new File(configFilePath); + long lastModified = file.exists() ? file.lastModified() : 0; + if (cachedEnabledRules != null && lastModified == cachedRulesLastModified) { + return cachedEnabledRules; + } + + List> rules = getFingerprintRules(); + List> enabled = new ArrayList<>(); + for (Map rule : rules) { + Object loaded = rule.get("loaded"); + if (Boolean.TRUE.equals(loaded)) { + enabled.add(rule); + } + } + cachedEnabledRules = enabled; + cachedRulesLastModified = lastModified; + return enabled; +} + +public List getScanPaths() { + File file = new File(configFilePath); + long lastModified = file.exists() ? file.lastModified() : 0; + if (cachedScanPaths != null && lastModified == cachedRulesLastModified) { + return cachedScanPaths; + } + + Set pathSet = new HashSet<>(); + for (Map rule : getEnabledRules()) { + Object urlObj = rule.get("url"); + if (urlObj != null) { + String url = urlObj.toString().trim(); + if (!url.isEmpty()) { + pathSet.add(url); + } + } + } + cachedScanPaths = new ArrayList<>(pathSet); + return cachedScanPaths; +} + +@SuppressWarnings("unchecked") +public List getBypassList() { + Map config = readConfig(); + List bypassList = (List) config.get("Bypass_List"); + return bypassList != null ? bypassList : new ArrayList<>(); +} + +@SuppressWarnings("unchecked") +public List> getIconHashRules() { + Map config = readConfig(); + List> list = (List>) config.get("Icon_Hash_List"); + return list != null ? list : new ArrayList<>(); +} + +public List generateRecursivePaths(String requestPath) { + List paths = new ArrayList<>(); + paths.add("/"); + if (requestPath == null || requestPath.isEmpty() || "/".equals(requestPath)) { + return paths; + } + String cleanPath = requestPath.split("\\?")[0].split("#")[0]; + String[] segments = cleanPath.split("/"); + StringBuilder currentPath = new StringBuilder(); + for (int i = 1; i < segments.length; i++) { + if (!segments[i].isEmpty()) { + currentPath.append("/").append(segments[i]); + if (i == segments.length - 1 && segments[i].contains(".")) { + break; + } + String path = currentPath.toString(); + if (!paths.contains(path)) { + paths.add(path); + } + } + } + return paths; +} +``` + +- [ ] **Step 3: Implement write APIs with notify-on-success** + +```java +public void writeConfig(Map data) { + try { + Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); + try (PrintWriter writer = new PrintWriter(new File(configFilePath))) { + yaml.dump(data, writer); + } + invalidateCache(); + notifyListeners(); + } catch (Exception e) { + Logger.error("Failed to write YAML config: %s", e.getMessage()); + // do not notify — file not updated + } +} + +@SuppressWarnings("unchecked") +public void addRule(Map rule) { + Map config = new HashMap<>(readConfig()); + List> loadList = new ArrayList<>(getFingerprintRules()); + rule.remove("id"); + loadList.add(rule); + config.put("Load_List", loadList); + writeConfig(config); +} + +@SuppressWarnings("unchecked") +public void updateRule(int index, Map updatedRule) { + Map config = new HashMap<>(readConfig()); + List> loadList = new ArrayList<>(getFingerprintRules()); + if (index < 0 || index >= loadList.size()) { + return; + } + updatedRule.remove("id"); + loadList.set(index, updatedRule); + config.put("Load_List", loadList); + writeConfig(config); +} + +@SuppressWarnings("unchecked") +public void removeRule(int index) { + Map config = new HashMap<>(readConfig()); + List> loadList = new ArrayList<>(getFingerprintRules()); + if (index < 0 || index >= loadList.size()) { + return; + } + loadList.remove(index); + config.put("Load_List", loadList); + writeConfig(config); +} + +@SuppressWarnings("unchecked") +public void addIconHashRule(Map rule) { + Map config = new HashMap<>(readConfig()); + List> list = new ArrayList<>(getIconHashRules()); + list.add(rule); + config.put("Icon_Hash_List", list); + writeConfig(config); +} + +@SuppressWarnings("unchecked") +public void updateIconHashRule(int index, Map updatedRule) { + Map config = new HashMap<>(readConfig()); + List> list = new ArrayList<>(getIconHashRules()); + if (index < 0 || index >= list.size()) { + return; + } + list.set(index, updatedRule); + config.put("Icon_Hash_List", list); + writeConfig(config); +} + +@SuppressWarnings("unchecked") +public void removeIconHashRule(int index) { + Map config = new HashMap<>(readConfig()); + List> list = new ArrayList<>(getIconHashRules()); + if (index < 0 || index >= list.size()) { + return; + } + list.remove(index); + config.put("Icon_Hash_List", list); + writeConfig(config); +} +``` + +- [ ] **Step 4: Implement `mergeUpdate` that preserves all keys (fixes Icon_Hash wipe bug)** + +```java +@SuppressWarnings("unchecked") +public void mergeUpdate(Map newYamlData) { + if (newYamlData == null) { + return; + } + // Start from full existing config so Icon_Hash_List and unknown keys survive + Map merged = new HashMap<>(readConfig()); + + List> oldLoadList = getFingerprintRules(); + List> newLoadList = (List>) newYamlData.get("Load_List"); + if (newLoadList != null) { + List> combined = new ArrayList<>(oldLoadList); + for (Map newRule : newLoadList) { + if (!isRuleInList(combined, newRule)) { + Map copy = new HashMap<>(newRule); + copy.remove("id"); + combined.add(copy); + } + } + merged.put("Load_List", combined); + } + + List oldBypass = getBypassList(); + List newBypass = (List) newYamlData.get("Bypass_List"); + if (newBypass != null) { + List combinedBypass = new ArrayList<>(oldBypass); + for (String bypass : newBypass) { + if (!combinedBypass.contains(bypass)) { + combinedBypass.add(bypass); + } + } + merged.put("Bypass_List", combinedBypass); + } + + List> oldIcons = getIconHashRules(); + List> newIcons = (List>) newYamlData.get("Icon_Hash_List"); + if (newIcons != null) { + List> combinedIcons = new ArrayList<>(oldIcons); + for (Map icon : newIcons) { + if (!isIconInList(combinedIcons, icon)) { + combinedIcons.add(new HashMap<>(icon)); + } + } + merged.put("Icon_Hash_List", combinedIcons); + } + + writeConfig(merged); +} + +private boolean isRuleInList(List> ruleList, Map targetRule) { + return ruleList.stream().anyMatch(rule -> + Objects.equals(rule.get("name"), targetRule.get("name")) + && Objects.equals(rule.get("method"), targetRule.get("method")) + && Objects.equals(rule.get("path"), targetRule.get("path"))); +} + +private boolean isIconInList(List> list, Map target) { + return list.stream().anyMatch(rule -> + Objects.equals(rule.get("name"), target.get("name")) + && Objects.equals(rule.get("murmur_hash"), target.get("murmur_hash")) + && Objects.equals(rule.get("md5"), target.get("md5"))); +} +``` + +- [ ] **Step 5: Commit** + +```bash +cd /Users/tdou/work/个人研究/ai开发/FingerScan-github +git add extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigStore.java +git commit -m "$(cat <<'EOF' +feat: add YamlConfigStore as single YAML config data source + +Introduce YamlConfigStore with mtime cache, index-based CRUD, +mergeUpdate that preserves Icon_Hash_List, and change listeners. + +Co-Authored-By: Claude Opus 4.8 +EOF +)" +``` + +--- + +### Task 2: Point rule engines at `YamlConfigStore` + +**Files:** +- Modify: `extender/src/main/java/burp/tdou/fingerscan/core/rule/YamlRuleEngine.java` +- Modify: `extender/src/main/java/burp/tdou/fingerscan/core/iconhash/IconHashRuleLoader.java` + +**Interfaces:** +- Consumes: `YamlConfigStore` read APIs (`getEnabledRules`, `getScanPaths`, `readConfig`) +- Produces: engines still constructible as `new YamlRuleEngine(store)` / `new IconHashRuleLoader(store)` + +- [ ] **Step 1: Update `YamlRuleEngine`** + +Replace import and field/constructor types: + +```java +// old +import burp.tdou.fingerscan.config.YamlConfigLoader; +private final YamlConfigLoader configLoader; +public YamlRuleEngine(YamlConfigLoader configLoader) { ... } + +// new +import burp.tdou.fingerscan.config.YamlConfigStore; +private final YamlConfigStore configStore; +public YamlRuleEngine(YamlConfigStore configStore) { + this.configStore = configStore; +} +``` + +Rename all `configLoader.` call sites in the file to `configStore.` (methods `getEnabledRules()` / `getScanPaths()` stay the same). Update the class javadoc line that mentions `YamlConfigLoader` → `YamlConfigStore`. + +- [ ] **Step 2: Update `IconHashRuleLoader`** + +Same rename pattern: + +```java +import burp.tdou.fingerscan.config.YamlConfigStore; + +private final YamlConfigStore configStore; + +public IconHashRuleLoader(YamlConfigStore configStore) { + this.configStore = configStore; +} +``` + +In `loadRules()`, change `configLoader.readConfig()` → `configStore.readConfig()`. Keep `invalidate()`, `loadRules()`, indexes unchanged. + +- [ ] **Step 3: Commit** + +```bash +git add extender/src/main/java/burp/tdou/fingerscan/core/rule/YamlRuleEngine.java \ + extender/src/main/java/burp/tdou/fingerscan/core/iconhash/IconHashRuleLoader.java +git commit -m "$(cat <<'EOF' +refactor: engines depend on YamlConfigStore + +YamlRuleEngine and IconHashRuleLoader now take YamlConfigStore. + +Co-Authored-By: Claude Opus 4.8 +EOF +)" +``` + +--- + +### Task 3: Migrate `FingerprintPanel` and `IconDataPanel` + +**Files:** +- Modify: `extender/src/main/java/burp/tdou/fingerscan/ui/tab/FingerprintPanel.java` +- Modify: `extender/src/main/java/burp/tdou/fingerscan/ui/tab/IconDataPanel.java` + +**Interfaces:** +- Consumes: `YamlConfigStore` write/read APIs from Task 1 +- Produces: panels constructible as `new FingerprintPanel(store)` / `new IconDataPanel(store, store)`; **no** `setOnReloadCallback` / `setOnRuleAddedCallback` + +- [ ] **Step 1: `FingerprintPanel` — type and field renames** + +1. Replace import: + ```java + // remove + import burp.tdou.fingerscan.core.YamlConfigManager; + // add + import burp.tdou.fingerscan.config.YamlConfigStore; + ``` +2. Change field: + ```java + private YamlConfigStore configStore; + ``` +3. Remove field and methods: + ```java + // DELETE these entirely + private Runnable onReloadCallback; + public void setOnReloadCallback(Runnable callback) { ... } + ``` +4. Constructor: + ```java + public FingerprintPanel(YamlConfigStore configStore) { + this.configStore = configStore; + // keep existing init that called loadFingerprintRules / loadIconHashRules + } + ``` +5. Replace every `configManager.` with `configStore.` then map method names: + +| Old call | New call | +|----------|----------| +| `configStore.getConfigFilePath()` | same | +| `configStore.setConfigFilePath(p)` | same | +| `configStore.getFingerprintRules()` | same | +| `configStore.addFingerprintRule(r)` | `configStore.addRule(r)` | +| `configStore.updateFingerprintRule(i, r)` | `configStore.updateRule(i, r)` | +| `configStore.removeFingerprintRule(i)` | `configStore.removeRule(i)` | +| `configStore.getIconHashRules()` | same | +| `configStore.addIconHashRule(r)` | same | +| `configStore.updateIconHashRule(i, r)` | same | +| `configStore.removeIconHashRule(i)` | same | +| `configStore.readYamlConfig()` | `configStore.readConfig()` | +| `configStore.writeYamlConfig(d)` | `configStore.writeConfig(d)` | +| `configStore.mergeUpdateYamlConfig(d)` | `configStore.mergeUpdate(d)` | + +6. Import/export temporary instances: + ```java + // import + YamlConfigStore importStore = new YamlConfigStore(importPath); + Map importData = importStore.readConfig(); + configStore.mergeUpdate(importData); + + // export + Map configData = configStore.readConfig(); + YamlConfigStore exportStore = new YamlConfigStore(exportPath); + exportStore.writeConfig(configData); + ``` + Do **not** call `addChangeListener` on import/export stores. + +7. `reloadConfig()` — remove callback invocation: + ```java + private void reloadConfig() { + loadFingerprintRules(); + loadIconHashRules(); + // path change already notified via setConfigFilePath → listeners + JOptionPane.showMessageDialog(this, "配置重新加载成功!", "提示", JOptionPane.INFORMATION_MESSAGE); + } + ``` + Keep `browseConfigFile()` calling `configStore.setConfigFilePath(selectedPath)` + `Config.put("yaml_config_path", selectedPath)`. + +- [ ] **Step 2: `IconDataPanel` — type and drop callback** + +1. Import `YamlConfigStore` instead of `YamlConfigManager`. +2. Field: `private final YamlConfigStore configStore;` +3. Constructor: `public IconDataPanel(IconHashStore store, YamlConfigStore configStore)` +4. Delete field + setter: + ```java + // DELETE + private Runnable onRuleAddedCallback; + public void setOnRuleAddedCallback(Runnable callback) { ... } + ``` +5. Where rule is added (~line 425), keep: + ```java + configStore.addIconHashRule(result); + // DELETE: if (onRuleAddedCallback != null) onRuleAddedCallback.run(); + ``` + Store write already notifies listeners. + +- [ ] **Step 3: Commit** + +```bash +git add extender/src/main/java/burp/tdou/fingerscan/ui/tab/FingerprintPanel.java \ + extender/src/main/java/burp/tdou/fingerscan/ui/tab/IconDataPanel.java +git commit -m "$(cat <<'EOF' +refactor: UI panels use YamlConfigStore + +FingerprintPanel and IconDataPanel take YamlConfigStore; remove +manual reload/rule-added callbacks in favor of store listeners. + +Co-Authored-By: Claude Opus 4.8 +EOF +)" +``` + +--- + +### Task 4: Inject store into `FingerScan` and `BurpExtender` + +**Files:** +- Modify: `extender/src/main/java/burp/tdou/fingerscan/FingerScan.java` +- Modify: `extender/src/main/java/burp/BurpExtender.java` + +**Interfaces:** +- Consumes: `YamlConfigStore` from Task 1; panels/engines from Tasks 2–3 +- Produces: single runtime instance owned by `BurpExtender`, injected everywhere + +- [ ] **Step 1: Rewrite `FingerScan` construction** + +Replace YAML-related imports/fields: + +```java +import burp.tdou.fingerscan.config.YamlConfigStore; +// remove YamlConfigLoader and YamlConfigManager imports + +private YamlConfigStore mConfigStore; +// remove: private YamlConfigManager mConfigManager; +``` + +Constructor: + +```java +public FingerScan(YamlConfigStore configStore) { + // existing tab setup for DataBoard / ConfigPanel stays + mConfigStore = configStore; + try { + mFingerprintPanel = new FingerprintPanel(configStore); + addTab("指纹管理", mFingerprintPanel); + } catch (Exception e) { + Logger.debug("YAML 指纹面板初始化失败: %s", e.getMessage()); + } + // DataPanel etc. unchanged +} +``` + +`initIconDataPanel`: + +```java +public void initIconDataPanel(IconHashStore store) { + mIconDataPanel = new IconDataPanel(store, mConfigStore); + addTab("图标数据", mIconDataPanel); + mIconDataPanel.loadIcons(); +} +``` + +`main` test entry: + +```java +public static void main(String[] args) { + Logger.init(true, System.out, System.err); + Config.init(null); + // look-and-feel block unchanged + YamlConfigStore store = new YamlConfigStore(Config.get("yaml_config_path")); + JFrame frame = new JFrame(Constants.PLUGIN_NAME + " v" + Constants.PLUGIN_VERSION); + frame.setSize(1400, 700); + FingerScan fingerScan = new FingerScan(store); + fingerScan.getDataBoardTab().testInit(); + frame.setContentPane(fingerScan); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setLocationRelativeTo(null); + frame.setVisible(true); +} +``` + +- [ ] **Step 2: Rewrite `BurpExtender` wiring** + +1. Imports: + ```java + // remove + import burp.tdou.fingerscan.config.YamlConfigLoader; + // add + import burp.tdou.fingerscan.config.YamlConfigStore; + ``` +2. Field: `private YamlConfigStore mYamlConfigStore;` (replace `mYamlConfigLoader`). +3. In `initNewArchitecture()`: + ```java + String yamlPath = Config.get("yaml_config_path"); + mYamlConfigStore = new YamlConfigStore(yamlPath); + + YamlRuleEngine yamlEngine = new YamlRuleEngine(mYamlConfigStore); + CompositeRuleEngine ruleEngine = new CompositeRuleEngine().register(yamlEngine); + + mIconHashRuleLoader = new IconHashRuleLoader(mYamlConfigStore); + mIconHashRuleLoader.loadRules(); + // rest of architecture setup unchanged + ``` +4. Where UI is created (currently `mFingerScan = new FingerScan();`): + ```java + mFingerScan = new FingerScan(mYamlConfigStore); + ``` +5. **Delete** the entire blocks that register: + - `mFingerScan.getIconDataPanel().setOnRuleAddedCallback(...)` + - `mFingerScan.getFingerprintPanel().setOnReloadCallback(...)` +6. **After** `mFingerScan` is created and icon panel init finishes, register the single listener: + ```java + mYamlConfigStore.addChangeListener(() -> { + if (mIconHashRuleLoader != null) { + mIconHashRuleLoader.invalidate(); + mIconHashRuleLoader.loadRules(); + } + if (mFingerScan != null && mFingerScan.getFingerprintPanel() != null) { + mFingerScan.getFingerprintPanel().loadIconHashRules(); + } + }); + ``` + Place this once after both `initIconDataPanel` and fingerprint panel exist (same region where the old callbacks were). + +7. Grep for remaining `mYamlConfigLoader` / `YamlConfigLoader` / `YamlConfigManager` / `setOnReloadCallback` / `setOnRuleAddedCallback` in `BurpExtender.java` — must be zero. + +- [ ] **Step 3: Commit** + +```bash +git add extender/src/main/java/burp/tdou/fingerscan/FingerScan.java \ + extender/src/main/java/burp/BurpExtender.java +git commit -m "$(cat <<'EOF' +refactor: inject single YamlConfigStore from BurpExtender + +FingerScan takes store via constructor; BurpExtender registers one +change listener and drops manual invalidate callbacks. + +Co-Authored-By: Claude Opus 4.8 +EOF +)" +``` + +--- + +### Task 5: Delete old classes and verify compile + +**Files:** +- Delete: `extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigLoader.java` +- Delete: `extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java` + +- [ ] **Step 1: Ensure no remaining references** + +```bash +cd /Users/tdou/work/个人研究/ai开发/FingerScan-github +grep -rn "YamlConfigLoader\|YamlConfigManager\|setOnReloadCallback\|setOnRuleAddedCallback\|addFingerprintRule\|readYamlConfig\|mergeUpdateYamlConfig" \ + extender/src --include="*.java" +``` + +Expected: **no matches** (or only historical comments you intentionally keep — prefer zero). + +If any remain, fix them before deleting files. + +- [ ] **Step 2: Delete the two old source files** + +```bash +git rm extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigLoader.java \ + extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java +``` + +- [ ] **Step 3: Compile with Gradle** + +```bash +# use project-required JDK 17 + Maven/Gradle env if needed +source ~/.zshrc 2>/dev/null +# if shell helpers exist from prior sessions: +# jdk17; # optional +cd /Users/tdou/work/个人研究/ai开发/FingerScan-github +./gradlew build -q 2>&1 || gradle build -q 2>&1 +``` + +Expected: **BUILD SUCCESSFUL**, artifact name contains `v3.0.5` (e.g. `FingerScan-v3.0.5.jar` under `build/libs/`). + +If Gradle wrapper is missing, use Maven instead: + +```bash +# after jdk17 && maven39 if those aliases exist +cd /Users/tdou/work/个人研究/ai开发/FingerScan-github +mvn -q -pl extender package +``` + +Expected: jar under `extender/target/` named like `FingerScan-v3.0.5.jar` (from assembly `finalName`). + +- [ ] **Step 4: Grep for leftover debug prints in config path** + +```bash +grep -rn "System.out.println" extender/src/main/java/burp/tdou/fingerscan/config \ + extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java 2>/dev/null || true +``` + +Expected: no hits (Manager already deleted). + +- [ ] **Step 5: Commit** + +```bash +git add -A extender/src/main/java/burp/tdou/fingerscan/config \ + extender/src/main/java/burp/tdou/fingerscan/core +git commit -m "$(cat <<'EOF' +chore: remove YamlConfigLoader and YamlConfigManager + +Single YamlConfigStore is now the only YAML config entry point. + +Co-Authored-By: Claude Opus 4.8 +EOF +)" +``` + +--- + +### Task 6: Manual smoke checklist (acceptance) + +**Files:** none (runtime verification) + +- [ ] **Step 1: Load plugin in Burp** + +Load `FingerScan-v3.0.5.jar`. Confirm suite tab shows version `v3.0.5` and fingerprint rules load from workdir `Config_yaml.yaml`. + +- [ ] **Step 2: Fingerprint CRUD auto-applies** + +1. Add a distinctive enabled rule (unique path/body marker). +2. Without clicking "重新加载", send a matching request through proxy/listen or "发送到插件". +3. Expected: match appears in scan results. + +- [ ] **Step 3: Icon hash rule auto-applies** + +1. From 图标数据, convert an icon to a rule (or add icon hash rule in 指纹管理). +2. Without manual reload, re-trigger icon analysis for that favicon. +3. Expected: match name updates; fingerprint panel icon-hash table refreshes via listener. + +- [ ] **Step 4: Path switch and import merge** + +1. Switch yaml path in UI to a copy of config; confirm rules reload and scans use new file. +2. Import a yaml that only contains `Load_List`; confirm existing `Icon_Hash_List` entries remain. + +- [ ] **Step 5: Final commit if smoke required small fixes** + +If smoke found bugs, fix and commit with messages like `fix: ...`. If clean, no extra commit. + +Optional: mark spec status to "已实现" in `docs/superpowers/specs/2026-07-15-yaml-config-store-design.md` and commit docs. + +```bash +git add docs/superpowers/specs/2026-07-15-yaml-config-store-design.md +git commit -m "$(cat <<'EOF' +docs: mark YamlConfigStore design as implemented + +Co-Authored-By: Claude Opus 4.8 +EOF +)" +``` + +--- + +## Spec Coverage Check + +| Spec requirement | Task | +|------------------|------| +| Single `YamlConfigStore` instance | Task 1 + 4 | +| Change listeners, auto refresh | Task 1 + 4 | +| Delete Manager + Loader | Task 5 | +| Index-based fingerprint CRUD | Task 1 + 3 | +| Icon hash CRUD | Task 1 + 3 | +| `mergeUpdate` preserves `Icon_Hash_List` | Task 1 Step 4 + Task 6 Step 4 | +| No dead `parseYamlString` / `getIgnoreExtensions` | Task 1 (omitted intentionally) | +| Inject into `FingerScan` | Task 4 | +| Remove manual invalidate callbacks | Task 3 + 4 | +| No System.out in config path | Task 1 + 5 | +| Version 3.0.5 build | Task 5 compile | +| `FingerScan.main` works | Task 4 Step 1 | + +## Placeholder / Consistency Check + +- No TBD/TODO left in steps. +- Method names consistent: `addRule` / `updateRule(int,)` / `removeRule(int,)` / `mergeUpdate` / `readConfig` / `writeConfig`. +- Field name after migration: `configStore` / `mYamlConfigStore` / `mConfigStore` (not mixed with old Manager names). diff --git a/docs/superpowers/specs/2026-07-15-yaml-config-store-design.md b/docs/superpowers/specs/2026-07-15-yaml-config-store-design.md new file mode 100644 index 0000000..f237c0b --- /dev/null +++ b/docs/superpowers/specs/2026-07-15-yaml-config-store-design.md @@ -0,0 +1,341 @@ +# YamlConfigStore 统一配置架构设计 + +**日期**: 2026-07-15 +**状态**: 已实现 +**范围**: FingerScan-github 指纹/图标规则 YAML 配置的读写与运行时同步 + +--- + +## 1. 背景与问题 + +当前同一份 `Config_yaml.yaml` 被 **3 个对象、2 份缓存** 包着: + +``` +BurpExtender.initNewArchitecture() + └─ new YamlConfigLoader(path) ← 实例 A(运行时:YamlRuleEngine / IconHashRuleLoader) + └─ 缓存 A(mtime) + +FingerScan() ← 无参构造,内部自建 + ├─ new YamlConfigLoader(path) ← 实例 B(只为 getConfigFilePath()) + └─ new YamlConfigManager(path) ← 实例 C(UI 读写,无缓存,独立 FileInputStream) +``` + +### 具体病灶 + +| # | 问题 | 表现 | +|---|------|------| +| 1 | 多实例缓存不通气 | UI 经 Manager 写文件后,运行时实例 A 全靠 mtime 巧合失效 | +| 2 | 手动 `invalidateCache` 打补丁 | `BurpExtender` 281/296 行人肉清缓存 + 重载,漏一处就是 bug | +| 3 | 旧类重复实现 | `YamlConfigManager`(`@version 2.0`)重复了 `readConfig / getFingerprintRules / generateRecursivePaths / getScanPaths`,还残留 `System.out.println` | +| 4 | 隐藏依赖 | `FingerScan` 无参构造内部自建依赖,无法注入,是多实例的根源 | + +--- + +## 2. 目标 + +1. **单一数据源**:全局只存在一个配置对象,UI 与运行时共用。 +2. **写后自动刷新**:任何写操作完成后,运行时规则索引自动重建,删除所有手动 `invalidateCache` 调用点。 +3. **删除重复代码**:移除 `YamlConfigManager`,清理 `System.out.println`。 +4. **注入式初始化**:`FingerScan` 改为有参构造,由 `BurpExtender` 注入 store。 + +**非目标(YAGNI)**: +- 不改 YAML 文件格式 / 字段 schema +- 不改 `Config.extractDefaultYamlConfig` 的首次释放逻辑(已在本会话修好) +- 不引入异步线程做 reload(索引重建很快,同步即可) +- 不重构 `Config`(`config.json`)本身 + +--- + +## 3. 目标架构 + +``` +插件启动(BurpExtender) + │ + ① Config.init(workDir) + │ └─ extractDefaultYamlConfig() → 首次从 jar 释放内置 Config_yaml.yaml + │ └─ 路径写入 Config["yaml_config_path"] + │ + ② mYamlConfigStore = new YamlConfigStore(yaml_config_path) ← 全局唯一 + │ + ③ 组装运行时 + 注册监听者 + │ YamlRuleEngine(store) + │ IconHashRuleLoader(store) + │ store.addChangeListener(() -> { + │ iconHashRuleLoader.invalidate(); + │ iconHashRuleLoader.loadRules(); + │ // YamlRuleEngine 无独立索引,下次 match 时走 store 缓存即可 + │ }) + │ + ④ mFingerScan = new FingerScan(store) ← 有参构造,注入同一个 store + │ FingerprintPanel(store) + │ IconDataPanel(store) + │ + ⑤ 不再有 YamlConfigManager;不再有第二份 YamlConfigLoader +``` + +### 读路径 + +任意调用方 → `store.readConfig()` / `getEnabledRules()` / `getIconHashRules()`: + +1. 检查 `Config.get("yaml_config_path")` 是否被 UI 改过;改过则切路径并清缓存。 +2. 比对文件 mtime:命中缓存 → 直接返回;未命中 → `SafeConstructor` 解析 → 更新缓存 → 返回。 + +### 写路径 + 自动刷新 + +``` +FingerprintPanel / IconDataPanel + │ + ▼ +store.addRule / updateRule / removeRule / addIconHashRule / ... + │ + ├─ 写文件 + ├─ 清自己的缓存 + └─ 通知所有 listener ──┬─► IconHashRuleLoader.reload() + └─► (其他监听者) +``` + +`BurpExtender` 现有两处手动 `invalidateCache() + loadRules()`(约 281、296 行)**全部删除**,改为启动时一次性 `addChangeListener`。 + +--- + +## 4. 组件设计 + +### 4.1 `YamlConfigStore`(新建,由 `YamlConfigLoader` 演进) + +**包路径**: `burp.tdou.fingerscan.config.YamlConfigStore` +**旧类**: `YamlConfigLoader` 删除(或重命名后迁移,不保留双类)。 + +#### 公开 API + +```java +public class YamlConfigStore { + + // ---- 生命周期 ---- + public YamlConfigStore(String configFilePath); + public void setConfigFilePath(String newPath); // 切路径 + 清缓存 + 通知 + public String getConfigFilePath(); + + // ---- 读(带 mtime 缓存)---- + public Map readConfig(); + public List> getFingerprintRules(); + public List> getEnabledRules(); + public List getScanPaths(); + public List getBypassList(); + public List> getIconHashRules(); + public List generateRecursivePaths(String requestPath); + + // ---- 写(写完清缓存 + 通知)---- + public void writeConfig(Map data); + public void addRule(Map rule); + public void updateRule(int index, Map rule); + public void removeRule(int index); + public void addIconHashRule(Map rule); + public void updateIconHashRule(int index, Map rule); + public void removeIconHashRule(int index); + public void mergeUpdate(Map importData); // 导入合并 + + // ---- 缓存 / 观察者 ---- + public void invalidateCache(); // 外部强制清缓存(一般不需要) + public void addChangeListener(Runnable listener); + public void removeChangeListener(Runnable listener); +} +``` + +#### 关键实现约定 + +| 项 | 约定 | +|----|------| +| 反序列化 | 继续用 SnakeYAML `SafeConstructor` | +| 缓存键 | 文件 mtime;路径切换时强制失效 | +| 写后行为 | `writeConfig` 及所有写方法:写盘 → `invalidateCache()` → `notifyListeners()` | +| 通知线程 | **同步、当前线程**(UI 事件线程);索引重建很快,不引入后台线程 | +| 监听器异常 | 单个 listener 抛异常不影响其他 listener,记 `Logger.error` | +| 路径切换 | `setConfigFilePath` 同样清缓存 + 通知 | +| 默认路径 | 保留现有平台感知默认路径逻辑(mac/win/linux),仅作构造时 fallback | +| 日志 | 全部走 `Logger`,禁止 `System.out.println` | + +#### 从 `YamlConfigManager` 迁入的能力 + +- Icon Hash 规则 CRUD(`get/add/update/removeIconHashRule`) +- 导入合并(`mergeUpdate`,对应旧 `mergeUpdateYamlConfig`) +- 按索引更新/删除(UI 面板按 table row 操作,保留 index 语义) + +> 注:旧 `YamlConfigLoader` 的 `updateRule/removeRule` 按 id 操作;UI 实际按 index 操作(`updateFingerprintRule(row, rule)` 等)。统一为 **按 index**(与 UI 一致),id 仅作数据字段保留。 + +#### 明确不迁入(死代码) + +| 方法 | 原因 | +|------|------| +| `parseYamlString` | 全项目无调用 | +| `getIgnoreExtensions` | 全项目无调用;后缀过滤走 `Config.KEY_EXCLUDE_SUFFIX` | + +#### `mergeUpdate` 必须修复的既有 bug + +旧 `mergeUpdateYamlConfig` 合并后只写回: + +```java +mergedData.put("Load_List", oldLoadList); +mergedData.put("Bypass_List", oldBypassList); +writeYamlConfig(mergedData); // ← 整文件覆盖,Icon_Hash_List 被抹掉 +``` + +新 `mergeUpdate` 约定: + +1. 以 `readConfig()` 得到的**完整旧配置**为底(保留所有未知键,含 `Icon_Hash_List`)。 +2. 仅合并更新 `Load_List` 与 `Bypass_List`(及若导入侧存在的 `Icon_Hash_List`,按 name+hash 去重追加)。 +3. 写回完整 map,禁止只放两个 key 后覆盖。 + +#### 从 `YamlConfigLoader` 保留的能力 + +- mtime 缓存的 `readConfig / getEnabledRules / getScanPaths` +- `generateRecursivePaths` +- 平台默认路径 + +### 4.2 删除 `YamlConfigManager` + +- 文件:`extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java` **删除** +- 所有 import / 字段 / 构造参数改为 `YamlConfigStore` + +### 4.3 `FingerScan` 构造改造 + +```java +// 旧 +public FingerScan() { ... 内部 new YamlConfigLoader + YamlConfigManager ... } + +// 新 +public FingerScan(YamlConfigStore store) { + ... + mFingerprintPanel = new FingerprintPanel(store); + // IconDataPanel 仍在 initIconDataPanel 中创建,同样注入 store +} + +// 独立 main 测试入口 +public static void main(String[] args) { + Config.init(null); + YamlConfigStore store = new YamlConfigStore(Config.get("yaml_config_path")); + FingerScan fingerScan = new FingerScan(store); + ... +} +``` + +### 4.4 `FingerprintPanel` / `IconDataPanel` + +- 构造参数类型:`YamlConfigManager` → `YamlConfigStore` +- 方法调用映射: + +| 旧(Manager) | 新(Store) | +|---|---| +| `getConfigFilePath()` | 同名 | +| `setConfigFilePath(p)` | 同名 | +| `getFingerprintRules()` | 同名 | +| `addFingerprintRule(r)` | `addRule(r)` | +| `updateFingerprintRule(i, r)` | `updateRule(i, r)` | +| `removeFingerprintRule(i)` | `removeRule(i)` | +| `getIconHashRules()` | 同名 | +| `addIconHashRule(r)` | 同名 | +| `updateIconHashRule(i, r)` | 同名 | +| `removeIconHashRule(i)` | 同名 | +| `readYamlConfig()` | `readConfig()` | +| `writeYamlConfig(d)` | `writeConfig(d)` | +| `mergeUpdateYamlConfig(d)` | `mergeUpdate(d)` | +| `new YamlConfigManager(importPath)` 临时实例 | `new YamlConfigStore(importPath)` 临时实例(仅导入/导出路径,不注册 listener) | + +- **删除** `setOnReloadCallback`:不再需要 UI → BurpExtender 的手动回调;store 的 listener 替代它。 +- `IconDataPanel.setOnRuleAddedCallback` 同理删除;写 store 后自动通知。 + +### 4.5 `BurpExtender` 改动 + +```java +// initNewArchitecture +mYamlConfigStore = new YamlConfigStore(Config.get("yaml_config_path")); +YamlRuleEngine yamlEngine = new YamlRuleEngine(mYamlConfigStore); +mIconHashRuleLoader = new IconHashRuleLoader(mYamlConfigStore); +mIconHashRuleLoader.loadRules(); + +// 一次性注册监听者(替代 281/296 两处手动 invalidate) +mYamlConfigStore.addChangeListener(() -> { + mIconHashRuleLoader.invalidate(); + mIconHashRuleLoader.loadRules(); + // 若指纹面板已创建,刷新其 icon hash 表格显示 + if (mFingerScan != null && mFingerScan.getFingerprintPanel() != null) { + mFingerScan.getFingerprintPanel().loadIconHashRules(); + } +}); + +// 构造 UI +mFingerScan = new FingerScan(mYamlConfigStore); + +// 删除: +// mFingerScan.getIconDataPanel().setOnRuleAddedCallback(...) +// mFingerScan.getFingerprintPanel().setOnReloadCallback(...) +``` + +字段:`mYamlConfigLoader` → `mYamlConfigStore`。 + +### 4.6 `YamlRuleEngine` / `IconHashRuleLoader` + +- 构造参数类型:`YamlConfigLoader` → `YamlConfigStore` +- 调用的读方法名不变(`getEnabledRules` / `getScanPaths` / `readConfig`),内部无需大改 +- `IconHashRuleLoader` 保留自己的索引缓存 + `invalidate/loadRules`;由 store 的 listener 触发 + +--- + +## 5. 错误处理 + +| 场景 | 行为 | +|------|------| +| 配置文件不存在 | `readConfig()` 返回空 Map;`Logger.debug` 记录路径 | +| 解析失败 | 返回上次有效缓存(若有),否则空 Map;`Logger.error` | +| 写入失败 | `Logger.error`;**不**通知 listener(文件未变) | +| listener 抛异常 | 捕获、记日志、继续通知其余 listener | +| 内置 yaml 缺失 | 已有 `extractDefaultYamlConfig` 的 error 日志(本会话已加) | + +--- + +## 6. 迁移步骤(实现顺序) + +1. **新建** `YamlConfigStore`:以现有 `YamlConfigLoader` 为底,迁入 Manager 的 Icon Hash CRUD / mergeUpdate / 按 index 写接口,加入 listener 机制。 +2. **改** `YamlRuleEngine`、`IconHashRuleLoader` 依赖类型为 `YamlConfigStore`。 +3. **改** `FingerprintPanel`、`IconDataPanel` 依赖类型与方法映射;删除 `setOnReloadCallback` / `setOnRuleAddedCallback`。 +4. **改** `FingerScan` 有参构造 + `main` 测试入口。 +5. **改** `BurpExtender`:创建唯一 store、注入、注册 listener;删除两处手动 invalidate。 +6. **删除** `YamlConfigManager.java`、`YamlConfigLoader.java`。 +7. 编译验证;手动冒烟:改一条指纹规则 → 确认运行时立即生效、UI 表格刷新正常。 + +--- + +## 7. 风险与回退 + +| 风险 | 缓解 | +|------|------| +| UI 方法名映射遗漏 | 编译期暴露(类型删除后所有旧引用必挂) | +| listener 在 UI 线程做 reload 卡顿 | 实测 icon/指纹索引重建为毫秒级;若后续变慢再异步化 | +| `main` 测试入口忘改 | 编译期暴露 | +| 导入/导出临时 store 误注册 listener | 约定:临时实例不 `addChangeListener`;文档与代码注释标明 | + +回退:git revert 本改动即可;不涉及数据迁移。 + +--- + +## 8. 验收标准 + +- [ ] 全项目只存在 **一个** `YamlConfigStore` 运行时实例(`BurpExtender` 持有并注入) +- [ ] `YamlConfigManager` / `YamlConfigLoader` 源文件已删除 +- [ ] 代码中无 `System.out.println` 与 YAML 配置相关的调试输出 +- [ ] `BurpExtender` 中无手动 `invalidateCache` / `setOnReloadCallback` / `setOnRuleAddedCallback` +- [ ] UI 增删改指纹规则后,无需点"重新加载",运行时扫描即用新规则 +- [ ] UI 增删改 Icon Hash 规则后,icon 匹配立即生效 +- [ ] 切换配置文件路径后,UI 与运行时均读到新文件(`setConfigFilePath` 触发 listener) +- [ ] 导入合并后 `Icon_Hash_List` 不被抹掉(修复旧 `mergeUpdateYamlConfig` bug) +- [ ] `./gradlew build` / `mvn package` 成功,产物版本为 `v3.0.5` +- [ ] 独立 `FingerScan.main` 可启动(使用注入的 store) + +--- + +## 9. 已完成的前置修复(本会话) + +以下不在本 spec 实现范围内,但已落地,作为本改动的前置: + +1. `build.gradle` 版本 `3.0.4 → 3.0.5` +2. `Config_yaml.yaml` 从 `src/main/java/yaml/` 移至 `src/main/resources/`(修复打包缺失) +3. `extractDefaultYamlConfig` 在资源缺失时打 `Logger.error` 告警 diff --git a/extender/pom.xml b/extender/pom.xml index 42af84d..81e23cc 100644 --- a/extender/pom.xml +++ b/extender/pom.xml @@ -10,7 +10,7 @@ 4.0.0 extender - 3.0.5 + 3.0.6 FingerScan diff --git a/extender/src/main/java/burp/BurpExtender.java b/extender/src/main/java/burp/BurpExtender.java index 1649605..5ec6833 100644 --- a/extender/src/main/java/burp/BurpExtender.java +++ b/extender/src/main/java/burp/BurpExtender.java @@ -49,7 +49,7 @@ import burp.tdou.fingerscan.core.strategy.PayloadProcessingStrategy; import burp.tdou.fingerscan.core.strategy.RecursiveDirectoryScanStrategy; import burp.tdou.fingerscan.core.strategy.IconHashStrategy; -import burp.tdou.fingerscan.config.YamlConfigLoader; +import burp.tdou.fingerscan.config.YamlConfigStore; import burp.tdou.fingerscan.filter.FilterChain; import burp.tdou.fingerscan.filter.HostFilter; import burp.tdou.fingerscan.filter.MethodFilter; @@ -91,7 +91,7 @@ public class BurpExtender implements BurpExtension, // v3.0 新架构核心组件 private ScanOrchestrator mOrchestrator; - private YamlConfigLoader mYamlConfigLoader; + private YamlConfigStore mYamlConfigStore; private RecursiveDirectoryScanStrategy mRecursiveStrategy; private PayloadProcessingStrategy mPayloadStrategy; private IconHashStore mIconHashStore; @@ -142,17 +142,17 @@ public void extensionUnloaded() { */ private void initNewArchitecture() { try { - // 1. 配置加载器(带缓存 + SafeConstructor) + // 1. 配置存储(单一运行时 YamlConfigStore 实例) String yamlPath = Config.get("yaml_config_path"); - mYamlConfigLoader = new YamlConfigLoader(yamlPath); + mYamlConfigStore = new YamlConfigStore(yamlPath); // 2. 规则引擎(仅 YAML) - YamlRuleEngine yamlEngine = new YamlRuleEngine(mYamlConfigLoader); + YamlRuleEngine yamlEngine = new YamlRuleEngine(mYamlConfigStore); CompositeRuleEngine ruleEngine = new CompositeRuleEngine() .register(yamlEngine); // 2.5 Icon Hash 组件 - mIconHashRuleLoader = new IconHashRuleLoader(mYamlConfigLoader); + mIconHashRuleLoader = new IconHashRuleLoader(mYamlConfigStore); mIconHashRuleLoader.loadRules(); IconHashMatcher iconHashMatcher = new IconHashMatcher(mIconHashRuleLoader); String workDir = getWorkDir(); @@ -250,7 +250,7 @@ private void onScanResult(ScanResult result) { @SuppressWarnings("deprecation") private void initView() { - mFingerScan = new FingerScan(); + mFingerScan = new FingerScan(mYamlConfigStore); mDataBoardTab = mFingerScan.getDataBoardTab(); mFingerScan.getConfigPanel().setOnTabEventListener(this); // 将 DataBoardTab 传递给策略(读取 UI 开关状态) @@ -275,27 +275,20 @@ private void initView() { if (mIconHashStore != null) { mFingerScan.initIconDataPanel(mIconHashStore); } - // 注册图标面板"转为规则"后的刷新回调 - if (mFingerScan.getIconDataPanel() != null && mIconHashRuleLoader != null) { - mFingerScan.getIconDataPanel().setOnRuleAddedCallback(() -> { - mYamlConfigLoader.invalidateCache(); - mIconHashRuleLoader.invalidate(); - mIconHashRuleLoader.loadRules(); - if (mFingerScan.getFingerprintPanel() != null) { - mFingerScan.getFingerprintPanel().loadIconHashRules(); - } - }); - } // 初始化路径收集面板 if (mPathStore != null) { mFingerScan.initPathCollectPanel(mPathStore); } - // 注册重新加载回调,刷新运行时ICO规则 - if (mFingerScan.getFingerprintPanel() != null && mIconHashRuleLoader != null) { - mFingerScan.getFingerprintPanel().setOnReloadCallback(() -> { - mYamlConfigLoader.invalidateCache(); - mIconHashRuleLoader.invalidate(); - mIconHashRuleLoader.loadRules(); + // 写操作后自动刷新 IconHash 规则与指纹面板 icon 表 + if (mYamlConfigStore != null) { + mYamlConfigStore.addChangeListener(() -> { + if (mIconHashRuleLoader != null) { + mIconHashRuleLoader.invalidate(); + mIconHashRuleLoader.loadRules(); + } + if (mFingerScan != null && mFingerScan.getFingerprintPanel() != null) { + mFingerScan.getFingerprintPanel().loadIconHashRules(); + } }); } } diff --git a/extender/src/main/java/burp/tdou/fingerscan/FingerScan.java b/extender/src/main/java/burp/tdou/fingerscan/FingerScan.java index cbbd699..5927056 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/FingerScan.java +++ b/extender/src/main/java/burp/tdou/fingerscan/FingerScan.java @@ -3,8 +3,7 @@ import burp.tdou.common.log.Logger; import burp.tdou.fingerscan.common.Config; import burp.tdou.fingerscan.common.Constants; -import burp.tdou.fingerscan.config.YamlConfigLoader; -import burp.tdou.fingerscan.core.YamlConfigManager; +import burp.tdou.fingerscan.config.YamlConfigStore; import burp.tdou.fingerscan.core.iconhash.IconHashStore; import burp.tdou.fingerscan.core.path.PathStore; import burp.tdou.fingerscan.ui.tab.ConfigPanel; @@ -27,10 +26,11 @@ public class FingerScan extends JTabbedPane { private DataPanel mDataPanel; private IconDataPanel mIconDataPanel; private PathCollectPanel mPathCollectPanel; - private YamlConfigManager mConfigManager; + private YamlConfigStore mConfigStore; - public FingerScan() { + public FingerScan(YamlConfigStore configStore) { Logger.info(Constants.BANNER); + mConfigStore = configStore; initView(); } @@ -42,11 +42,7 @@ private void initView() { addTab(mConfigPanel.getTitleName(), mConfigPanel); try { - String yamlPath = Config.get("yaml_config_path"); - YamlConfigLoader loader = new YamlConfigLoader(yamlPath); - YamlConfigManager configManager = new YamlConfigManager(loader.getConfigFilePath()); - mConfigManager = configManager; - mFingerprintPanel = new FingerprintPanel(configManager); + mFingerprintPanel = new FingerprintPanel(mConfigStore); addTab("指纹管理", mFingerprintPanel); } catch (Exception e) { Logger.debug("YAML 指纹面板初始化失败: %s", e.getMessage()); @@ -64,7 +60,7 @@ private void initView() { public PathCollectPanel getPathCollectPanel() { return mPathCollectPanel; } public void initIconDataPanel(IconHashStore store) { - mIconDataPanel = new IconDataPanel(store, mConfigManager); + mIconDataPanel = new IconDataPanel(store, mConfigStore); addTab("图标数据", mIconDataPanel); mIconDataPanel.loadIcons(); } @@ -87,9 +83,10 @@ public static void main(String[] args) { } catch (Exception e) { Logger.error(e.getMessage()); } + YamlConfigStore store = new YamlConfigStore(Config.get("yaml_config_path")); JFrame frame = new JFrame(Constants.PLUGIN_NAME + " v" + Constants.PLUGIN_VERSION); frame.setSize(1400, 700); - FingerScan fingerScan = new FingerScan(); + FingerScan fingerScan = new FingerScan(store); fingerScan.getDataBoardTab().testInit(); frame.setContentPane(fingerScan); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); diff --git a/extender/src/main/java/burp/tdou/fingerscan/common/Config.java b/extender/src/main/java/burp/tdou/fingerscan/common/Config.java index a147046..066bb40 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/common/Config.java +++ b/extender/src/main/java/burp/tdou/fingerscan/common/Config.java @@ -48,6 +48,7 @@ public class Config { public static final String KEY_ENABLE_REPLACE_HEADER = "enable-replace-header"; public static final String KEY_ENABLE_PAYLOAD_PROCESSING = "payload-processing"; public static final String KEY_ENABLE_ACTIVE_SCAN = "enable-active-scan"; + public static final String KEY_FINGERPRINT_URL_MATCH = "fingerprint-url-match"; // 配置常量值 public static final String DIRECT_LEFT = "left"; public static final String DIRECT_RIGHT = "right"; @@ -94,6 +95,7 @@ public static void init(String wordDir) { initDefaultConfig(Config.KEY_ENABLE_REPLACE_HEADER, "true"); initDefaultConfig(Config.KEY_ENABLE_PAYLOAD_PROCESSING, "true"); initDefaultConfig(Config.KEY_ENABLE_ACTIVE_SCAN, "true"); + initDefaultConfig(Config.KEY_FINGERPRINT_URL_MATCH, "false"); initDefaultConfig("yaml_config_path", getWorkDir() + "Config_yaml.yaml"); // 初始化数据收集管理 // 初始化字典管理 @@ -313,6 +315,9 @@ private static void extractDefaultYamlConfig(String workDir) { if (is != null) { FileUtils.writeFile(is, yamlFile); Logger.info("Default fingerprint config extracted to: %s", yamlPath); + } else { + Logger.error("Built-in Config_yaml.yaml not found in classpath — " + + "packaging error, plugin will start with empty fingerprint rules"); } } catch (Exception e) { Logger.error("Failed to extract default yaml config: %s", e.getMessage()); diff --git a/extender/src/main/java/burp/tdou/fingerscan/common/Constants.java b/extender/src/main/java/burp/tdou/fingerscan/common/Constants.java index fc47bbc..9ef30f9 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/common/Constants.java +++ b/extender/src/main/java/burp/tdou/fingerscan/common/Constants.java @@ -11,7 +11,7 @@ public interface Constants { // 插件信息 String PLUGIN_NAME = "FingerScan"; - String PLUGIN_VERSION = "3.0.5"; + String PLUGIN_VERSION = "3.0.6"; boolean DEBUG = false; // 插件启动显示的信息 diff --git a/extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigLoader.java b/extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigStore.java similarity index 50% rename from extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigLoader.java rename to extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigStore.java index 83d4805..ed85cce 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigLoader.java +++ b/extender/src/main/java/burp/tdou/fingerscan/config/YamlConfigStore.java @@ -14,92 +14,105 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; /** - * YAML 配置加载器(带缓存 + SafeConstructor) - * - * 改进: - * - 使用 SafeConstructor 防止反序列化攻击 (CVE-2022-1471) - * - 基于文件修改时间的缓存,避免高频磁盘读取 - * - try-with-resources 保证资源释放 - * - 平台感知的默认路径 + * Unified YAML config data source with mtime cache, index-based CRUD, + * mergeUpdate that preserves Icon_Hash_List, and change listeners. */ -public class YamlConfigLoader { +public class YamlConfigStore { private volatile String configFilePath; - - // 缓存 private volatile Map cachedConfig; private volatile long cachedLastModified = -1; - - // 预处理缓存 private volatile List> cachedEnabledRules; private volatile List cachedScanPaths; private volatile long cachedRulesLastModified = -1; - public YamlConfigLoader(String configFilePath) { + private final List changeListeners = new CopyOnWriteArrayList<>(); + + public YamlConfigStore(String configFilePath) { this.configFilePath = configFilePath != null ? configFilePath : getDefaultConfigPath(); } - /** - * 更新配置文件路径并清除所有缓存 - */ public void setConfigFilePath(String newPath) { if (newPath != null && !newPath.equals(this.configFilePath)) { this.configFilePath = newPath; invalidateCache(); - Logger.debug("YamlConfigLoader: config path updated to %s", newPath); + notifyListeners(); + Logger.debug("YamlConfigStore: config path updated to %s", newPath); } } - /** - * 获取平台感知的默认配置路径 - */ + public String getConfigFilePath() { + return configFilePath; + } + private static String getDefaultConfigPath() { String os = System.getProperty("os.name", "").toLowerCase(); if (os.contains("mac")) { return "/Applications/Burp Suite Professional.app/Contents/Resources/app/Config_yaml.yaml"; } else if (os.contains("win")) { - return System.getenv("APPDATA") + "\\BurpSuite\\Config_yaml.yaml"; + String appData = System.getenv("APPDATA"); + return (appData != null ? appData : "") + "\\BurpSuite\\Config_yaml.yaml"; } else { return System.getProperty("user.home") + "/.BurpSuite/Config_yaml.yaml"; } } - /** - * 读取 YAML 配置(带缓存) - * 每次读取前检查 Config 中的路径是否变更 - */ + public void invalidateCache() { + cachedConfig = null; + cachedLastModified = -1; + cachedEnabledRules = null; + cachedScanPaths = null; + cachedRulesLastModified = -1; + } + + public void addChangeListener(Runnable listener) { + if (listener != null) { + changeListeners.add(listener); + } + } + + public void removeChangeListener(Runnable listener) { + changeListeners.remove(listener); + } + + private void notifyListeners() { + for (Runnable listener : changeListeners) { + try { + listener.run(); + } catch (Exception e) { + Logger.error("YamlConfigStore listener error: %s", e.getMessage()); + } + } + } + @SuppressWarnings("unchecked") public Map readConfig() { - // 检查路径是否被外部更新 String currentPath = burp.tdou.fingerscan.common.Config.get("yaml_config_path"); if (currentPath != null && !currentPath.isEmpty() && !currentPath.equals(configFilePath)) { setConfigFilePath(currentPath); } File file = new File(configFilePath); - if (!file.exists()) { Logger.debug("YAML config file not found: %s", configFilePath); return new HashMap<>(); } long lastModified = file.lastModified(); - - // 检查缓存是否有效 if (cachedConfig != null && lastModified == cachedLastModified) { return cachedConfig; } - // 重新加载 try (InputStream is = new FileInputStream(file)) { Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); Map data = yaml.load(is); cachedConfig = data != null ? data : new HashMap<>(); cachedLastModified = lastModified; - // 清除预处理缓存 cachedEnabledRules = null; cachedScanPaths = null; return cachedConfig; @@ -109,28 +122,6 @@ public Map readConfig() { } } - /** - * 写入 YAML 配置 - */ - public void writeConfig(Map data) { - try { - Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); - try (PrintWriter writer = new PrintWriter(new File(configFilePath))) { - yaml.dump(data, writer); - } - // 清除缓存 - cachedConfig = null; - cachedLastModified = -1; - cachedEnabledRules = null; - cachedScanPaths = null; - } catch (Exception e) { - Logger.error("Failed to write YAML config: %s", e.getMessage()); - } - } - - /** - * 获取所有指纹规则 - */ @SuppressWarnings("unchecked") public List> getFingerprintRules() { Map config = readConfig(); @@ -138,48 +129,36 @@ public List> getFingerprintRules() { return loadList != null ? loadList : new ArrayList<>(); } - /** - * 获取已启用的指纹规则(带缓存) - */ @SuppressWarnings("unchecked") public List> getEnabledRules() { File file = new File(configFilePath); long lastModified = file.exists() ? file.lastModified() : 0; - if (cachedEnabledRules != null && lastModified == cachedRulesLastModified) { return cachedEnabledRules; } List> rules = getFingerprintRules(); List> enabled = new ArrayList<>(); - for (Map rule : rules) { Object loaded = rule.get("loaded"); - if (loaded != null && Boolean.TRUE.equals(loaded)) { + if (Boolean.TRUE.equals(loaded)) { enabled.add(rule); } } - cachedEnabledRules = enabled; cachedRulesLastModified = lastModified; return enabled; } - /** - * 获取扫描路径列表(仅从已启用的规则中提取去重的 url 字段) - */ public List getScanPaths() { File file = new File(configFilePath); long lastModified = file.exists() ? file.lastModified() : 0; - if (cachedScanPaths != null && lastModified == cachedRulesLastModified) { return cachedScanPaths; } Set pathSet = new HashSet<>(); - List> rules = getEnabledRules(); - - for (Map rule : rules) { + for (Map rule : getEnabledRules()) { Object urlObj = rule.get("url"); if (urlObj != null) { String url = urlObj.toString().trim(); @@ -188,14 +167,10 @@ public List getScanPaths() { } } } - cachedScanPaths = new ArrayList<>(pathSet); return cachedScanPaths; } - /** - * 获取绕过路径列表 - */ @SuppressWarnings("unchecked") public List getBypassList() { Map config = readConfig(); @@ -203,128 +178,179 @@ public List getBypassList() { return bypassList != null ? bypassList : new ArrayList<>(); } - /** - * 基于请求路径生成递归扫描路径 - */ + @SuppressWarnings("unchecked") + public List> getIconHashRules() { + Map config = readConfig(); + List> list = (List>) config.get("Icon_Hash_List"); + return list != null ? list : new ArrayList<>(); + } + public List generateRecursivePaths(String requestPath) { List paths = new ArrayList<>(); paths.add("/"); - if (requestPath == null || requestPath.isEmpty() || "/".equals(requestPath)) { return paths; } - - // 清理路径 String cleanPath = requestPath.split("\\?")[0].split("#")[0]; String[] segments = cleanPath.split("/"); StringBuilder currentPath = new StringBuilder(); - for (int i = 1; i < segments.length; i++) { if (!segments[i].isEmpty()) { currentPath.append("/").append(segments[i]); - - // 最后一段如果有扩展名则跳过 if (i == segments.length - 1 && segments[i].contains(".")) { break; } - String path = currentPath.toString(); if (!paths.contains(path)) { paths.add(path); } } } - return paths; } - /** - * 添加指纹规则 - */ - public void addRule(Map rule) { - Map config = readConfig(); - List> loadList = getFingerprintRules(); - - // 安全检查 ID - Object idObj = rule.get("id"); - if (idObj == null) { - int maxId = loadList.stream() - .filter(r -> r.get("id") != null) - .mapToInt(r -> { - try { return Integer.parseInt(r.get("id").toString()); } - catch (NumberFormatException e) { return 0; } - }) - .max() - .orElse(0); - rule.put("id", maxId + 1); - } else { - // 检查重复 ID - String ruleId = idObj.toString(); - boolean exists = loadList.stream() - .anyMatch(r -> r.get("id") != null && r.get("id").toString().equals(ruleId)); - if (exists) { - return; + public void writeConfig(Map data) { + try { + Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); + try (PrintWriter writer = new PrintWriter(new File(configFilePath))) { + yaml.dump(data, writer); } + invalidateCache(); + notifyListeners(); + } catch (Exception e) { + Logger.error("Failed to write YAML config: %s", e.getMessage()); + // do not notify — file not updated } + } + @SuppressWarnings("unchecked") + public void addRule(Map rule) { + Map config = new HashMap<>(readConfig()); + List> loadList = new ArrayList<>(getFingerprintRules()); + rule.remove("id"); loadList.add(rule); config.put("Load_List", loadList); writeConfig(config); } - /** - * 更新指纹规则 - */ - public void updateRule(Map updatedRule) { - Map config = readConfig(); - List> loadList = getFingerprintRules(); - List> newList = new ArrayList<>(); + @SuppressWarnings("unchecked") + public void updateRule(int index, Map updatedRule) { + Map config = new HashMap<>(readConfig()); + List> loadList = new ArrayList<>(getFingerprintRules()); + if (index < 0 || index >= loadList.size()) { + return; + } + updatedRule.remove("id"); + loadList.set(index, updatedRule); + config.put("Load_List", loadList); + writeConfig(config); + } - String targetId = updatedRule.get("id") != null ? updatedRule.get("id").toString() : null; - if (targetId == null) return; + @SuppressWarnings("unchecked") + public void removeRule(int index) { + Map config = new HashMap<>(readConfig()); + List> loadList = new ArrayList<>(getFingerprintRules()); + if (index < 0 || index >= loadList.size()) { + return; + } + loadList.remove(index); + config.put("Load_List", loadList); + writeConfig(config); + } - for (Map rule : loadList) { - if (rule.get("id") != null && rule.get("id").toString().equals(targetId)) { - newList.add(updatedRule); - } else { - newList.add(rule); - } + @SuppressWarnings("unchecked") + public void addIconHashRule(Map rule) { + Map config = new HashMap<>(readConfig()); + List> list = new ArrayList<>(getIconHashRules()); + list.add(rule); + config.put("Icon_Hash_List", list); + writeConfig(config); + } + + @SuppressWarnings("unchecked") + public void updateIconHashRule(int index, Map updatedRule) { + Map config = new HashMap<>(readConfig()); + List> list = new ArrayList<>(getIconHashRules()); + if (index < 0 || index >= list.size()) { + return; } + list.set(index, updatedRule); + config.put("Icon_Hash_List", list); + writeConfig(config); + } - config.put("Load_List", newList); + @SuppressWarnings("unchecked") + public void removeIconHashRule(int index) { + Map config = new HashMap<>(readConfig()); + List> list = new ArrayList<>(getIconHashRules()); + if (index < 0 || index >= list.size()) { + return; + } + list.remove(index); + config.put("Icon_Hash_List", list); writeConfig(config); } - /** - * 删除指纹规则 - */ - public void removeRule(String ruleId) { - Map config = readConfig(); - List> loadList = getFingerprintRules(); - List> newList = new ArrayList<>(); + @SuppressWarnings("unchecked") + public void mergeUpdate(Map newYamlData) { + if (newYamlData == null) { + return; + } + // Start from full existing config so Icon_Hash_List and unknown keys survive + Map merged = new HashMap<>(readConfig()); + + List> oldLoadList = getFingerprintRules(); + List> newLoadList = (List>) newYamlData.get("Load_List"); + if (newLoadList != null) { + List> combined = new ArrayList<>(oldLoadList); + for (Map newRule : newLoadList) { + if (!isRuleInList(combined, newRule)) { + Map copy = new HashMap<>(newRule); + copy.remove("id"); + combined.add(copy); + } + } + merged.put("Load_List", combined); + } - for (Map rule : loadList) { - if (rule.get("id") == null || !rule.get("id").toString().equals(ruleId)) { - newList.add(rule); + List oldBypass = getBypassList(); + List newBypass = (List) newYamlData.get("Bypass_List"); + if (newBypass != null) { + List combinedBypass = new ArrayList<>(oldBypass); + for (String bypass : newBypass) { + if (!combinedBypass.contains(bypass)) { + combinedBypass.add(bypass); + } } + merged.put("Bypass_List", combinedBypass); } - config.put("Load_List", newList); - writeConfig(config); + List> oldIcons = getIconHashRules(); + List> newIcons = (List>) newYamlData.get("Icon_Hash_List"); + if (newIcons != null) { + List> combinedIcons = new ArrayList<>(oldIcons); + for (Map icon : newIcons) { + if (!isIconInList(combinedIcons, icon)) { + combinedIcons.add(new HashMap<>(icon)); + } + } + merged.put("Icon_Hash_List", combinedIcons); + } + + writeConfig(merged); } - /** - * 强制清除缓存 - */ - public void invalidateCache() { - cachedConfig = null; - cachedLastModified = -1; - cachedEnabledRules = null; - cachedScanPaths = null; - cachedRulesLastModified = -1; + private boolean isRuleInList(List> ruleList, Map targetRule) { + return ruleList.stream().anyMatch(rule -> + Objects.equals(rule.get("name"), targetRule.get("name")) + && Objects.equals(rule.get("method"), targetRule.get("method")) + && Objects.equals(rule.get("path"), targetRule.get("path"))); } - public String getConfigFilePath() { - return configFilePath; + private boolean isIconInList(List> list, Map target) { + return list.stream().anyMatch(rule -> + Objects.equals(rule.get("name"), target.get("name")) + && Objects.equals(rule.get("murmur_hash"), target.get("murmur_hash")) + && Objects.equals(rule.get("md5"), target.get("md5"))); } } diff --git a/extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java b/extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java deleted file mode 100644 index 71f4ba2..0000000 --- a/extender/src/main/java/burp/tdou/fingerscan/core/YamlConfigManager.java +++ /dev/null @@ -1,423 +0,0 @@ -/** - * YAML配置管理器 - * 负责指纹规则的读取、写入、更新、删除等操作 - * 基于RouteVulScanPro1的YamlUtil逻辑进行适配 - * - * @author OneScan Team - * @version 2.0 - */ -package burp.tdou.fingerscan.core; - -import org.yaml.snakeyaml.LoaderOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.SafeConstructor; -import java.io.*; -import java.util.*; - -public class YamlConfigManager { - - private String configFilePath; - private static final String DEFAULT_CONFIG_FILE = "/Applications/Burp Suite Professional.app/Contents/Resources/app/Config_yaml.yaml"; - - /** - * 构造函数 - * @param configFilePath YAML配置文件路径 - */ - public YamlConfigManager(String configFilePath) { - this.configFilePath = configFilePath != null ? configFilePath : DEFAULT_CONFIG_FILE; - } - - /** - * 读取YAML配置文件 - * @return 配置数据Map - */ - public Map readYamlConfig() { - File file = new File(configFilePath); - Map data = null; - try { - if (!file.exists()) { - // 如果文件不存在,创建默认配置 - createDefaultConfig(); - } - InputStream inputStream = new FileInputStream(file); - Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); - data = yaml.load(inputStream); - inputStream.close(); - } catch (IOException e) { - System.err.println("读取YAML配置文件失败: " + e.getMessage()); - e.printStackTrace(); - } - return data != null ? data : new HashMap<>(); - } - - /** - * 写入YAML配置文件 - * @param data 配置数据 - */ - public void writeYamlConfig(Map data) { - Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); - try { - PrintWriter writer = new PrintWriter(new File(configFilePath)); - yaml.dump(data, writer); - writer.close(); - } catch (FileNotFoundException e) { - System.err.println("写入YAML配置文件失败: " + e.getMessage()); - e.printStackTrace(); - } - } - - /** - * 获取指纹规则列表 - * @return 指纹规则列表 - */ - @SuppressWarnings("unchecked") - public List> getFingerprintRules() { - Map yamlData = readYamlConfig(); - List> loadList = (List>) yamlData.get("Load_List"); - return loadList != null ? loadList : new ArrayList<>(); - } - - /** - * 获取绕过路径列表 - * @return 绕过路径列表 - */ - @SuppressWarnings("unchecked") - public List getBypassList() { - Map yamlData = readYamlConfig(); - List bypassList = (List) yamlData.get("Bypass_List"); - return bypassList != null ? bypassList : new ArrayList<>(); - } - - /** - * 添加指纹规则 - * @param rule 指纹规则 - */ - public void addFingerprintRule(Map rule) { - Map yamlData = readYamlConfig(); - List> loadList = getFingerprintRules(); - rule.remove("id"); - loadList.add(rule); - yamlData.put("Load_List", loadList); - writeYamlConfig(yamlData); - } - - /** - * 更新指纹规则(按索引) - */ - public void updateFingerprintRule(int index, Map updatedRule) { - Map yamlData = readYamlConfig(); - List> loadList = getFingerprintRules(); - if (index >= 0 && index < loadList.size()) { - updatedRule.remove("id"); - loadList.set(index, updatedRule); - yamlData.put("Load_List", loadList); - writeYamlConfig(yamlData); - } - } - - /** - * 删除指纹规则(按索引) - */ - public void removeFingerprintRule(int index) { - Map yamlData = readYamlConfig(); - List> loadList = getFingerprintRules(); - if (index >= 0 && index < loadList.size()) { - loadList.remove(index); - yamlData.put("Load_List", loadList); - writeYamlConfig(yamlData); - } - } - - // ============================================================ - // Icon Hash 规则 CRUD - // ============================================================ - - @SuppressWarnings("unchecked") - public List> getIconHashRules() { - Map yamlData = readYamlConfig(); - List> list = (List>) yamlData.get("Icon_Hash_List"); - return list != null ? list : new ArrayList<>(); - } - - public void addIconHashRule(Map rule) { - Map yamlData = readYamlConfig(); - List> list = getIconHashRules(); - list.add(rule); - yamlData.put("Icon_Hash_List", list); - writeYamlConfig(yamlData); - } - - public void updateIconHashRule(int index, Map updatedRule) { - Map yamlData = readYamlConfig(); - List> list = getIconHashRules(); - if (index >= 0 && index < list.size()) { - list.set(index, updatedRule); - yamlData.put("Icon_Hash_List", list); - writeYamlConfig(yamlData); - } - } - - public void removeIconHashRule(int index) { - Map yamlData = readYamlConfig(); - List> list = getIconHashRules(); - if (index >= 0 && index < list.size()) { - list.remove(index); - yamlData.put("Icon_Hash_List", list); - writeYamlConfig(yamlData); - } - } - - /** - * 从字符串解析YAML - * @param yamlString YAML字符串 - * @return 解析后的数据 - */ - public Map parseYamlString(String yamlString) { - Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())); - try { - return yaml.load(yamlString); - } catch (Exception e) { - System.err.println("解析YAML字符串失败: " + e.getMessage()); - return new HashMap<>(); - } - } - - /** - * 合并更新YAML配置 - * @param newYamlData 新的YAML数据 - */ - @SuppressWarnings("unchecked") - public void mergeUpdateYamlConfig(Map newYamlData) { - Map oldYamlData = readYamlConfig(); - List> oldLoadList = (List>) oldYamlData.get("Load_List"); - List> newLoadList = (List>) newYamlData.get("Load_List"); - - if (oldLoadList == null) { - oldLoadList = new ArrayList<>(); - } - - // 合并指纹规则列表 - for (Map newRule : newLoadList) { - if (!isRuleInList(oldLoadList, newRule)) { - newRule.remove("id"); - oldLoadList.add(newRule); - } - } - - // 合并绕过列表 - List oldBypassList = (List) oldYamlData.get("Bypass_List"); - List newBypassList = (List) newYamlData.get("Bypass_List"); - - if (oldBypassList == null) { - oldBypassList = new ArrayList<>(); - } - - if (newBypassList != null) { - for (String bypass : newBypassList) { - if (!oldBypassList.contains(bypass)) { - oldBypassList.add(bypass); - } - } - } - - // 保存合并后的配置 - Map mergedData = new HashMap<>(); - mergedData.put("Load_List", oldLoadList); - mergedData.put("Bypass_List", oldBypassList); - writeYamlConfig(mergedData); - } - - /** - * 检查规则是否已存在于列表中 - * @param ruleList 规则列表 - * @param targetRule 目标规则 - * @return 是否存在 - */ - private boolean isRuleInList(List> ruleList, Map targetRule) { - return ruleList.stream().anyMatch(rule -> isRuleEqual(rule, targetRule)); - } - - /** - * 比较两个规则是否相等(忽略loaded、id、type字段) - * @param rule1 规则1 - * @param rule2 规则2 - * @return 是否相等 - */ - private boolean isRuleEqual(Map rule1, Map rule2) { - // 使用Java 8兼容的方式创建Set - Set keyFields = new HashSet<>(); - keyFields.add("name"); - keyFields.add("method"); - keyFields.add("path"); - - for (String key : keyFields) { - Object value1 = rule1.get(key); - Object value2 = rule2.get(key); - if (!Objects.equals(value1, value2)) { - return false; - } - } - return true; - } - - /** - * 创建默认配置文件 - */ - private void createDefaultConfig() { - Map defaultConfig = new HashMap<>(); - defaultConfig.put("Load_List", new ArrayList<>()); - defaultConfig.put("Bypass_List", new ArrayList<>()); - writeYamlConfig(defaultConfig); - } - - /** - * 获取配置文件路径 - * @return 配置文件路径 - */ - public String getConfigFilePath() { - return configFilePath; - } - - /** - * 设置配置文件路径 - * @param configFilePath 新的配置文件路径 - */ - public void setConfigFilePath(String configFilePath) { - this.configFilePath = configFilePath; - } - - /** - * 基于请求路径生成递归扫描路径列表 - * 从请求路径中提取各级目录,用于递归扫描 - * @param requestPath 原始请求路径 - * @return 递归扫描路径列表 - */ - public List generateRecursivePaths(String requestPath) { - List recursivePaths = new ArrayList<>(); - - try { - System.out.println("[YamlConfigManager] 开始生成递归路径,原始请求路径: " + requestPath); - - // 添加根路径 - recursivePaths.add("/"); - - if (requestPath != null && !requestPath.isEmpty() && !requestPath.equals("/")) { - // 清理路径,移除查询参数和锚点 - String cleanPath = requestPath.split("\\?")[0].split("#")[0]; - - // 分割路径段 - String[] segments = cleanPath.split("/"); - StringBuilder currentPath = new StringBuilder(); - - for (int i = 1; i < segments.length; i++) { - if (!segments[i].isEmpty()) { - currentPath.append("/").append(segments[i]); - - // 如果是最后一个段且包含文件扩展名,则跳过(不扫描文件路径) - if (i == segments.length - 1 && segments[i].contains(".")) { - break; - } - - String path = currentPath.toString(); - if (!recursivePaths.contains(path)) { - recursivePaths.add(path); - System.out.println("[YamlConfigManager] 添加递归路径: " + path); - } - } - } - } - - System.out.println("[YamlConfigManager] 递归路径生成完成,总数: " + recursivePaths.size()); - System.out.println("[YamlConfigManager] 递归路径列表: " + recursivePaths); - - return recursivePaths; - - } catch (Exception e) { - System.err.println("[YamlConfigManager] 生成递归路径时发生异常: " + e.getMessage()); - e.printStackTrace(); - // 异常情况下返回默认根路径 - List defaultPaths = new ArrayList<>(); - defaultPaths.add("/"); - return defaultPaths; - } - } - - /** - * 获取指纹规则中的扫描路径列表 - * 从所有指纹规则中提取url字段,用于被动扫描 - * @return 扫描路径列表 - */ - @SuppressWarnings("unchecked") - public List getScanPaths() { - Set scanPathsSet = new HashSet<>(); - - try { - List> fingerprintRules = getFingerprintRules(); - System.out.println("[YamlConfigManager] 开始提取扫描路径,指纹规则数量: " + fingerprintRules.size()); - - for (Map rule : fingerprintRules) { - // 从url字段提取路径,因为Config_yaml.yaml中使用的是url字段 - Object urlObj = rule.get("url"); - if (urlObj != null) { - String url = urlObj.toString().trim(); - if (!url.isEmpty()) { - boolean added = scanPathsSet.add(url); - if (added) { - System.out.println("[YamlConfigManager] 添加扫描路径: " + url); - } - } - } - } - - // 转换为List - List scanPaths = new ArrayList<>(scanPathsSet); - - // 如果没有配置路径,返回默认根路径 - if (scanPaths.isEmpty()) { - scanPaths.add("/"); - System.out.println("[YamlConfigManager] 没有找到配置路径,使用默认根路径: /"); - } - - System.out.println("[YamlConfigManager] 扫描路径提取完成,总数: " + scanPaths.size()); - System.out.println("[YamlConfigManager] 扫描路径列表: " + scanPaths); - - return scanPaths; - - } catch (Exception e) { - System.err.println("[YamlConfigManager] 提取扫描路径时发生异常: " + e.getMessage()); - e.printStackTrace(); - // 异常情况下返回默认路径 - List defaultPaths = new ArrayList<>(); - defaultPaths.add("/"); - return defaultPaths; - } - } - - /** - * 获取忽略的文件扩展名列表 - * 用于被动监听时过滤不需要扫描的文件类型 - * @return 忽略扩展名列表 - */ - @SuppressWarnings("unchecked") - public List getIgnoreExtensions() { - Map yamlData = readYamlConfig(); - Map filterConfig = (Map) yamlData.get("filter_config"); - - if (filterConfig != null) { - List ignoreExtensions = (List) filterConfig.get("ignore_extensions"); - return ignoreExtensions != null ? ignoreExtensions : new ArrayList<>(); - } - - // 返回默认忽略扩展名 - List defaultIgnoreExtensions = new ArrayList<>(); - defaultIgnoreExtensions.add("css"); - defaultIgnoreExtensions.add("js"); - defaultIgnoreExtensions.add("png"); - defaultIgnoreExtensions.add("jpg"); - defaultIgnoreExtensions.add("jpeg"); - defaultIgnoreExtensions.add("gif"); - defaultIgnoreExtensions.add("ico"); - defaultIgnoreExtensions.add("svg"); - return defaultIgnoreExtensions; - } -} \ No newline at end of file diff --git a/extender/src/main/java/burp/tdou/fingerscan/core/iconhash/IconHashRuleLoader.java b/extender/src/main/java/burp/tdou/fingerscan/core/iconhash/IconHashRuleLoader.java index bd97136..9e8ecd7 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/core/iconhash/IconHashRuleLoader.java +++ b/extender/src/main/java/burp/tdou/fingerscan/core/iconhash/IconHashRuleLoader.java @@ -1,7 +1,7 @@ package burp.tdou.fingerscan.core.iconhash; import burp.tdou.common.log.Logger; -import burp.tdou.fingerscan.config.YamlConfigLoader; +import burp.tdou.fingerscan.config.YamlConfigStore; import java.util.ArrayList; import java.util.HashMap; @@ -10,18 +10,18 @@ public class IconHashRuleLoader { - private final YamlConfigLoader configLoader; + private final YamlConfigStore configStore; private Map> murmurIndex = new HashMap<>(); private Map> md5Index = new HashMap<>(); private long lastLoadTime = 0; - public IconHashRuleLoader(YamlConfigLoader configLoader) { - this.configLoader = configLoader; + public IconHashRuleLoader(YamlConfigStore configStore) { + this.configStore = configStore; } @SuppressWarnings("unchecked") public void loadRules() { - Map config = configLoader.readConfig(); + Map config = configStore.readConfig(); if (config == null) { return; } diff --git a/extender/src/main/java/burp/tdou/fingerscan/core/pipeline/RequestPipeline.java b/extender/src/main/java/burp/tdou/fingerscan/core/pipeline/RequestPipeline.java index 3e35811..13e6736 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/core/pipeline/RequestPipeline.java +++ b/extender/src/main/java/burp/tdou/fingerscan/core/pipeline/RequestPipeline.java @@ -107,8 +107,10 @@ private void submitAnalysis(ScanTask task) { pool.execute(() -> { try { + String requestPath = task.getReqResp() != null && task.getReqResp().request() != null + ? extractRequestPath(task.getReqResp().request()) : ""; List matches = ruleEngine.match( - task.getExistingRequest(), task.getExistingResponse()); + task.getExistingRequest(), task.getExistingResponse(), requestPath); // 无论是否匹配到指纹,都构建完整结果用于扫描记录 ScanResult.Builder builder = new ScanResult.Builder() @@ -300,7 +302,7 @@ private ScanResult buildHttpResult(ScanTask task, HttpRequestResponse reqResp, H } byte[] reqBytes = request != null ? request.toByteArray().getBytes() : null; - List matches = ruleEngine.match(reqBytes, respBytes); + List matches = ruleEngine.match(reqBytes, respBytes, reqUrl); return new ScanResult.Builder() .task(task) @@ -352,18 +354,23 @@ private void fillResultFromReqResp(ScanResult.Builder builder, ScanTask task) { */ private String extractRequestPath(HttpRequest request) { if (request == null) return ""; - // Parse from raw request header line + // 优先使用 Montoya API 的 path(),返回纯路径(如 /swagger-ui.html) + String path = request.path(); + if (path != null && !path.isEmpty()) { + return path; + } + // 降级:从原始请求行解析 String reqStr = request.toString(); int lineEnd = reqStr.indexOf("\r\n"); if (lineEnd < 0) lineEnd = reqStr.indexOf("\n"); - if (lineEnd < 0) return request.path(); + if (lineEnd < 0) return ""; String reqLine = reqStr.substring(0, lineEnd); int start = reqLine.indexOf(' '); int end = reqLine.lastIndexOf(" HTTP/"); if (start >= 0 && end > start) { return reqLine.substring(start + 1, end); } - return request.path(); + return ""; } private static int parseStatusCode(String statusLine) { diff --git a/extender/src/main/java/burp/tdou/fingerscan/core/rule/CompositeRuleEngine.java b/extender/src/main/java/burp/tdou/fingerscan/core/rule/CompositeRuleEngine.java index 95a4089..ffbe9d4 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/core/rule/CompositeRuleEngine.java +++ b/extender/src/main/java/burp/tdou/fingerscan/core/rule/CompositeRuleEngine.java @@ -30,11 +30,11 @@ public void unregister(RuleEngine engine) { } @Override - public List match(byte[] request, byte[] response) { + public List match(byte[] request, byte[] response, String requestPath) { List allResults = new ArrayList<>(); for (RuleEngine engine : engines) { try { - List results = engine.match(request, response); + List results = engine.match(request, response, requestPath); if (results != null) { allResults.addAll(results); } diff --git a/extender/src/main/java/burp/tdou/fingerscan/core/rule/RuleEngine.java b/extender/src/main/java/burp/tdou/fingerscan/core/rule/RuleEngine.java index df44d32..b9bd67c 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/core/rule/RuleEngine.java +++ b/extender/src/main/java/burp/tdou/fingerscan/core/rule/RuleEngine.java @@ -11,11 +11,19 @@ public interface RuleEngine { /** * 对请求/响应数据进行指纹匹配 * - * @param request 请求原始字节(可为 null) - * @param response 响应原始字节(可为 null) + * @param request 请求原始字节(可为 null) + * @param response 响应原始字节(可为 null) + * @param requestPath 请求路径(可为 null),用于与规则 url 字段做路径比对 * @return 匹配结果列表(无匹配返回空列表,永不返回 null) */ - List match(byte[] request, byte[] response); + List match(byte[] request, byte[] response, String requestPath); + + /** + * 对请求/响应数据进行指纹匹配(不传路径,兼容旧调用) + */ + default List match(byte[] request, byte[] response) { + return match(request, response, null); + } /** * 获取本引擎需要扫描的路径列表(用于递归扫描策略) diff --git a/extender/src/main/java/burp/tdou/fingerscan/core/rule/YamlRuleEngine.java b/extender/src/main/java/burp/tdou/fingerscan/core/rule/YamlRuleEngine.java index 9bfdd62..0d49b8c 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/core/rule/YamlRuleEngine.java +++ b/extender/src/main/java/burp/tdou/fingerscan/core/rule/YamlRuleEngine.java @@ -1,8 +1,10 @@ package burp.tdou.fingerscan.core.rule; import burp.tdou.common.log.Logger; -import burp.tdou.fingerscan.config.YamlConfigLoader; +import burp.tdou.fingerscan.common.Config; +import burp.tdou.fingerscan.config.YamlConfigStore; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -17,25 +19,26 @@ * * 改进: * - Pattern 缓存避免重复编译 - * - 通过 YamlConfigLoader 使用带缓存的配置读取 + * - 通过 YamlConfigStore 使用带缓存的配置读取 * - 线程安全的 Pattern 缓存 + * - 可选的请求路径与规则 url 精确匹配 */ public class YamlRuleEngine implements RuleEngine { - private final YamlConfigLoader configLoader; + private final YamlConfigStore configStore; private final ConcurrentHashMap patternCache = new ConcurrentHashMap<>(); - public YamlRuleEngine(YamlConfigLoader configLoader) { - this.configLoader = configLoader; + public YamlRuleEngine(YamlConfigStore configStore) { + this.configStore = configStore; } @Override - public List match(byte[] request, byte[] response) { + public List match(byte[] request, byte[] response, String requestPath) { if (response == null || response.length == 0) { return Collections.emptyList(); } - List> rules = configLoader.getEnabledRules(); + List> rules = configStore.getEnabledRules(); if (rules.isEmpty()) { return Collections.emptyList(); } @@ -57,6 +60,10 @@ public List match(byte[] request, byte[] response) { continue; } + if (!matchPath(requestPath, getStringField(rule, "url"))) { + continue; + } + if (matchesRegex(responseStr, regex)) { results.add(MatchResult.fromYamlRule(name, regex)); } @@ -70,7 +77,7 @@ public List match(byte[] request, byte[] response) { @Override public List getScanPaths() { - return configLoader.getScanPaths(); + return configStore.getScanPaths(); } /** @@ -139,6 +146,36 @@ private boolean matchStatusCode(int statusCode, String state) { } } + /** + * 校验请求路径是否匹配规则的 url 字段 + * 开关关闭时始终返回 true;url 为 null、空或 "/" 时不限路径(始终匹配) + */ + private boolean matchPath(String requestPath, String ruleUrl) { + if (!Config.getBoolean(Config.KEY_FINGERPRINT_URL_MATCH)) { + return true; + } + if (ruleUrl == null || ruleUrl.isEmpty() || "/".equals(ruleUrl)) { + return true; + } + if (requestPath == null || requestPath.isEmpty()) { + return false; + } + // 清理查询参数和锚点 + String cleanPath = requestPath.split("\\?")[0].split("#")[0]; + // 兼容完整 URL 格式(如 http://host/path) + if (cleanPath.startsWith("http://") || cleanPath.startsWith("https://")) { + try { + cleanPath = new URL(cleanPath).getPath(); + } catch (Exception e) { + return false; + } + } + if (!cleanPath.startsWith("/")) { + cleanPath = "/" + cleanPath; + } + return cleanPath.equals(ruleUrl); + } + /** * 清空 Pattern 缓存 */ diff --git a/extender/src/main/java/burp/tdou/fingerscan/ui/tab/FingerprintPanel.java b/extender/src/main/java/burp/tdou/fingerscan/ui/tab/FingerprintPanel.java index 0a45806..9675f05 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/ui/tab/FingerprintPanel.java +++ b/extender/src/main/java/burp/tdou/fingerscan/ui/tab/FingerprintPanel.java @@ -9,7 +9,7 @@ package burp.tdou.fingerscan.ui.tab; import burp.tdou.fingerscan.common.Config; -import burp.tdou.fingerscan.core.YamlConfigManager; +import burp.tdou.fingerscan.config.YamlConfigStore; import burp.tdou.fingerscan.ui.widget.FingerprintRuleDialog; import burp.tdou.fingerscan.ui.widget.IconHashRuleDialog; import burp.tdou.fingerscan.ui.widget.TestRuleDialog; @@ -29,9 +29,8 @@ import java.util.regex.Pattern; public class FingerprintPanel extends JPanel implements ActionListener, KeyListener { - - private YamlConfigManager configManager; - private Runnable onReloadCallback; + + private YamlConfigStore configStore; // UI组件 private JTable fingerprintTable; @@ -66,20 +65,15 @@ public class FingerprintPanel extends JPanel implements ActionListener, KeyListe /** * 构造函数 - * @param configManager YAML配置管理器 - * @param scanner 指纹扫描器 + * @param configStore YAML配置存储 */ - public FingerprintPanel(YamlConfigManager configManager) { - this.configManager = configManager; + public FingerprintPanel(YamlConfigStore configStore) { + this.configStore = configStore; initializeUI(); loadFingerprintRules(); loadIconHashRules(); } - public void setOnReloadCallback(Runnable callback) { - this.onReloadCallback = callback; - } - /** * 初始化UI界面 */ @@ -122,7 +116,7 @@ private JPanel createTopPanel() { JPanel pathPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); pathPanel.add(new JLabel("配置文件路径:")); - configPathField = new JTextField(configManager.getConfigFilePath(), 30); + configPathField = new JTextField(configStore.getConfigFilePath(), 30); configPathField.setEditable(false); pathPanel.add(configPathField); @@ -285,7 +279,7 @@ private void setColumnWidths() { public void loadFingerprintRules() { tableModel.setRowCount(0); - List> rules = configManager.getFingerprintRules(); + List> rules = configStore.getFingerprintRules(); for (int i = 0; i < rules.size(); i++) { Map rule = rules.get(i); @@ -397,11 +391,11 @@ private void updateRuleEnabledStatus(int row) { Boolean enabled = (Boolean) tableModel.getValueAt(row, 2); - List> rules = configManager.getFingerprintRules(); + List> rules = configStore.getFingerprintRules(); if (row < rules.size()) { Map rule = rules.get(row); rule.put("loaded", enabled); - configManager.updateFingerprintRule(row, rule); + configStore.updateRule(row, rule); } } @@ -434,7 +428,7 @@ private int getSelectedModelIndex() { private Map getSelectedRule() { int modelRow = getSelectedModelIndex(); if (modelRow < 0) return null; - List> rules = configManager.getFingerprintRules(); + List> rules = configStore.getFingerprintRules(); return modelRow < rules.size() ? rules.get(modelRow) : null; } @@ -509,7 +503,7 @@ private void browseConfigFile() { if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selectedPath = fileChooser.getSelectedFile().getAbsolutePath(); - configManager.setConfigFilePath(selectedPath); + configStore.setConfigFilePath(selectedPath); Config.put("yaml_config_path", selectedPath); configPathField.setText(selectedPath); reloadConfig(); @@ -522,9 +516,7 @@ private void browseConfigFile() { private void reloadConfig() { loadFingerprintRules(); loadIconHashRules(); - if (onReloadCallback != null) { - onReloadCallback.run(); - } + // path change already notified via setConfigFilePath → listeners JOptionPane.showMessageDialog(this, "配置重新加载成功!", "提示", JOptionPane.INFORMATION_MESSAGE); } @@ -541,7 +533,7 @@ private void addRule() { Map newRule = dialog.showDialog(); if (newRule != null) { try { - configManager.addFingerprintRule(newRule); + configStore.addRule(newRule); // 刷新表格 loadFingerprintRules(); @@ -573,7 +565,7 @@ private void editRule() { Map editedRule = dialog.showDialog(); if (editedRule != null) { try { - configManager.updateFingerprintRule(modelIndex, editedRule); + configStore.updateRule(modelIndex, editedRule); loadFingerprintRules(); JOptionPane.showMessageDialog(this, "规则更新成功!", "成功", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { @@ -604,7 +596,7 @@ private void deleteRule() { // 从后往前删除,避免索引变化 for (int i = selectedRows.length - 1; i >= 0; i--) { int modelRow = fingerprintTable.convertRowIndexToModel(selectedRows[i]); - configManager.removeFingerprintRule(modelRow); + configStore.removeRule(modelRow); } // 刷新表格 @@ -633,14 +625,14 @@ private void copyRule() { try { int modelRow = fingerprintTable.convertRowIndexToModel(selectedRow); - List> rules = configManager.getFingerprintRules(); + List> rules = configStore.getFingerprintRules(); if (modelRow >= rules.size()) return; Map copiedRule = new HashMap<>(rules.get(modelRow)); copiedRule.remove("id"); copiedRule.put("name", copiedRule.get("name") + " (副本)"); - configManager.addFingerprintRule(copiedRule); + configStore.addRule(copiedRule); loadFingerprintRules(); JOptionPane.showMessageDialog(this, "规则复制成功!", "成功", JOptionPane.INFORMATION_MESSAGE); @@ -656,23 +648,23 @@ private void copyRule() { private void importConfig() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("YAML文件", "yaml", "yml")); - + if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try { String importPath = fileChooser.getSelectedFile().getAbsolutePath(); - YamlConfigManager importManager = new YamlConfigManager(importPath); - Map importData = importManager.readYamlConfig(); - - configManager.mergeUpdateYamlConfig(importData); + YamlConfigStore importStore = new YamlConfigStore(importPath); + Map importData = importStore.readConfig(); + + configStore.mergeUpdate(importData); loadFingerprintRules(); - + JOptionPane.showMessageDialog(this, "配置导入成功!", "提示", JOptionPane.INFORMATION_MESSAGE); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "导入失败:" + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE); } } } - + /** * 导出配置 */ @@ -680,15 +672,15 @@ private void exportConfig() { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileFilter(new javax.swing.filechooser.FileNameExtensionFilter("YAML文件", "yaml", "yml")); fileChooser.setSelectedFile(new java.io.File("fingerprint_rules_export.yaml")); - + if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { try { String exportPath = fileChooser.getSelectedFile().getAbsolutePath(); - Map configData = configManager.readYamlConfig(); - - YamlConfigManager exportManager = new YamlConfigManager(exportPath); - exportManager.writeYamlConfig(configData); - + Map configData = configStore.readConfig(); + + YamlConfigStore exportStore = new YamlConfigStore(exportPath); + exportStore.writeConfig(configData); + JOptionPane.showMessageDialog(this, "配置导出成功!", "提示", JOptionPane.INFORMATION_MESSAGE); } catch (Exception ex) { JOptionPane.showMessageDialog(this, "导出失败:" + ex.getMessage(), "错误", JOptionPane.ERROR_MESSAGE); @@ -835,7 +827,7 @@ public boolean isCellEditable(int row, int column) { public void loadIconHashRules() { iconHashTableModel.setRowCount(0); - List> rules = configManager.getIconHashRules(); + List> rules = configStore.getIconHashRules(); for (Map rule : rules) { Object[] rowData = { rule.get("name"), @@ -854,7 +846,7 @@ private void addIconHashRule() { (JFrame) SwingUtilities.getWindowAncestor(this), "添加 Icon Hash 规则", null); Map newRule = dialog.showDialog(); if (newRule != null) { - configManager.addIconHashRule(newRule); + configStore.addIconHashRule(newRule); loadIconHashRules(); } } @@ -866,14 +858,14 @@ private void editIconHashRule() { return; } int modelRow = iconHashTable.convertRowIndexToModel(selectedRow); - List> rules = configManager.getIconHashRules(); + List> rules = configStore.getIconHashRules(); if (modelRow >= rules.size()) return; IconHashRuleDialog dialog = new IconHashRuleDialog( (JFrame) SwingUtilities.getWindowAncestor(this), "编辑 Icon Hash 规则", rules.get(modelRow)); Map edited = dialog.showDialog(); if (edited != null) { - configManager.updateIconHashRule(modelRow, edited); + configStore.updateIconHashRule(modelRow, edited); loadIconHashRules(); } } @@ -888,7 +880,7 @@ private void deleteIconHashRule() { JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { int modelRow = iconHashTable.convertRowIndexToModel(selectedRow); - configManager.removeIconHashRule(modelRow); + configStore.removeIconHashRule(modelRow); loadIconHashRules(); } } diff --git a/extender/src/main/java/burp/tdou/fingerscan/ui/tab/IconDataPanel.java b/extender/src/main/java/burp/tdou/fingerscan/ui/tab/IconDataPanel.java index 4646d49..b04727e 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/ui/tab/IconDataPanel.java +++ b/extender/src/main/java/burp/tdou/fingerscan/ui/tab/IconDataPanel.java @@ -1,7 +1,7 @@ package burp.tdou.fingerscan.ui.tab; import burp.tdou.fingerscan.core.iconhash.IconHashStore; -import burp.tdou.fingerscan.core.YamlConfigManager; +import burp.tdou.fingerscan.config.YamlConfigStore; import burp.tdou.fingerscan.ui.widget.IconHashRuleDialog; import javax.swing.*; @@ -19,8 +19,7 @@ public class IconDataPanel extends JPanel { private final IconHashStore store; - private final YamlConfigManager configManager; - private Runnable onRuleAddedCallback; + private final YamlConfigStore configStore; private JTable iconTable; private DefaultTableModel tableModel; private JLabel iconPreview; @@ -33,16 +32,12 @@ public class IconDataPanel extends JPanel { }; private static final String[] SOURCE_COLUMNS = {"Host", "路径", "发现时间"}; - public IconDataPanel(IconHashStore store, YamlConfigManager configManager) { + public IconDataPanel(IconHashStore store, YamlConfigStore configStore) { this.store = store; - this.configManager = configManager; + this.configStore = configStore; initUI(); } - public void setOnRuleAddedCallback(Runnable callback) { - this.onRuleAddedCallback = callback; - } - private void initUI() { setLayout(new BorderLayout()); @@ -400,7 +395,7 @@ private void convertToRule() { JOptionPane.showMessageDialog(this, "请先选择要转换的图标", "提示", JOptionPane.WARNING_MESSAGE); return; } - if (configManager == null) { + if (configStore == null) { JOptionPane.showMessageDialog(this, "指纹配置管理器未初始化", "错误", JOptionPane.ERROR_MESSAGE); return; } @@ -422,10 +417,7 @@ private void convertToRule() { IconHashRuleDialog dialog = new IconHashRuleDialog(frame, "转为 Icon Hash 指纹规则", prefill); Map result = dialog.showDialog(); if (result != null) { - configManager.addIconHashRule(result); - if (onRuleAddedCallback != null) { - onRuleAddedCallback.run(); - } + configStore.addIconHashRule(result); String ruleName = String.valueOf(result.get("name")); String oldMatch = (String) tableModel.getValueAt(modelRow, 5); String newMatch; diff --git a/extender/src/main/java/burp/tdou/fingerscan/ui/tab/config/OtherTab.java b/extender/src/main/java/burp/tdou/fingerscan/ui/tab/config/OtherTab.java index e9ce477..8e157d9 100644 --- a/extender/src/main/java/burp/tdou/fingerscan/ui/tab/config/OtherTab.java +++ b/extender/src/main/java/burp/tdou/fingerscan/ui/tab/config/OtherTab.java @@ -24,6 +24,9 @@ protected void initView() { // 请求响应最大长度 addTextConfigPanel(L.get("maximum_display_length"), L.get("maximum_display_length_sub_title"), 20, Config.KEY_MAX_DISPLAY_LENGTH).addKeyListener(new NumberFilter(8)); + // 指纹 URL 精确匹配开关 + addEnabledConfigPanel(L.get("fingerprint_url_match"), L.get("fingerprint_url_match_sub_title"), + Config.KEY_FINGERPRINT_URL_MATCH); addReadOnlyPathPanel(L.get("config_directory"), L.get("config_directory_sub_title"), Config.getWorkDir()); addReadOnlyPathPanel(L.get("database_path"), L.get("database_path_sub_title"), Config.getWorkDir() + "icon_hash.db"); } diff --git a/extender/src/main/java/yaml/Config_yaml.yaml b/extender/src/main/resources/Config_yaml.yaml similarity index 100% rename from extender/src/main/java/yaml/Config_yaml.yaml rename to extender/src/main/resources/Config_yaml.yaml diff --git a/extender/src/main/resources/i18n/messages_en_US.properties b/extender/src/main/resources/i18n/messages_en_US.properties index 19135b3..aa1d874 100644 --- a/extender/src/main/resources/i18n/messages_en_US.properties +++ b/extender/src/main/resources/i18n/messages_en_US.properties @@ -292,4 +292,8 @@ payload_rule_list_is_empty_hint=Payload rule list is empty! processing_table_columns.enabled=Enabled processing_table_columns.merge=Merge processing_table_columns.rule_name=RuleName -processing_table_columns.rule_count=RuleCount \ No newline at end of file +processing_table_columns.rule_count=RuleCount + +# fingerprint url match +fingerprint_url_match=Fingerprint URL Match +fingerprint_url_match_sub_title=When enabled, passive fingerprint matching only applies when the request path exactly matches the rule url field; rules with empty or "/" url are not affected. \ No newline at end of file diff --git a/extender/src/main/resources/i18n/messages_zh_CN.properties b/extender/src/main/resources/i18n/messages_zh_CN.properties index 857ccda..2776d87 100644 --- a/extender/src/main/resources/i18n/messages_zh_CN.properties +++ b/extender/src/main/resources/i18n/messages_zh_CN.properties @@ -288,4 +288,8 @@ payload_rule_list_is_empty_hint=\u89C4\u5219\u5217\u8868\u4E3A\u7A7A processing_table_columns.enabled=\u542F\u7528 processing_table_columns.merge=\u5408\u5E76 processing_table_columns.rule_name=\u89C4\u5219\u540D -processing_table_columns.rule_count=\u89C4\u5219\u6570\u91CF \ No newline at end of file +processing_table_columns.rule_count=\u89C4\u5219\u6570\u91CF + +# fingerprint url match +fingerprint_url_match=\u6307\u7EB9 URL \u5339\u914D +fingerprint_url_match_sub_title=\u5F00\u542F\u540E\uFF0C\u88AB\u52A8\u6307\u7EB9\u8BC6\u522B\u4EC5\u5728\u8BF7\u6C42\u8DEF\u5F84\u4E0E\u89C4\u5219 url \u5B57\u6BB5\u7CBE\u786E\u5339\u914D\u65F6\u751F\u6548\uFF1Burl \u4E3A\u7A7A\u6216\u201C/\u201D\u7684\u89C4\u5219\u4E0D\u53D7\u5F71\u54CD \ No newline at end of file