jaypatel-Cyber/Malware-Traffic-Analysis
GitHub: jaypatel-Cyber/Malware-Traffic-Analysis
一套端到端的恶意软件流量取证管线,整合 Zeek、Suricata 和 ELK 实现从 PCAP 摄取、威胁情报丰富到感染链可视化的全流程自动化分析。
Stars: 0 | Forks: 0
# 企业级恶意软件流量分析 (Zeek → ELK)
**角色定位:** 网络安全分析师 / 事件响应人员
**难度:** 高级
**状态:** 已完成
## 目标
通过全自动化的 Python Pipeline 摄取真实世界的恶意软件 PCAP (Emotet, Trickbot, Qakbot),该流程:
1. 运行 **Zeek** 和 **Suricata** 以生成结构化的网络日志
2. 通过三个威胁情报源提取并丰富 IOC (IPs, domains, file hashes)
3. 将每个事件分类为 **感染链阶段** (初始攻陷 → 数据窃取)
4. 将所有事件索引到 **Elasticsearch** 中,并在 **Kibana** 中可视化完整的攻击时间线
## 架构
```
┌──────────────────────┐
│ Malware PCAP Input │ ← malware-traffic-analysis.net or local file
└──────────┬───────────┘
│
┌────────┴──────────────────┐
│ │
┌─▼──────────┐ ┌────────▼──────────┐
│ Zeek 6.x │ │ Suricata 7.x │
│ │ │ (IDS alerts) │
│ conn dns │ │ eve.json │
│ http ssl │ └────────┬──────────┘
│ files │ │
└─────┬──────┘ │
└──────────┬────────────┘
│ Normalised JSON events
▼
┌───────────────────────┐
│ Threat Intel Enricher │◄─── AbuseIPDB + VirusTotal + OTX
│ (threat score 0–100) │
└───────────┬────────────┘
│ Enriched events
▼
┌───────────────────────┐
│ Infection Chain │
│ Annotator │ → Stage 1–6 + MITRE ATT&CK tags
└───────────┬────────────┘
│
┌───────────▼────────────┐ ┌─────────────────────┐
│ Elasticsearch 8.x │ │ Incident Report │
│ malware-traffic-* │ │ (JSON + terminal) │
└───────────┬────────────┘ └─────────────────────┘
│
┌───────────▼────────────┐
│ Kibana Dashboard │
│ (Infection Chain viz) │
└────────────────────────┘
```
## 技术栈
| 组件 | 工具 | 角色 |
|---|---|---|
| 网络分析 | Zeek 6.x | 2–7 层连接/协议日志 |
| IDS 告警 | Suricata 7.x + ET Open Rules | 基于特征的威胁检测 |
| 威胁情报 | AbuseIPDB v2, VirusTotal v3, OTX | IOC 评分与丰富 |
| 数据存储 | Elasticsearch 8.13 | 时序事件存储 |
| 可视化 | Kibana 8.13 | 感染链仪表板 |
| 编排 | Python 3.11 (stdlib only) | Pipeline 自动化 |
| 容器化 | Docker Compose | ELK Stack 部署 |
| Detection-as-Code | Sigma (YAML) | 可移植检测规则 |
| 自定义检测 | Zeek 脚本语言 | C2 beacon, DNS tunnel, exfil 检测 |
## 感染链阶段
| 阶段 | 名称 | MITRE ATT&CK | 指标 |
|---|---|---|---|
| 1 | 初始攻陷 (Initial Compromise) | T1566, T1189 | 恶意 HTTP 下载, 钓鱼 URL |
| 2 | 恶意软件投递 (Malware Delivery) | T1105, T1059 | 来自标记主机的 `.exe/.dll/.ps1` 下载 |
| 3 | C2 Beacon | T1071.001, T1071.004 | 周期性连接, 低标准差间隔 |
| 4 | 二次载荷 (Secondary Payload) | T1105, T1547 | `/gate.php`, `/payload` 端点模式 |
| 5 | 横向移动 (Lateral Movement) | T1021, T1135 | 内部 SMB/RDP/WMI 连接 |
| 6 | 数据窃取 (Data Exfiltration) | T1041, T1048 | 向恶意 IP 的出站流量 >10 MB |
## 自定义 Zeek 检测
| 通知类型 | 检测逻辑 | MITRE |
|---|---|---|
| `C2_Beaconing` | 连接间隔标准差 < 5s 且超过 ≥5 个间隔 | T1071 |
| `DNS_Tunneling` | 查询标签 > 52 个字符或十六进制编码的子域 | T1071.004 |
| `Suspicious_UserAgent` | 匹配已知恶意软件 UA 片段 (Emotet, Trickbot) | T1071.001 |
| `Executable_Download` | HTTP 200 响应下载 `.exe/.dll/.ps1` 文件 | T1105 |
| `Large_Exfiltration` | 向外部 IP 的出站流量 > 10 MB | T1041 |
| `SelfSigned_Cert` | TLS 证书颁发者 == 使用者 | T1573 |
| `Malware_Port` | 连接到已知 RAT 端口 (4444, 31337, 9001) | T1571 |
## Sigma 规则
| 规则文件 | 技术 | 严重性 |
|---|---|---|
| `c2_beaconing_detection.yml` | T1071.001, T1571, T1573.001 | High |
| `dns_tunneling_detection.yml` | T1071.004, T1048.001, T1568.002 | High |
| `malware_delivery_detection.yml` | T1566.001, T1059, T1027, T1105 | Critical |
## 快速开始
### 1. 前置条件
```
# 安装 Zeek (Ubuntu/Debian)
echo 'deb http://download.opensuse.org/repositories/security:/zeek/xUbuntu_22.04/ /' \
| sudo tee /etc/apt/sources.list.d/security:zeek.list
sudo apt update && sudo apt install zeek
# 安装 Suricata + ET Open rules
sudo apt install suricata
sudo suricata-update
# 安装 Python 3.11+
python3 --version # 3.11+ required
```
### 2. 启动 ELK Stack
```
cd Project_3_Malware_Traffic_Analysis/
docker-compose up -d elasticsearch kibana
# 等待 Elasticsearch 变为健康状态 (~30s)
curl http://localhost:9200/_cluster/health
```
### 3. 配置环境
```
cp .env.example .env
# 使用您的 API keys 编辑 .env:
# ABUSEIPDB_KEY — https://www.abuseipdb.com/account/api
# VIRUSTOTAL_KEY — https://www.virustotal.com/gui/my-apikey
# OTX_KEY — https://otx.alienvault.com/api
```
### 4. 获取恶意软件 PCAP
```
# 选项 A:直接从 malware-traffic-analysis.net 下载
python3 pipeline/pcap_downloader.py \
--url https://malware-traffic-analysis.net/2024/01/15/2024-01-15.pcap.zip
# 选项 B:搜索 Emotet 样本
python3 pipeline/pcap_downloader.py --search emotet --limit 3
# 选项 C:使用包含的样本数据 (无需 PCAP)
python3 pipeline/elk_ingestor.py --events sample_data/sample_emotet_zeek_logs.json
```
### 5. 运行完整 Pipeline
```
cd pipeline/
# 完整 pipeline (Zeek + Suricata + enrichment + ELK)
python3 pipeline_orchestrator.py --pcap ../pcaps/your_sample.pcap
# 跳过 Suricata (更快,若未安装)
python3 pipeline_orchestrator.py --pcap ../pcaps/your_sample.pcap --no-suricata
# Dry run — 分析但不写入 Elasticsearch
python3 pipeline_orchestrator.py --pcap ../pcaps/your_sample.pcap --dry-run
# 将事件报告保存为 JSON
python3 pipeline_orchestrator.py --pcap ../pcaps/your_sample.pcap --report-json
```
### 6. 导入 Kibana 仪表板
```
# 通过 Kibana UI:Stack Management → Saved Objects → Import
# 文件:kibana/dashboards/malware_traffic_dashboard.ndjson
# 或通过 API:
curl -X POST "http://localhost:5601/api/saved_objects/_import" \
-H "kbn-xsrf: true" \
--form file=@kibana/dashboards/malware_traffic_dashboard.ndjson
```
### 7. 运行测试
```
python3 -m pytest tests/test_pipeline.py -v
# 或独立运行 (无 pytest):
python3 tests/test_pipeline.py
```
## 服务 URL
| 服务 | URL | 凭证 |
|---|---|---|
| Kibana | http://localhost:5601 | elastic / changeme |
| Elasticsearch | http://localhost:9200 | elastic / changeme |
| ES 健康状态 | http://localhost:9200/_cluster/health | — |
| ES 索引 | http://localhost:9200/_cat/indices?v | — |
## 文件结构
```
Project_3_Malware_Traffic_Analysis/
├── README.md
├── .env.example # API key template
├── docker-compose.yml # ELK + Zeek + Suricata containers
│
├── pipeline/
│ ├── pipeline_orchestrator.py # Main entry point — wires all stages
│ ├── pcap_downloader.py # PCAP fetch + zip extraction
│ ├── zeek_runner.py # Zeek execution + log parsing
│ ├── suricata_runner.py # Suricata execution + eve.json parsing
│ ├── threat_intel_enricher.py # AbuseIPDB + VT + OTX enrichment
│ └── elk_ingestor.py # ES bulk index + Kibana setup
│
├── zeek/
│ └── scripts/
│ └── malware_detection.zeek # C2/DNS/exfil custom notices
│
├── suricata/
│ └── config/
│ └── suricata.yaml # Offline PCAP analysis config
│
├── elasticsearch/
│ └── templates/
│ └── zeek_index_template.json # Field mappings + index settings
│
├── kibana/
│ └── dashboards/
│ └── malware_traffic_dashboard.ndjson # 7-panel Saved Objects export
│
├── sigma_rules/
│ ├── c2_beaconing_detection.yml
│ ├── dns_tunneling_detection.yml
│ └── malware_delivery_detection.yml
│
├── sample_data/
│ └── sample_emotet_zeek_logs.json # Realistic Emotet infection events
│
├── tests/
│ └── test_pipeline.py # Unit + integration tests
│
├── docs/
│ └── architecture.md # Detailed pipeline architecture
│
└── pcaps/ # Downloaded PCAPs land here
```
## 展示的技能
| 技能 | 证据 |
|---|---|
| **网络取证** | Zeek 多协议日志解析 (conn/dns/http/ssl/files) |
| **Python 数据工程** | 流式 JSON 解析器, ES 批量索引, 限速 API 调用 |
| **威胁情报** | 多源丰富 (AbuseIPDB, VT, OTX), 标准化评分 |
| **事件响应** | 感染链分类器将事件映射到 6 阶段杀伤链 |
| **SIEM 架构** | ELK 索引模板, Kibana Saved Objects API, ILM 模式 |
| **检测工程** | 3 条 Sigma 规则 + 7 个自定义 Zeek 通知, 映射到 MITRE ATT&CK |
| **IDS 分析** | Suricata 规则覆盖, eve.json 解析, 告警分类 |
| **数据可视化** | Kibana 仪表板: 时间线, 热力图, 柱状/饼图, 异常表 |
| **基础设施即代码** | Docker Compose 实现可复现的 ELK Stack 部署 |
| **安全优先编码** | 私有 IP 过滤, 缓存去重, 无硬编码凭证 |
标签:Beacon Object File, DNS 反向解析, Elasticsearch, ELK Stack, Emotet, FTP漏洞扫描, HTTP工具, IP 地址批量处理, Metaprompt, PCAP分析, Python, Qakbot, Rootkit, Suricata, Trickbot, Zeek, 企业安全, 威胁情报, 安全编排, 开发者工具, 攻击链分析, 无后门, 版权保护, 现代安全运营, 网络信息收集, 网络安全, 网络资产管理, 自动化取证, 越狱测试, 逆向工具, 隐私保护