jmoreira01/suricata-ids-integration

GitHub: jmoreira01/suricata-ids-integration

将 Suricata 网络入侵检测系统与 Wazuh SIEM 深度集成,实现集中告警关联与基于签名匹配的自动化威胁响应能力。

Stars: 0 | Forks: 0

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Wazuh](https://img.shields.io/badge/Wazuh-SIEM-00A6D6)](https://wazuh.com/) [![Suricata](https://img.shields.io/badge/Suricata-IDS-EF3B2D)](https://suricata.io/) # Wazuh SIEM — Suricata IDS 集成 ## 目录 - [概述](#overview) - [架构](#architecture) - [技术栈](#technologies) - [安装与配置](#installation--configuration) - [攻击模拟与检测结果](#attack-simulations--detection-results) - [主动响应 — 自动化 NMAP 阻断](#active-response--automated-nmap-blocking) - [MITRE ATT&CK 映射](#mitre-attck-mapping) - [故障排除](#troubleshooting) - [核心学习与修正](#key-learnings--corrections) - [参考资料](#references) ## 概述 本项目使用 Suricata 实现了一套**网络入侵检测系统 (NIDS)**,并与 Wazuh SIEM 完全集成,以实现集中的安全监控、告警和自动化威胁响应。 该集成支持实时检测基于网络的攻击,包括端口扫描、漏洞侦察和拒绝服务攻击尝试,告警信息经关联后将与基于主机的检测结果一起显示在 Wazuh 仪表板中。 ### 核心能力 - 通过 Suricata 在受监控主机上进行**实时网络流量分析** - 通过 Wazuh SIEM 仪表板进行**集中告警关联** - 使用由 Suricata 告警触发的 Wazuh 主动响应实现**自动化 IP 阻断** - 结合 NIDS (Suricata) 和 HIDS (Wazuh Agent) 的**多向量检测** - 通过 `suricata-update` 自动更新的 **Emerging Threats 规则集** ### 已实现的 IDS 类型 | 类型 | 工具 | 功能 | |------|------|----------| | **NIDS** (基于网络) | Suricata | 监控网络流量,分析数据包和数据流 | | **HIDS** (基于主机) | Wazuh Agent | 监控主机活动 — 日志、文件完整性、进程 | ## 架构 ``` ┌─────────────────────────┐ ┌────────────────────────────────┐ ┌─────────────────────────┐ │ Kali Linux │ │ Ubuntu 22.04 (Victim) │ │ Wazuh Server │ │ (Attacker) │────▶│ Suricata + Wazuh Agent │────▶│ Manager + Dashboard │ │ │ │ │ │ │ │ Tools: │ │ Services: │ │ Services: │ │ ├─ NMAP (recon) │ │ ├─ Suricata 8.0.3 (NIDS) │ │ ├─ wazuh-manager │ │ ├─ GoldenEye (DoS) │ │ ├─ Apache2 (web server) │ │ ├─ wazuh-indexer │ │ └─ Hydra (brute force) │ │ ├─ Wazuh Agent │ │ └─ wazuh-dashboard │ │ │ │ └─ YARA (malware detection) │ │ │ └─────────────────────────┘ └────────────────────────────────┘ └─────────────────────────┘ Attack Traffic ──────────▶ Suricata captures & alerts ────────▶ Wazuh correlates & responds ``` ### 数据流 1. **攻击者** 向受害机发送恶意流量 2. **Suricata** 捕获网络接口上的数据包,与 ET Open 签名进行匹配,并将告警记录到 `/var/log/suricata/eve.json` 3. **Wazuh Agent** 读取 Suricata JSON 日志并将事件转发给 Wazuh Server 4. **Wazuh Manager** 处理告警,应用规则,并在配置后触发主动响应 5. **Wazuh Dashboard** 显示关联后的告警以供分析和调查 ## 技术栈 | 组件 | 版本 | 用途 | |-----------|---------|---------| | **Suricata** | 8.0.3 | 网络入侵检测系统 | | **Wazuh** | 4.x | SIEM — 安全信息与事件管理 | | **Ubuntu** | 22.04 LTS | 受害机/Agent 操作系统 | | **Kali Linux** | 最新版 | 攻击模拟平台 | | **Apache2** | 2.4.x | Web 服务器 (DoS 目标) | | **NMAP** | 7.x | 网络侦察工具 | | **GoldenEye** | 最新版 | HTTP DoS 模拟工具 | | **ET Open Rules** | 最新版 | Emerging Threats 签名数据库 | ## 安装与配置 ### 前置条件 - Wazuh Server 已安装并正常运行 - Wazuh Agent 已在受害机上安装并连接 - Apache2 已在受害机上安装并运行 (进行 DoS 测试所需) - Kali Linux 虚拟机可用于攻击模拟 ### 步骤 1 — 安装 Suricata (受害机) ``` sudo add-apt-repository -y ppa:oisf/suricata-stable sudo apt-get update sudo apt-get install suricata -y ``` 验证安装: ``` suricata -V ``` ### 步骤 2 — 下载与更新规则 使用 `suricata-update` 进行与已安装版本兼容的自动规则管理: ``` sudo suricata-update ``` 规则被安装到 `/var/lib/suricata/rules/`。 ### 步骤 3 — 配置 Suricata 识别网络接口: ``` ip a ``` 编辑配置文件: ``` sudo nano /etc/suricata/suricata.yaml ``` 需要配置的关键设置: ``` # 网络变量 HOME_NET: "" EXTERNAL_NET: "any" # Rule 路径 (suricata-update 位置) default-rule-path: /var/lib/suricata/rules rule-files: - "*.rules" # Capture interface af-packet: - interface: enp0s3 # Adjust to your interface # 统计信息 stats: enabled: yes ``` 验证并重启: ``` sudo suricata -T -c /etc/suricata/suricata.yaml sudo systemctl restart suricata sudo systemctl status suricata ``` ### 步骤 4 — 集成 Wazuh Agent 在受害机上编辑 Wazuh Agent 配置: ``` sudo nano /var/ossec/etc/ossec.conf ``` 在最后的 `` 之前添加: ``` json /var/log/suricata/eve.json ``` 重启 Agent: ``` sudo systemctl restart wazuh-agent ``` ## 攻击模拟与检测结果 ### 测试 1 — NMAP 侦察 **攻击命令 (来自 Kali):** ``` nmap -sS --script=vuln ``` **在 Wazuh 中的检测结果:** | 告警描述 | 规则 ID | 级别 | 数量 | |-------------------|---------|-------|-------| | Suricata: ET SCAN Nmap Scripting Engine User-Agent Detected | 86601 | 3 | 3,500+ | | Web 服务器 400 错误码 | 31101 | 5 | 多次 | | 来自同一源 IP 的多次 Web 服务器 400 错误码 | 31151 | 10 | 多次 | **生成的告警总数:** 3,539 次 - **结果:** Suricata 成功检测到 NMAP 扫描,并且 Wazuh 关联了来自网络 和应用 层的多种告警类型。 ### 测试 2 — GoldenEye DoS 攻击 **攻击命令 (来自 Kali):** ``` git clone https://github.com/jseidl/GoldenEye.git cd GoldenEye python3 goldeneye.py http:// ``` **在 Wazuh 中的检测结果:** | 告警描述 | 规则 ID | 级别 | 意义 | |-------------------|---------|-------|--------------| | Agent 事件队列已满 90% | 202 | 7 | Agent 因事件洪水而过载 | | Agent 事件队列恢复正常负载 | 205 | 3 | 攻击停止后恢复 | **GoldenEye 输出:** 6,202 次打击,并显示“Server may be DOWN!”,表明服务已成功降级。 ⚠️ **结果:** Suricata 没有直接检测到 GoldenEye DoS 模式 (ET Open 规则中没有特定签名)。但是,**间接指标**清晰可见: - Agent 事件队列饱和 (90% 满) - Apache 日志中出现大量 HTTP 错误 - 来自单一源 IP 的异常连接量 - Web 服务器性能下降 ## 主动响应 — 自动化 NMAP 阻断 ### 配置 (Wazuh Server) 当 Suricata 检测到 NMAP 扫描时,主动响应机制会自动阻断攻击者的 IP。 **添加到 Wazuh Server 的 `ossec.conf` 中:** ``` firewall-drop firewall-drop yes no firewall-drop local 86601 300 ``` ### 工作原理 ``` NMAP Scan → Suricata Alert (Rule 86601) → Wazuh Agent forwards to Manager → Manager triggers Active Response → firewall-drop script executes on Agent → iptables DROP rule added for attacker IP → Blocked for 300 seconds ``` ### 参数 | 参数 | 值 | 描述 | |-----------|-------|-------------| | `command` | firewall-drop | 为源 IP 添加 iptables DROP 规则 | | `location` | local | 在检测到攻击的 Agent 上执行 | | `rules_id` | 86601 | Suricata: ET SCAN Nmap Scripting Engine Detected | | `timeout` | 300 | 阻断持续时间,以秒为单位 (5 分钟) | ### 验证 触发 NMAP 扫描后,在受害机上验证阻断情况: ``` sudo iptables -L -n | grep ``` 预期输出: ``` DROP all -- 0.0.0.0/0 ``` 该规则将在超时时间过后自动移除。 ## MITRE ATT&CK 映射 | 战术 | 技术 | ID | 检测方法 | |--------|-----------|-----|-----------------| | **侦察** | 主动扫描:漏洞扫描 | T1595.002 | Suricata NMAP 检测 (规则 86601) | | **侦察** | 主动扫描:IP 块扫描 | T1595.001 | Suricata 网络监控 | | **影响** | 端点拒绝服务 | T1499 | Agent 队列饱和,HTTP 错误关联 | | **影响** | 网络拒绝服务 | T1498 | 流量异常检测 | ## 故障排除 ### Suricata 无法启动 ``` # 验证配置 sudo suricata -T -c /etc/suricata/suricata.yaml # 检查日志 sudo journalctl -u suricata --no-pager | tail -30 ``` 常见原因:YAML 缩进错误、接口名称不正确、规则路径无效。 ### 配置主动响应后 Wazuh Manager 失败 ``` sudo journalctl -u wazuh-manager --no-pager | tail -20 ``` 常见原因:使用了 `` 而不是 ``。 ### Agent 无法连接到 Server ``` # 检查配置的服务器地址 grep "
" /var/ossec/etc/ossec.conf # 验证连接 ss -an | grep 1514 ``` 常见原因:在不同环境之间服务器 IP 发生了变化 (例如,学校与家庭网络)。 ### Suricata 未生成告警 ``` # 检查 Suricata 是否正在捕获流量 tail -f /var/log/suricata/eve.json # 验证接口配置 grep "interface" /etc/suricata/suricata.yaml ip a ``` ### 主动响应阻断了错误的 IP (例如,Server IP) ``` # 查看所有 iptables 规则 sudo iptables -L -n --line-numbers # 移除特定 block sudo iptables -D INPUT -s -j DROP # 紧急情况:清空所有规则 sudo iptables -F ``` ## 核心学习与修正 在实施过程中,发现并修正了原始实验室文档中的几个问题: | # | 原始问题 | 应用的修正 | |---|---------------|-------------------| | 1 | 针对 Suricata 6.0.8 的手动规则下载 (版本不匹配) | 使用 `suricata-update` 自动获取版本兼容的规则 | | 2 | 对规则文件使用 `chmod 777` (安全风险) | `suricata-update` 的默认权限是正确的 | | 3 | 在使用 `suricata-update` 时规则路径 `/etc/suricata/rules/` 不正确 | 正确路径:`/var/lib/suricata/rules/` | | 4 | nmap 命令中的长划线字符 (`–` 与 `--`) | 使用双连字符:`--script=vuln` | | 5 | Apache2 未列为 GoldenEye 的前置条件 | 已将其添加为明确的前置条件 | | 6 | 配置文件路径未指定 | 已明确记录:`/etc/suricata/suricata.yaml` | | 7 | `add-apt-repository` 缺少 `-y` 标志 | 为无头/非 GUI 环境添加了 `-y` | | 8 | 主动响应中的 `` 标签 (无效) | 更正为 `` (复数) | ## 核心命令参考 ``` # --- SURICATA --- suricata -V # Check version sudo suricata-update # Update rules sudo suricata -T -c /etc/suricata/suricata.yaml # Validate config sudo systemctl restart suricata # Restart service tail -f /var/log/suricata/eve.json # Monitor alerts live # --- WAZUH AGENT --- sudo systemctl restart wazuh-agent # Restart agent grep "
" /var/ossec/etc/ossec.conf # Check server IP # --- WAZUH SERVER --- sudo systemctl restart wazuh-manager # Restart manager /var/ossec/bin/agent_control -l # List connected agents # --- ACTIVE RESPONSE --- sudo iptables -L -n | grep # Check if IP is blocked sudo iptables -D INPUT -s -j DROP # Manual unblock # --- ATTACK SIMULATION (Kali) --- nmap -sS --script=vuln # Vulnerability scan python3 goldeneye.py http:// # HTTP DoS ``` ## 参考资料 - [Wazuh 文档 — Suricata 集成](https://documentation.wazuh.com/current/proof-of-concept-guide/integrate-network-ids-suricata.html) - [Suricata 官方文档](https://docs.suricata.io/) - [Emerging Threats Open 规则](https://rules.emergingthreats.net/) - [MITRE ATT&CK 框架](https://attack.mitre.org/) - [Suricata-Update 文档](https://suricata-update.readthedocs.io/) ## 许可证 本项目基于 MIT 许可证授权 — 详情请参见 [LICENSE](LICENSE) 文件。 *所有攻击模拟均在隔离的实验室环境中进行。*
标签:CISA项目, Cloudflare, EDR, HIDS, HTTP/HTTPS抓包, IP 地址批量处理, IP封禁, Linux运维, Metaprompt, MITRE ATT&CK, NIDS, Suricata, Wazuh, 入侵检测系统, 分布式系统, 响应大小分析, 威胁情报, 安全仪表盘, 安全数据湖, 安全规则更新, 安全运营, 安全防御体系, 容器化, 密码管理, 开发者工具, 异常流量, 态势感知, 扫描框架, 拒绝服务攻击, 插件系统, 无线安全, 日志关联, 现代安全运营, 端口扫描检测, 网络安全, 网络安全审计, 脆弱性评估, 自动化响应, 蜜罐, 证书利用, 配置错误, 隐私保护