trac3r00/wazuh-ai-siem
GitHub: trac3r00/wazuh-ai-siem
一个基于 Wazuh 的 AI 驱动 SIEM 实验室,集成了自定义检测规则、LLM 威胁分流和自动化响应工作流,并通过真实攻击模拟验证检测效果。
Stars: 0 | Forks: 0
# 🛡️ Wazuh AI 驱动的 SIEM 与检测工程实验室




## 📌 本项目展示了什么
| 领域 | 我做了什么 |
|------|-----------|
| **SIEM 工程** | 从零开始部署并调优 Wazuh 4.14(Manager + Indexer + Dashboard);接入来自 Windows (Sysmon)、Linux、pfSense 防火墙和 AdGuard DNS 的日志 |
| **检测工程** | 编写了 11+ 条映射到 MITRE ATT&CK 的自定义检测规则,并通过真实的攻击模拟(Atomic Red Team、Impacket、Mimikatz)对每条规则进行了验证 |
| **AI 集成** | 构建了 Python 集成,将安全事件通过本地托管的 LLM (Qwen 14B) 进行威胁分流,并提供自然语言日志搜索服务(FAISS 向量数据库 + REST API) |
| **SOAR / 自动化响应** | 从 Discord 警报实现一键隔离 → n8n 工作流 → pfSense 防火墙封禁;使用自定义通用 iptables 包装器的 Wazuh 原生主动响应 |
| **对手模拟** | 部署了 GOAD 活动目录实验环境,并执行了 Kerberoasting、AS-REP Roasting、Pass-the-Hash、凭据转储 —— 随后设计了相应的检测规则来捕获它们 |
| **警报工程** | 抑制常规事件同时升级真实攻击的降噪规则集 —— 这是无人问津的仪表板与关键警报之间的本质区别 |
## 📐 架构
```
┌─────────────────────────────────────────────────────────────────────────┐
│ WAZUH SERVER │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Wazuh │ │ Threat │ │ MCP │ │ Discord │ │
│ │ Manager │ │ Hunter │ │ Server │ │ Alerts │ │
│ │ :55000 │ │ :8080 │ │ :8081 │ │ │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
│ │ │ │ │ │
│ └────────────────┴────────────────┴────────────────┘ │
│ │ │
└───────────────────────────────────┼─────────────────────────────────────┘
│
┌───────────────────────────┼───────────────────────────┐
│ │ │
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ AdGuard │ │ pfSense │ │ Local LLM │
│ DNS Agent │ │ Firewall │ │ Server │
│ (Agent) │ │ (Syslog) │ │ (Qwen 14B) │
└───────────────┘ └───────────────┘ └───────────────┘
│
▼
┌───────────────┐
│ n8n │
│ Automation │
│ (Webhooks) │
└───────────────┘
```
**技术栈:** Dell R720 上的 Proxmox VE · Wazuh 4.14.2 · Python 3.10 · LMStudio (Qwen 14B) · n8n · pfSense · AdGuard Home · Discord
## 🎯 检测工程亮点
所有规则均为自定义编写,映射到 MITRE ATT&CK,并且**通过在隔离实验室中实际执行攻击进行了验证** —— 而不是仅仅从博客文章中复制。
| 规则 ID | 检测内容 | MITRE ATT&CK | 验证方式 |
|---------|-----------|--------------|------------|
| 100001–2 | Mimikatz(文件名 + 命令行) | [T1003](https://attack.mitre.org/techniques/T1003/) | ✅ 执行 Mimikatz |
| 100003 | 编码的 PowerShell 命令 | [T1059.001](https://attack.mitre.org/techniques/T1059/001/) | ✅ Atomic Red Team |
| 100004 | PowerShell 下载启动器 | [T1059.001](https://attack.mitre.org/techniques/T1059/001/) | ✅ 实时模拟 |
| 100005 | 创建本地账户 | [T1136.001](https://attack.mitre.org/techniques/T1136/001/) | ✅ Atomic Red Team |
| 100006 | 计划任务持久化 | [T1053.005](https://attack.mitre.org/techniques/T1053/005/) | ✅ Atomic Red Team |
| 100007–8 | 篡改 Defender / 终止安全服务 | [T1562.001](https://attack.mitre.org/techniques/T1562/001/) | ✅ 实时模拟 |
| 100009 | Kerberoasting(RC4 票据请求) | [T1558.003](https://attack.mitre.org/techniques/T1558/003/) | ✅ Impacket GetUserSPNs |
| 100010 | AS-REP Roasting(无预身份验证) | [T1558.004](https://attack.mitre.org/techniques/T1558/004/) | ✅ Impacket GetNPUsers |
| 100011 | 恶意软件文件投放 (FIM) | [T1105](https://attack.mitre.org/techniques/T1105/) | ✅ 实时模拟 |
| 92652* | Pass-the-Hash(NTLM 登录类型 3) | [T1550.002](https://attack.mitre.org/techniques/T1550/002/) | ✅ 横向移动模拟 |
*\*内置规则,已针对 AD 实验环境中的实时 Pass-the-Hash 执行进行了验证。*
**值得注意的工程工作:**
- **Sysmon decoder 调试** —— 自定义规则最初静默失败,因为日志被解码为通用的 `json` 而不是 `windows_eventchannel`。通过 Wazuh 归档 (`logall_json`) 找到了根本原因,并设计了*自给自足的规则*,直接匹配 `win.system.providerName` + `eventID`,将检测逻辑与 decoder 的怪癖解耦。
- **主动响应字段不匹配** —— Wazuh 默认的 `firewall-drop` 需要 `srcip`,但 Suricata 发出的是 `src_ip`,导致自动化静默失败。构建了一个通用的 iptables 包装器,无论输入格式如何,都能从原始 STDIN 中提取 IP。结果:C2 user-agent 检测现在会触发即时的防火墙封禁。
→ 包含每日进展的完整实验日志:[`detection-lab/`](detection-lab/)
## 🤖 AI 驱动的组件
### 1. LLM 威胁分流(DNS + 防火墙)
Python 集成,在发出警报之前将安全事件提供给本地托管的 LLM 进行分类:
- **DNS 分析** ([`integrations/custom-ai-dns-discord.py`](integrations/custom-ai-dns-discord.py)) —— 未知域名由 AI 进行分类(恶意 / 追踪 / 安全);跳过已封禁和已知安全的域名以防止警报疲劳
- **防火墙分析** ([`integrations/custom-pfsense-ai-discord.py`](integrations/custom-pfsense-ai-discord.py)) —— 在来自单个 IP 的封禁超过 20 次/分钟时触发;AI 分类攻击类型(端口扫描、暴力破解等),并在 LLM 不可用时优雅降级
### 2. 自然语言威胁狩猎
[`services/threat_hunter.py`](services/threat_hunter.py) —— 通过 FAISS 向量数据库 + REST API 用纯英语查询安全日志:
### 3. MCP / Chat API 服务器
[`services/mcp_server.py`](services/mcp_server.py) —— 用于 SIEM 交互的 REST API + Web UI:代理状态、警报摘要、对话式日志查询。
### 4. AI 文件伪装检测 (Magika)
[`integrations/file_masquerade_scan.py`](integrations/file_masquerade_scan.py) —— 使用 Google 的 **[Magika](https://github.com/google/magika)** 深度学习内容分类器,从文件字节中识别其*真实*类型,并标记实际内容与其扩展名不符的文件 —— 经典的 dropper/webshell 伪装(一个保存为 `report.csv` 的 shell 脚本,一个伪装成 `readme.txt` 的 ELF)。发出映射到 **MITRE ATT&CK [T1036.008](https://attack.mitre.org/techniques/T1036/008/)**(伪装文件类型)且适配 Wazuh 的 JSON 事件,由 [`rules/magika_masquerade_rules.xml`](rules/magika_masquerade_rules.xml) 消费(级别 8→14,针对 Web 服务目录中的原生可执行文件进行升级)。在 cron/inotify 触发器上将其指向某个上传目录:
```
file_masquerade_scan.py /var/www/uploads --json-out /var/log/masquerade.json
```
自检 ([`integrations/selftest_masquerade.py`](integrations/selftest_masquerade.py)) 验证了对合成样本的检测,并在 CI 中运行。
## ⚡ 自动化响应 (SOAR)
Discord 警报包含连接到 n8n 工作流的**一键响应按钮**:
| 操作 | 流程 |
|--------|------|
| 🔒 隔离 | Discord 按钮 → n8n webhook → SSH 到 pfSense → 在防火墙封禁 IP |
| 🔓 取消隔离 | Discord 按钮 → n8n webhook → 释放 IP |
| 🔇 忽略域名 | Discord 按钮 → n8n webhook → 追加到 Wazuh CDB 安全列表 |
受保护的 IP 护栏可防止自动化系统隔离关键基础设施。
```
DNS Query → AdGuard
├── Blocked? → Skip (no alert)
└── Not blocked?
├── Known safe / user-ignored? → Skip
└── Unknown → AI Analysis
├── Safe/tracking? → Skip
└── Malicious? → Discord Alert
├── [Quarantine] → Block IP
└── [Ignore] → Add to safe list
```
## 🔇 降噪
一个对所有事情都发出警报的 SIEM 等于没有警报。自定义抑制规则集:
| 事件 | 操作 |
|-------|--------|
| pfSense 单次封禁 | 已抑制 |
| AdGuard 常规封禁查询 | 已抑制 |
| PAM 会话开启/关闭 | 已抑制 |
| 受信任用户的 Sudo | 已抑制 |
| 来自内部 IP 的 SSH | 已抑制 |
| **SSH 暴力破解(5 次以上失败)** | **警报 — 级别 10** |
| **pfSense 攻击模式(20 次以上封禁/分钟)** | **警报 — 级别 8+** |
## 📁 仓库结构
```
wazuh-ai-siem/
├── integrations/ # AI-powered Wazuh→Discord integrations (DNS, pfSense, SSH)
├── services/ # Threat Hunter (NL search) + MCP server + systemd units
├── rules/ # Custom detection & noise-reduction rules (pfSense, AdGuard)
├── decoders/ # Custom log decoders (AdGuard)
├── scripts/ # Setup, pfSense quarantine, integration tests
├── n8n-workflows/ # Quarantine / unquarantine / ignore automation (importable JSON)
├── config/ # Example ossec.conf
├── docs/ # Setup guide + troubleshooting
└── detection-lab/ # Detection engineering lab: AD attack sims, Sysmon rules,
├── README.md # day-by-day lab journal (GOAD, Kerberoasting, FIM, ...)
├── deployment.md # full infrastructure deployment guide
├── rules/windows/ # custom Sysmon / Mimikatz detection rules
└── active-response/ # universal firewall-drop wrapper + manager config
```
## 🚀 快速开始
```
git clone https://github.com/trac3r00/wazuh-ai-siem.git
cd wazuh-ai-siem
chmod +x scripts/setup.sh
sudo ./scripts/setup.sh
```
**前置条件:** Ubuntu 24.04 上的 Wazuh 4.14+(6+ 核心,16GB+ RAM) · 具有 SSH 访问权限的 pfSense · AdGuard Home · LMStudio 或 Ollama · n8n · Discord webhook
详细说明:[`docs/SETUP.md`](docs/SETUP.md) · [`docs/troubleshooting.md`](docs/troubleshooting.md)
### 配置
创建 `/etc/wazuh-ai-siem.env`:
```
LMSTUDIO_URL=http://YOUR_LLM_HOST:1234/v1/chat/completions
LMSTUDIO_MODEL=qwen/qwen3-14b
DISCORD_WEBHOOK=https://discord.com/api/webhooks/YOUR_WEBHOOK
N8N_BASE_URL=https://n8n.yourserver.com/webhook
PFSENSE_HOST=YOUR_PFSENSE_IP
PFSENSE_SSH_PORT=22
PFSENSE_SSH_KEY=/etc/ssh/pfsense_automation
WAZUH_API_USER=wazuh-wui
WAZUH_API_PASS=your_api_password
```
## 🧪 测试
```
# 测试 AI DNS 集成
sudo python3 /var/ossec/integrations/custom-ai-dns-discord.py /tmp/test.alert
# 测试自然语言威胁狩猎
curl -X POST http://localhost:8080/query \
-H "Content-Type: application/json" \
-d '{"question": "Were there any SSH attacks?", "hours": 24}'
# 测试 MCP server
curl http://localhost:8081/alerts/summary
# 完整集成测试套件
./scripts/test-integrations.sh
```
## 📄 许可证
MIT — 查看 [许可证](LICENSE)。
## 🙏 致谢
[Wazuh](https://wazuh.com/) · [GOAD](https://github.com/Orange-Cyberdefense/GOAD) · [Atomic Red Team](https://github.com/redcanaryco/atomic-red-team) · [LMStudio](https://lmstudio.ai/) · [n8n](https://n8n.io/) · [pfSense](https://www.pfsense.org/) · [AdGuard Home](https://adguard.com/en/adguard-home/overview.html) · [SwiftOnSecurity Sysmon config](https://github.com/SwiftOnSecurity/sysmon-config)
*由 [@trac3r00](https://github.com/trac3r00) 构建并运营 —— 本仓库中的每个检测都是针对真实的攻击执行进行验证的,而不仅仅是理论。*
标签:AMSI绕过, DLL 劫持, Modbus, SOAR, Wazuh, 大语言模型, 威胁检测, 安全运营, 扫描框架, 模拟器, 逆向工具