feat: YARA .yar 规则自动化生成 + 边界记录验证
rules/test_rules.yar (7 条规则): - Test_ReverseShell_Basic: nc 反弹 shell - Test_PowerShell_Download: Invoke-WebRequest - Newly_Added_Rule_Test: 热加载验证 - Meta_Label_Test: metadata 输出验证 - Regex_Shell_Pattern: powershell -enc 正则 - Count_Condition_Test: count >= 3 条件 - Size_Condition_Test: filesize <= 10KB 条件 YARA 命中验证: 7/7 ✅ L4-001 → Test_ReverseShell_Basic + keywords.ReverseShellNetcat 复合命中 L4-004 → Test_ReverseShell_Basic + Test_PowerShell_Download + 3 条关键词 L4-005/007/010/011/012 → 全部命中 ✅ 边界记录验证: 4/4 ✅ 全 clean L1-005 EICAR 1 字节修改 → ClamAV 不命中 ✅ L1-012 EICAR base64 → ClamAV 不解码 ✅ L3-007 高危串 base64 → 关键词不解码 ✅ L3-019 unicode 同形字 → 关键词不还原 ✅
This commit is contained in:
100
rules/test_rules.yar
Normal file
100
rules/test_rules.yar
Normal file
@@ -0,0 +1,100 @@
|
||||
/* MeshSafe 测试靶场 YARA 规则
|
||||
* 自动生成,覆盖 CSV L4-001 ~ L4-012
|
||||
* 引擎自动扫描 rules/*.yar,热加载
|
||||
*/
|
||||
|
||||
// L4-001: 基础规则 —— 正向命中 shell 反弹特征
|
||||
rule Test_ReverseShell_Basic {
|
||||
meta:
|
||||
family = "TestRules"
|
||||
author = "MeshSafe Test Suite"
|
||||
version = "1.0"
|
||||
description = "L4-001 基础规则: 匹配 nc 反弹 shell 特征"
|
||||
strings:
|
||||
$a = /nc\s+[0-9.]+\s+[0-9]+\s+-e/
|
||||
$b = /bash\s+-i\s+>&\s+\/dev\/tcp\//
|
||||
condition:
|
||||
$a or $b
|
||||
}
|
||||
|
||||
// L4-004: 第二条规则 —— 同时命中验证
|
||||
rule Test_PowerShell_Download {
|
||||
meta:
|
||||
family = "TestRules"
|
||||
author = "MeshSafe Test Suite"
|
||||
description = "L4-004 多规则同时命中: 匹配 PowerShell 下载"
|
||||
strings:
|
||||
$c = /Invoke-WebRequest\s+-Uri/
|
||||
$d = /powershell\s+-w\s+hidden/
|
||||
condition:
|
||||
$c or $d
|
||||
}
|
||||
|
||||
// L4-005: 新增规则(热加载验证)
|
||||
rule Newly_Added_Rule_Test {
|
||||
meta:
|
||||
family = "TestRules"
|
||||
author = "MeshSafe Test Suite"
|
||||
description = "L4-005 热加载验证: 运行时新增此规则后应能命中"
|
||||
strings:
|
||||
$e = "meshsafe-hot-reload-test-string"
|
||||
condition:
|
||||
$e
|
||||
}
|
||||
|
||||
// L4-007: metadata 标签测试
|
||||
rule Meta_Label_Test {
|
||||
meta:
|
||||
family = "Trojan.Generic"
|
||||
author = "Security Researcher"
|
||||
description = "L4-007 metadata 输出验证: 规则带完整 meta 字段"
|
||||
severity = "high"
|
||||
strings:
|
||||
$f = "trojan-metadata-test"
|
||||
condition:
|
||||
$f
|
||||
}
|
||||
|
||||
// L4-010: 正则型规则
|
||||
rule Regex_Shell_Pattern {
|
||||
meta:
|
||||
family = "TestRules"
|
||||
author = "MeshSafe Test Suite"
|
||||
description = "L4-010 正则匹配: powershell -enc 编码执行"
|
||||
strings:
|
||||
$g = /powershell\s+-e[nN][cC]\s+[A-Za-z0-9+\/]{20,}/
|
||||
condition:
|
||||
$g
|
||||
}
|
||||
|
||||
// L4-011: count 条件(出现 ≥3 次才触发)
|
||||
rule Count_Condition_Test {
|
||||
meta:
|
||||
family = "TestRules"
|
||||
author = "MeshSafe Test Suite"
|
||||
description = "L4-011 count 条件: 文件内匹配串 ≥3 次命中"
|
||||
strings:
|
||||
$h = "malicious_token_count_test"
|
||||
condition:
|
||||
#h >= 3
|
||||
}
|
||||
|
||||
// L4-012: size 条件(仅匹配 ≤10KB 的文件)
|
||||
rule Size_Condition_Test {
|
||||
meta:
|
||||
family = "TestRules"
|
||||
author = "MeshSafe Test Suite"
|
||||
description = "L4-012 size 条件: 仅匹配 size <= 10KB 的文件"
|
||||
strings:
|
||||
$i = "size_condition_test_payload"
|
||||
condition:
|
||||
$i and filesize <= 10KB
|
||||
}
|
||||
|
||||
// L4-003: PE 内字符串(实际是 Test_PowerShell_Download 的 strings 也在 PE 里)
|
||||
// 已由 Test_PowerShell_Download 覆盖,因为 PE 里的 strings() 也会被 YARA 扫描
|
||||
|
||||
// L4-009: 加密包内无法扫描(不是规则缺失,是 zipfile 跳过加密内容)
|
||||
// L4-013: 大文件 YARA —— 由 Test_ReverseShell_Basic 自动覆盖大文件扫描
|
||||
// L4-014: 开关测试 —— 由引擎 is_enabled() 控制
|
||||
// L4-015: 哈希白名单 —— 需在 policy.yaml 配置,不是 .yar 文件
|
||||
Reference in New Issue
Block a user