jadhavyash/detection-engineering-splunk-mitre
GitHub: jadhavyash/detection-engineering-splunk-mitre
一个基于 Splunk SPL 的安全检测工程实验项目,提供五条映射 MITRE ATT&CK 框架并经红队验证的攻击检测规则。
Stars: 0 | Forks: 0
# 🔍 Splunk 检测工程实验室 — MITRE ATT&CK 自定义规则
## 📐 架构概述
```
┌─────────────────────────────────────────────────────────┐
│ Detection Pipeline │
│ │
│ ┌──────────────────┐ ┌────────────────────────┐ │
│ │ Windows Endpoint │─────►│ Splunk Universal │ │
│ │ │ │ Forwarder │ │
│ │ ● Security Logs │ └──────────┬─────────────┘ │
│ │ ● Sysmon Events │ │ │
│ │ ● PowerShell │ ▼ │
│ │ ScriptBlock │ ┌────────────────────────┐ │
│ └──────────────────┘ │ Splunk Indexer │ │
│ │ index=windows │ │
│ └──────────┬─────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────┐ │
│ │ SPL Detection Rules │ │
│ │ (Saved as Alerts) │ │
│ └──────────┬─────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────┐ │
│ │ Splunk Dashboard │ │
│ │ MITRE ATT&CK Coverage │ │
│ └────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
```
## 🗺️ MITRE ATT&CK 覆盖范围
| 规则 | 技术 ID | 技术名称 | 战术 | 事件来源 |
|---|---|---|---|---|
| RULE-001 | T1055 | 进程注入 | 防御规避, 权限提升 | Sysmon EventCode 10, 8 |
| RULE-002 | T1053.005 | 计划任务/作业 | 执行, 持久化 | Windows Security 4698, 4702 |
| RULE-003 | T1003 | 操作系统凭证转储 (LSASS) | 凭证访问 | Sysmon EventCode 10 |
| RULE-004 | T1059.001 | PowerShell 混淆 | 执行 | PowerShell EventCode 4104 |
| RULE-005 | T1550.002 | Pass-the-Hash | 横向移动 | Windows Security 4624 |
## 🔧 前置条件
- **Splunk Enterprise**(免费试用版或授权版) — [下载](https://www.splunk.com/en_us/download/splunk-enterprise.html)
- **Sysmon**(由 Sysinternals 提供的系统监视器)已部署在 Windows 终端上 — [下载](https://learn.microsoft.com/en-us/sysinternals/downloads/sysmon)
- **Sysmon config** 已启用 ProcessAccess (EventCode 10) 和 CreateRemoteThread (EventCode 8) 日志记录
- 已通过组策略配置安全事件日志记录的 Windows 终端
**所需的 Windows 审核策略:**
| 策略 | 设置 |
|---|---|
| 审核登录事件 | 成功和失败 |
| 审核进程创建 | 成功 |
| 审核账户登录事件 | 成功和失败 |
| PowerShell 脚本块日志记录 | 已启用(组策略) |
| Sysmon EventCode 10 (ProcessAccess) | 在 Sysmon config 中启用 |
| Sysmon EventCode 8 (CreateRemoteThread) | 在 Sysmon config 中启用 |
**启用 PowerShell 脚本块日志记录(组策略):**
```
Computer Configuration → Administrative Templates →
Windows Components → Windows PowerShell →
Turn on Script Block Logging → Enabled
```
## ⚙️ Splunk 设置
**1. 创建索引:**
在 Splunk 中:`Settings → Indexes → New Index → Name: windows`
**2. 配置 Universal Forwarder 的 `inputs.conf`:**
```
[WinEventLog://Security]
index = windows
disabled = false
[WinEventLog://Microsoft-Windows-Sysmon/Operational]
index = windows
disabled = false
[WinEventLog://Microsoft-Windows-PowerShell/Operational]
index = windows
disabled = false
```
**3. 验证数据流:**
```
index=windows | head 10
```
## 🧠 检测规则 (SPL)
### RULE-001 — 进程注入 (T1055)
通过 Sysmon EventCode 10 (ProcessAccess) 检测具有高权限访问权限的跨进程内存访问 — 这是 DLL 注入、进程镂空和 shellcode 注入的关键指标。
```
index=windows EventCode=10 OR EventCode=8
| where TargetImage!=SourceImage
| eval technique="T1055 - Process Injection"
| stats count by SourceImage, TargetImage, GrantedAccess, _time
| where GrantedAccess="0x1fffff" OR GrantedAccess="0x1f0fff"
| eval severity=if(count>5,"HIGH","MEDIUM")
| table _time, SourceImage, TargetImage, GrantedAccess, count, severity
```
**关键指标:**
- `GrantedAccess = 0x1fffff` — 完全进程访问权限(所有权限)
- 源进程:`powershell.exe`、`mshta.exe`、`cmd.exe`
- 目标进程:`lsass.exe`、`svchost.exe`、`winlogon.exe`、`explorer.exe`
### RULE-002 — 计划任务创建 (T1053.005)
标记 Windows 任务创建或修改 (EventCode 4698 / 4702),其中任务命令使用了可疑的解释器,例如 PowerShell、cmd、mshta、wscript 或 rundll32。
```
index=windows EventCode=4698 OR EventCode=4702
| eval technique="T1053.005 - Scheduled Task"
| rex field=TaskContent "(?(?P[^<]+))"
| eval suspicious=if(match(cmd, "powershell|cmd|wscript|mshta|rundll32"), "YES", "NO")
| where suspicious="YES"
| stats count by TaskName, TaskCommand, UserName, ComputerName
| sort -count
```
**关键指标:**
- 模仿 Windows 内置组件的任务名称(例如 `\Microsoft\WindowsUpdate`)
- 使用 `-enc`、`-w hidden` 或 `-exec bypass` 的命令
- 包含外部 URL 的任务(`mshta.exe http://...`)
### RULE-003 — 操作系统凭证转储 / LSASS (T1003)
检测任何访问 `lsass.exe` 内存的行为 — 这是 Mimikatz 和 ProcDump 等工具用于提取密码哈希和明文凭证的主要方法。
```
index=windows EventCode=10 TargetImage="*lsass.exe"
| eval technique="T1003 - Credential Dumping"
| eval tool=case(
match(SourceImage,"mimikatz"),"Mimikatz",
match(SourceImage,"procdump"),"ProcDump",
match(GrantedAccess,"0x1fffff"),"Full Access Dump",
1==1,"Unknown")
| eval severity="CRITICAL"
| stats count by SourceImage, GrantedAccess, tool, _time, ComputerName
| sort -_time
```
**关键指标:**
- `mimikatz.exe` 或 `procdump.exe` 作为 `SourceImage` → **需要立即进行 CRITICAL 级别的响应**
- `powershell.exe` 访问 `lsass.exe` → 内存中的 Mimikatz
- 对 lsass 的 `GrantedAccess = 0x1fffff`
### RULE-004 — PowerShell 混淆 (T1059.001)
使用 ScriptBlock Logging (EventCode 4104) 识别混淆的 PowerShell 执行。根据在脚本块中发现的混淆指标分配综合风险评分。
```
index=windows EventCode=4104
| eval technique="T1059.001 - PowerShell Obfuscation"
| eval obfuscated=if(match(ScriptBlockText,
"-[Ee][Nn][Cc]|-[Ee][Nn][Cc][Oo][Dd][Ee]|IEX|Invoke-Expression|FromBase64String"),
"YES", "NO")
| where obfuscated="YES"
| eval score=0
| eval score=score+if(match(ScriptBlockText,"-enc"),3,0)
| eval score=score+if(match(ScriptBlockText,"IEX|Invoke-Expression"),2,0)
| eval score=score+if(match(ScriptBlockText,"FromBase64String"),2,0)
| eval score=score+if(match(ScriptBlockText,"-NonInteractive"),1,0)
| table _time, ComputerName, UserName, score, ScriptBlockText
```
**风险评分指南:**
| 评分 | 严重程度 | 描述 |
|---|---|---|
| 5+ | HIGH | 结合使用了多种混淆技术 |
| 2–4 | MEDIUM | 单个混淆指标 |
| 1 | LOW | 轻微标记,需要上下文 |
**关键指标:**
- `-enc` 或 `-EncodedCommand` 带有长 Base64 字符串
- `IEX` / `Invoke-Expression` 带有下载托盘模式
- `SYSTEM` 账户运行编码的 PowerShell
### RULE-005 — Pass-the-Hash / 横向移动 (T1550.002)
使用 EventCode 4624(网络登录)检测 Pass-the-Hash 攻击,并结合 NTLM 认证、`KeyLength=0` 和空的 `SubjectUserName` — 这种组合可将 PtH 与合法的网络登录区分开来。
```
index=windows EventCode=4624 LogonType=3
| eval technique="T1550.002 - Pass the Hash"
| where AuthenticationPackageName="NTLM" AND KeyLength=0
| eval pth_indicator=if(
match(SubjectUserName,"-") AND SubjectLogonId="0x0",
"LIKELY_PTH","REVIEW")
| stats count by SubjectUserName, IpAddress, WorkstationName, LogonType, pth_indicator
| where pth_indicator="LIKELY_PTH"
| sort -count
```
**关键指标:**
- `SubjectUserName = "-"`(破折号)— PtH 的标志,在登录时没有主体身份
- `KeyLength = 0` 结合 NTLM 认证
- 短时间窗口内来自单一源 IP 针对多个目标的频繁命中
- 与 RULE-003 交叉引用 — 凭证被转储随后用于横向移动
## 💾 将规则保存为计划告警
一旦查询产生准确的结果,将其保存为 Splunk 告警以自动运行:
1. 在 **Search & Reporting** 中运行 SPL 查询
2. 点击 **Save As → Alert**
3. 设置 **Alert Title**(例如 `RULE-003: LSASS Credential Dump Detected`)
4. 将 **Permissions** 设置为 `Shared in App`
5. 将 **Alert type** 设置为 `Scheduled`
6. 设置 **Cron schedule**(例如,每 15 分钟:`*/15 * * * *`)
7. 设置 **Time Range** 以匹配计划窗口(例如,过去 15 分钟)
8. 设置 **Trigger Condition**:结果数大于 `0`
9. 添加 **Trigger Action**:发送电子邮件或 Slack webhook 通知
10. 点击 **Save**
## 📊 快速参考 — 所有 5 条规则
| 规则 ID | MITRE ID | EventCode(s) | SPL 关键过滤器 |
|---|---|---|---|
| RULE-001 | T1055 | Sysmon 10, 8 | `GrantedAccess="0x1fffff" AND TargetImage!=SourceImage` |
| RULE-002 | T1053.005 | 4698, 4702 | `match(cmd, "powershell\|mshta\|wscript")` |
| RULE-003 | T1003 | Sysmon 10 | `TargetImage="*lsass.exe"` |
| RULE-004 | T1059.001 | 4104 | `match(ScriptBlockText, "-enc\|IEX\|FromBase64String")` |
| RULE-005 | T1550.002 | 4624 | `LogonType=3 AND NTLM AND KeyLength=0` |
## 🛠️ 技术栈
| 技术 | 用途 |
|---|---|
| **Splunk Enterprise** | SIEM 平台 — 索引、SPL 查询、告警、仪表板 |
| **Sysmon (Sysinternals)** | 终端遥测 — ProcessAccess、CreateRemoteThread、网络事件 |
| **Windows Event Log** | 原生 Windows 安全和 PowerShell 事件 |
| **SPL** | Splunk 的搜索处理语言 — 检测规则逻辑 |
| **MITRE ATT&CK** | 对手技术框架,用于映射和验证每条规则 |
## 📚 参考资料
- [MITRE ATT&CK 框架](https://attack.mitre.org)
- [Splunk SPL 文档](https://docs.splunk.com/Documentation/Splunk/latest/SearchReference)
- [Sysmon 事件 ID 参考](https://learn.microsoft.com/en-us/sysinternals/downloads/sysmon)
- [SwiftOnSecurity Sysmon 配置](https://github.com/SwiftOnSecurity/sysmon-config)
- [Splunk Security Essentials 应用](https://splunkbase.splunk.com/app/3435)
- [MITRE ATT&CK T1055 — 进程注入](https://attack.mitre.org/techniques/T1055/)
- [MITRE ATT&CK T1003 — 凭证转储](https://attack.mitre.org/techniques/T1003/)
## ⚠️ 免责声明
该项目完全出于**教育和网络安全研究目的**而构建。所示的所有检测规则、事件数据和截图均在受控实验室环境中生成。这些 SPL 查询仅作为起点 — 在生产环境中部署之前,请务必针对您的特定环境进行调整,以减少误报。切勿在授权的独立实验室之外运行攻击性安全工具。
## 📄 许可证
MIT License — 免费分支、改编和构建。
标签:AMSI绕过, Atomic Red Team, Cloudflare, MITRE ATT&CK, Modbus, PB级数据处理, SPL检测规则, 威胁检测, 安全运维, 数据泄露检测