Nageshvs11/Detection-Engineering
GitHub: Nageshvs11/Detection-Engineering
结合 Sigma、KQL、SPL 和 YARA 规则的检测工程知识库,并配备 MCP 服务器以支持 AI 辅助检测规则编写。
Stars: 0 | Forks: 0
# 检测工程
这是一个检测工程知识库,结合了 Sigma 规则、KQL (Microsoft Sentinel / Defender XDR)、SPL (Splunk) 和 YARA 规则 —— 并配备了一个 MCP 服务器,将知识库暴露给 Claude,以实现 AI 辅助的检测编写。
## 仓库结构
```
Detection-Engineering/
├── kql/ # KQL rules — Microsoft Sentinel / Defender XDR
│ ├── cloud/
│ ├── identity/
│ ├── windows/
│ ├── linux/ network/ web/ application/ macos/
│
├── splunk/ # SPL rules — Splunk Enterprise Security
│ ├── identity/ windows/ cloud/
│ ├── linux/ network/ web/ application/ macos/
│
├── rules/ # Sigma rules (platform-agnostic YAML)
├── yara/ # YARA detection rules
├── mappings/ # ATT&CK technique → rule ID index
├── server.py # MCP server (Claude Code integration)
└── .claude/skills/ # Detection engineering skill definitions
```
## 检测覆盖范围
### KQL 规则
所有规则均按照 Sigma YAML schema 编写为 `.yml` 文件。KQL 规则在 `kql_query:` 块中嵌入了 Sentinel/XDR 查询;SPL 规则使用 `spl_query:` 块。这提供了一种行业标准格式,在所有平台上具有一致的元数据。
| 文件 | 用例 ID | ATT&CK | 平台 | 严重性 |
|---|---|---|---|---|
| `kql/identity/001_dcsync_non_dc.yml` | OS-DET-AD-001 | T1003.006 — DCSync | Sentinel / Defender XDR | Critical |
| `kql/identity/002_mfa_fatigue_adfs_push_bombing.yml` | Identity-DET-Azure-002 | T1621 — MFA Request Generation | Sentinel | High / Critical |
| `kql/identity/003_password_spray.yml` | Identity-DET-Azure-003 | T1110.003 — Password Spray | Sentinel | High / Critical |
| `kql/identity/004_attack_chain_credential_access.yml` | Identity-DET-Azure-004 | T1110.003 · T1621 · T1078.004 — 相关链 | Sentinel | High / Critical |
| `kql/identity/005_kerberoasting_spn_request.yml` | OS-DET-AD-002 | T1558.003 — Kerberoasting | Sentinel | High / Critical |
| `kql/windows/001_pass_the_hash_ntlm_lateral_movement.yml` | OS-DET-WIN-001 | T1550.002 — Pass the Hash | Sentinel / Defender XDR | High / Critical |
| `kql/windows/002_handala_wiper_chain.yml` | OS-DET-WIN-002 | T1485 — Data Destruction | Sentinel / Defender XDR | Critical |
| `kql/cloud/001_impossible_travel_login.yml` | Cloud-DET-Azure-001 | T1078.004 — Cloud Accounts | Sentinel | High / Critical |
### Sigma 规则 (`rules/`)
| 类别 | 规则 |
|---|---|
| Credential Access — LSASS | `proc_access_win_lsass_memdump.yml`, `proc_access_win_lsass_minidump_api.yml`, `proc_access_win_lsass_dump_comsvcs_dll.yml`, `proc_access_win_lsass_susp_access_flag.yml`, `proc_access_win_hktl_handlekatz_lsass_access.yml` |
| Credential Access — Dumping tools | `proc_creation_win_lsass_dump_procdump.yml`, `proc_creation_win_sysinternals_procdump_lsass.yml`, `proc_creation_win_rundll32_process_dump_via_comsvcs.yml`, `rules/win_security_susp_lsass_dump_generic.yml` |
| Credential Access — Mimikatz | `proc_creation_win_hktl_mimikatz_command_line.yml` |
| Credential Access — Kerberos | `win_security_kerberoasting_activity.yml`, `win_security_kerberoasting_rc4.yml`, `win_security_susp_rc4_kerberos.yml`, `posh_ps_spn_enumeration_kerberoasting.yml`, `posh_ps_request_kerberos_ticket.yml`, `proc_creation_win_setspn_spn_enumeration.yml` |
| Lateral Movement | `win_security_pass_the_hash.yml`, `win_security_pass_the_hash_2.yml`, `win_security_overpass_the_hash.yml`, `win_susp_ntlm_auth.yml` |
| Privilege Escalation | `win_security_golden_ticket.yml` |
| Active Directory | `win_security_dcsync.yml`, `win_security_ad_replication_non_machine_account.yml` |
| Offensive Tools | `posh_ps_hktl_rubeus.yml`, `proc_creation_win_hktl_rubeus.yml`, `pipe_created_hktl_generic_cred_dump_tools_pipes.yml`, `file_event_win_lsass_default_dump_file_names.yml` |
### YARA 规则 (`yara/`)
| 文件 | 目标 | 描述 |
|---|---|---|
| `MAL_Win_CobaltStrike_Beacon_May26.yar` | Windows PE | CobaltStrike Beacon 检测 |
## KQL 规则设计
每个 KQL 规则都遵循标准结构:
- **双控制台支持** — 规则声明 `// Target: Sentinel`、`// Target: DefenderXDR` 或 `// Target: Both`,并使用正确的时间戳字段(`TimeGenerated` vs `Timestamp`)
- **上下文感知的 watchlist 排除** — 根据规则的关注领域应用七个标准的 Sentinel Watchlist(参见下方的排除矩阵)
- **严重性分级** — 当目标账户或资产出现在 `High-Value-Assets` 中时,告警将升级为 `Critical`
- **规则类型** — 每个规则在头部声明 `AnalyticRule`(自动创建 incident)或 `HuntingQuery`(由分析师审核)
- **去重** — `summarize + arg_max(TimeGenerated, *)` 确保在每个告警窗口内每个实体仅保留一行记录
- **分诊指南** — 每个规则都包含一个 `Triage` 字段,提供分步的分析师说明
### Sentinel Watchlist
| Watchlist | 用途 | 使用它的规则 |
|---|---|---|
| `VPN-Egress-IPs` | 企业 VPN 网关和 ZTNA 出口 IP | 网络、身份、云规则 |
| `Vuln-Scanner-IPs` | Nessus, Qualys, Rapid7, OpenVAS 扫描器 IP | 任何包含源 IP 字段的规则 |
| `BAS-IPs` | SafeBreach, AttackIQ, Cymulate, XM Cyber 代理和控制器 IP | 任何包含源 IP 字段的规则 |
| `Service-Accounts` | 非人类账户 —— 服务、自动化、同步账户 | 每个身份、登录和进程规则 |
| `Admin-Workstations` | PAW 机器、跳板机、堡垒服务器 | 终端、横向移动、凭证访问规则 |
| `Sanctioned-Tools` | 批准的安全和管理工具进程名 | 进程创建、执行、防御规避规则 |
| `Sanctioned-Apps` | 批准的应用名称 (AppDisplayName) —— 备份代理、同步工具、SIEM 连接器 | 身份、云、MFA 规则 |
| `High-Value-Assets` | 域控制器、CA 服务器、PAM 服务器、核心资产 | 所有规则 —— 严重性分级 |
## SPL 规则设计
SPL 规则(编写后会添加到 `splunk/` 中)遵循相同的原则,并针对 Splunk ES 进行了调整:
- **索引路由** — 规则针对正确的索引模式(`*-os-win`, `*-os-linux`, `*-network`, `*-edr`, `*-azure`, `*-pam` 等)
- **上下文感知的 lookup 排除** — 七个标准的 lookup CSV 映射 Sentinel Watchlist,并根据规则的关注领域进行应用(参见下方的排除矩阵)
- **规则类型** — `CorrelationSearch`(创建 notable event)或 `SavedSearch`(分析师审核报告)
- **RBA 支持** — 高频信号使用 Risk-Based Alerting 模式(`risk_object`, `risk_score`, `risk_index`),而不是直接生成 notable event
### Splunk Lookup CSV
| CSV 文件 | 用途 | 使用它的规则 |
|---|---|---|
| `vpn_egress_ips.csv` | 企业 VPN 网关和 ZTNA 出口 IP | 网络、身份、云规则 |
| `vuln_scanner_ips.csv` | Nessus, Qualys, Rapid7, OpenVAS 扫描器 IP | 任何包含 `src_ip` 或 `dest_ip` 字段的规则 |
| `bas_ips.csv` | SafeBreach, AttackIQ, Cymulate, XM Cyber 代理和控制器 IP | 任何包含 `src_ip` 或 `dest_ip` 字段的规则 |
| `service_accounts.csv` | 非人类账户 —— 服务、自动化、同步账户 | 每个身份、登录和进程规则 |
| `admin_workstations.csv` | PAW 机器、跳板机、堡垒服务器 | 终端、横向移动、凭证访问规则 |
| `sanctioned_tools.csv` | 批准的安全和管理工具进程名 | 进程创建、执行、防御规避规则 |
| `high_value_assets.csv` | 域控制器、CA 服务器、PAM 服务器、核心资产 | 所有规则 —— 严重性分级 |
## 排除矩阵
每个规则都根据其关注领域应用排除项。下方的矩阵确定了每种规则类型所需的 watchlist 和 lookup CSV。
| 规则关注点 | 必需的排除项 | 原因 |
|---|---|---|
| **网络** (防火墙、代理、DNS、IDS/IPS) | VPN IP · 扫描器 IP · BAS IP | 扫描器和 BAS 工具会生成与网络检测模式匹配的高频授权流量 |
| **身份/认证** (登录、MFA、LDAP、Kerberos) | 服务账户 · VPN IP · 扫描器 IP · BAS IP · 批准的应用 | 扫描器/BAS 的认证尝试看起来与凭证填充完全相同;批准的应用(备份、同步)合法地对多个账户进行认证 |
| **进程执行** (进程创建、脚本执行) | 服务账户 · 管理工作站 · 批准的工具 | 管理员和批准的工具会运行与攻击者滥用的相同的二进制文件 |
| **凭证访问** (LSASS, SAM, DPAPI) | 服务账户 · 管理工作站 · 批准的工具 · 扫描器 IP · BAS IP | 扫描器和 BAS 工具会探测凭证存储,作为授权评估的一部分 |
| **横向移动** (PsExec, WMI, SMB, RDP) | 服务账户 · 管理工作站 · 扫描器 IP · BAS IP | 扫描器枚举 SMB/RDP;管理员使用相同的远程管理工具 |
| **云** (Azure/AWS/GCP API,资源更改) | 服务账户 · VPN IP · 扫描器 IP · BAS IP · 批准的应用 | 云评估工具、自动化账户和批准的云连接器应用会生成高频的授权 API 调用 |
| **终端/EDR** (文件、注册表、注入) | 服务账户 · 管理工作站 · 批准的工具 · BAS IP | BAS 代理直接在终端上运行,并执行与真实攻击者相同的 artifact |
| **PAM/特权访问** | 服务账户 · 扫描器 IP · BAS IP | 密码轮换脚本和 BAS 凭证测试模块直接与 PAM API 交互 |
| **所有规则** | High-Value-Assets | 严重性分级 —— 始终应用,从不作为排除项使用 |
**快速决策规则:**
- 规则包含源 IP 字段 → 始终添加 VPN + 扫描器 + BAS IP
- 规则包含用户/账户字段 → 始终添加服务账户
- 规则针对进程执行或终端活动 → 始终添加管理工作站 + 批准的工具
- 规则针对登录、MFA 或云 API 活动 → 始终添加批准的应用
## Claude Code 集成 (MCP 服务器)
`server.py` 是一个 [MCP (Model Context Protocol)](https://modelcontextprotocol.io) 服务器,它将此知识库暴露给 Claude Code。注册后,Claude 可以:
- 按 ATT&CK 技术浏览和查询 Sigma 规则
- 检查 `mappings/attack_techniques.json` 中的检测覆盖缺口
- 将 Hayabusa 扫描命中结果与规则 ID 进行交叉比对
**在 `~/.claude/settings.json` 中注册:**
```
{
"mcpServers": {
"detection-kb": {
"command": "python",
"args": ["/path/to/Detection-Engineering/server.py"]
}
}
}
```
**独立运行:**
```
python server.py
```
### 检测工程技能
`.claude/skills/detection-engineering/SKILL.md` 是一个 Claude Code 技能,用于在编写或审查规则时强制执行检测质量标准。它涵盖:
- ATT&CK 技术标签要求
- 严重性级别判定
- 误报文档
- 测试用例生成
- 文件命名和序列编号
- KQL watchlist 和 SPL lookup 排除模式
- 规则类型分类和提升路径
自定义数据源 schema 存储在 `.claude/skills/detection-engineering/references/` 下:
| 目录 | 用途 |
|---|---|
| `references/custom-tables/` | KQL `_CL` 表 schema(例如 `thycotic_cl.md`) |
| `references/custom-indexes/` | Splunk 自定义索引 schema(例如 `thycotic_pam.md`) |
## 添加规则
所有规则 —— KQL、SPL 和 Sigma —— 均按照 Sigma YAML schema 编写为 `.yml` 文件。
### KQL (Sentinel / Defender XDR)
1. 获取下一个序列号:
python .claude/skills/detection-engineering/scripts/next-seq.py kql/windows
# → 003
2. 使用 `SKILL.md` 中的 KQL YAML 模板创建 `kql//NNN_description.yml`
3. 将完整的 KQL 查询嵌入到 `kql_query:` 块标量中
4. 将技术映射添加到 `mappings/attack_techniques.json`
### SPL (Splunk ES)
1. 获取下一个序列号:
python .claude/skills/detection-engineering/scripts/next-seq.py splunk/windows
# → 001
2. 使用 `SKILL.md` 中的 SPL YAML 模板创建 `splunk//NNN_description.yml`
3. 将完整的 SPL 查询嵌入到 `spl_query:` 块标量中
4. 将技术映射添加到 `mappings/attack_techniques.json`
### Sigma (平台无关)
1. 遵循 SigmaHQ 命名约定创建 `rules/.yml`
2. 验证:`python .claude/skills/detection-engineering/scripts/validate-rule.py rules/.yml`
3. 如果需要,使用 sigma-cli 转换为 KQL 或 SPL:
sigma convert -t microsoft365defender rules/.yml
sigma convert -t splunk rules/.yml
4. 添加到 `mappings/attack_techniques.json`
## ATT&CK 技术索引
`mappings/attack_techniques.json` 将 ATT&CK 技术 ID 映射到规则 ID。目前涵盖:
| 技术 | 名称 | 规则 |
|---|---|---|
| T1003.006 | DCSync | `OS-DET-AD-001_dcsync_non_dc` |
| T1550.002 | Pass the Hash | `OS-DET-WIN-001_pass_the_hash_ntlm_lateral_movement` |
| T1621 | MFA Request Generation | `Identity-DET-Azure-002_mfa_fatigue_adfs_push_bombing` |
## 前置条件
| 组件 | 要求 |
|---|---|
| KQL 规则 | 启用了相关数据连接器的 Microsoft Sentinel 工作区 |
| Defender XDR 规则 | Microsoft Defender XDR Advanced Hunting 访问权限 |
| SPL 规则 | 部署了 lookup CSV 的 Splunk Enterprise Security |
| MCP 服务器 | Python 3.9+,`mcp` package |
| Sigma 验证 | `pyyaml` package |
标签:AMSI绕过, KQL, MCP, Sigma规则, 威胁检测, 安全运营, 扫描框架, 目标导入, 逆向工具