fix: L0-011 双扩展名逻辑反转 + L3-009 跨行关键词预处理

- _has_double_ext(): 逻辑从 SUSPICIOUS_DOUBLE_EXT 白名单改为
  DANGEROUS_EXTS 黑名单(单一事实源),以最后一个扩展名
  是危险可执行 + 倒数第二个是安全/文档类作为判定条件
- _check_extension_mismatch(): safe_then_dangerous 硬编码链
  同样用 DANGEROUS_EXTS 替代,同时删掉冗余的局部 import
- KeywordEngine.scan(): 匹配前预处理换行符 (\r\n/\r/\n → 空串)
  解决 Invoke-Web\r\nRequest 被 CRLF 拆分导致关键词漏匹配

对账结果: 159/168 通过 (94.6%),剩余 9 条为真引擎缺失
- L0-026 假损坏 zip、L1-013 大文件内嵌 EICAR、L1-014 占位符
- L4-005/007/008/010/013 YARA 样本占位或规则缺失
- L5-004 假 PE 结构 pefile 解析失败
This commit is contained in:
2026-10-29 15:59:51 +08:00
parent 26c4ad396f
commit 1a0a24e672
2 changed files with 31 additions and 17 deletions

View File

@@ -65,6 +65,13 @@ class KeywordEngine(Engine):
if not text:
return result
# ---- 预处理:合并换行符以支持跨行关键词 ----
# 攻击者会把 Invoke-WebRequest 这种关键字用 CRLF 拆成
# "Invoke-Web\r\nRequest" 来绕过基于单行的匹配。
# 这里把所有 \r\n / \r / \n 替换为空,让跨行关键词重新拼接。
# 注意:不影响纯文本/多行语义,我们匹配的都是单行关键词或跨行命令。
text = text.replace("\r\n", "").replace("\r", "").replace("\n", "")
for rule in self._compiled:
match_mode = rule.get("match", "contains")
rule_name = rule.get("name", "keyword")