didjas88-bot/pcap-c2-incident-analysis
GitHub: didjas88-bot/pcap-c2-incident-analysis
端到端的合成 C2 事件网络取证演练项目,从生成模拟入侵流量到输出包含 IoC、Sigma 规则和 ATT&CK 映射的完整事件报告。
Stars: 0 | Forks: 0
# PCAP 分析:合成 C2 事件响应
全周期网络取证案例 —— 从生成被攻陷的 PCAP 到交付面向客户的最终事件报告,包含 IoCs、Sigma 规则和 MITRE ATT&CK 映射。
## 场景
企业网络 `192.168.1.0/24` 中的一台工作站 `192.168.1.100` 被 C2 框架(Cobalt Strike 风格)攻陷。在捕获的 12.8 分钟流量中:
| 攻击阶段 | MITRE ATT&CK | 描述 |
|---|---|---|
| 网络发现 | T1046 | 对 30 台内部主机进行 SMB 端口扫描(端口 139、445) |
| C2 Beaconing | T1071.001 | 每隔约 60s 定期向 `185.220.101.42:443` 发送 beacon(抖动率 14.6%) |
| DNS Exfiltration | T1071.004 | 通过 `exfil.attacker-domain.xyz` 的子域名传输 Base32 编码的窃取数据 |
| HTTP Exfiltration | T1041 | 向 `91.243.85.117:8080/upload.php` 发送 1346 字节的 POST 请求 |
| 未加密 Exfiltration | T1048.003 | DNS 隧道作为数据外泄通道 |
## Kill Chain
```
Initial Access (outside PCAP scope) → Execution → Discovery (T1046) →
C2 (T1071.001) → Collection → Exfiltration (T1041 + T1071.004 + T1048.003)
```
## Repository 结构
```
pcap-c2-incident-analysis/
├── infected_capture.pcap # Source traffic (144 packets, 16 KB)
├── scripts/
│ ├── gen_infected_pcap.py # Traffic generator (creates the PCAP)
│ ├── analyze_pcap.py # Analyzer v1
│ ├── analyze_pcap_v2.py # Analyzer v2 (extended coverage)
│ └── dns_exfil_decode.py # DNS exfiltration decoder (base32)
├── reports/
│ ├── incident_report.md # Human-readable incident report
│ ├── analysis_report.json # Machine-readable statistics
│ ├── dns_exfil_decoded.txt # Recovered stolen data (154 bytes)
│ └── analysis_v2_console.log # Full analysis console log
├── iocs/
│ └── iocs_stix21.json # STIX 2.1 bundle for SIEM import
└── detections/
├── sigma_ioc_rules.yml # 4 Sigma detection rules
└── attack_navigator_layer.json # ATT&CK Navigator heatmap layer
```
## 提取的 IoCs
### IP
| IP | 上下文 |
|---|---|
| `185.220.101.42` | C2 服务器 (beaconing) |
| `91.243.85.117` | HTTP 数据外泄 endpoint |
### 域名
| 域名 | 上下文 |
|---|---|
| `exfil.attacker-domain.xyz` | DNS 数据外泄隧道 |
| `malicious-c2.example.com` | 指向 C2 的 TLS SNI |
### User-Agents
| UA | 指标 |
|---|---|
| `Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)` | 默认 Cobalt Strike beacon UA |
| `python-requests/2.31.0` | 非浏览器数据外泄 |
### 恢复的窃取数据(通过 DNS 隧道)
| 类型 | 示例 |
|---|---|
| 凭据 | `admin:Passw0rd123!` |
| AWS Key | `AKIAIOSFODNN7EXAMPLE` |
| SSH Key | `ssh-rsa AAAA...root@prod-db-01` |
| 文件路径 | `\\fileserver\share\HR\salary_2025.xlsx` |
| 业务数据 | `customer_db_export_part_1_of_3` |
## Sigma 检测规则
| # | 规则 | 级别 | ATT&CK |
|---|---|---|---|
| 1 | 通过超长子域名进行 DNS 数据外泄 | critical | T1071.004, T1048.003 |
| 2 | 向已知 C2 IP 进行 HTTP POST 数据外泄 | critical | T1041, T1048.003 |
| 3 | Cobalt Strike Beacon 默认 User-Agent | critical | T1071.001, T1090 |
| 4 | 来自单一源的内部 SMB 端口扫描 | high | T1046 |
验证:PyYAML `safe_load_all` 通过,pySigma `SigmaCollection.from_yaml` 通过。
## 工具与技术
- **Scapy 2.7.0** — 数据包构造与分析
- **Shannon 熵** — DNS 子域名异常检测
- **变异系数(RITA 指标)** — beacon 频率分析
- **Base32 解码** — DNS 隧道数据恢复
- **STIX 2.1** — 结构化 IoC bundle
- **Sigma 2.0** — SIEM 检测规则
- **MITRE ATT&CK Navigator** — 技术覆盖率热力图
## 复现
```
# 1. 生成受感染的 PCAP
python scripts/gen_infected_pcap.py
# 2. 运行分析
python scripts/analyze_pcap_v2.py
# 3. 解码 DNS exfiltration
python scripts/dns_exfil_decode.py
```
依赖要求:`scapy>=2.7.0`, `pyyaml`, `pysigma`
## 关键指标
| 指标 | 数值 |
|---|---|
| 总数据包数 | 144 |
| 捕获时长 | 12.8 分钟 |
| Beacon 间隔 | 平均 59.6s,抖动率 14.6% |
| DNS 数据外泄量 | 154 字节 |
| HTTP 数据外泄量 | 1346 字节 |
| 扫描主机数 | 30 |
| 映射的 ATT&CK 技术数 | 5 |
| 生成的 Sigma 规则数 | 4 |
| 严重程度 | HIGH (P2) |
标签:代码示例, 威胁情报, 库, 应急响应, 开发者工具, 恶意代码分类, 插件系统, 数据分析, 网络安全, 网络流量取证, 逆向工具, 隐私保护