JhonnyValdivieso/suricata-ids-rule-tuning
GitHub: JhonnyValdivieso/suricata-ids-rule-tuning
基于 Docker 的 Suricata IDS 规则调优实验室,通过模拟攻击场景演示如何消除误报和冗余告警,实现高保真的入侵检测告警输出。
Stars: 0 | Forks: 0
# 🛡️ Suricata IDS:规则调优与降噪实验室
[](https://suricata.io/)
[](https://www.docker.com/)
[](https://opensource.org/licenses/MIT)
[]()
一个注重实践的网络入侵检测系统 (NIDS) 实验室,专注于设计自定义的 Suricata 检测规则,分析原始遥测数据,并应用 **Alert Tuning** 技术来消除误报和警报疲劳,同时不影响安全覆盖范围。
## 📌 执行摘要
入侵检测系统中大量的噪音和未优化的签名会导致 **警报疲劳**,从而掩盖了安全运营中心 (SOC) 内部的关键安全事件。
本项目模拟了一个受控的容器化环境,在此环境中针对自定义签名发起了网络攻击向量(ICMP 发现、TCP SYN 扫描和 Web 应用程序 SQL Injection)。通过迭代优化(利用速率限制阈值、双向流过滤和特定的 ICMP 类型),成功将日志量从冗余的多数据包流减少为 **精确、高保真的警报**。
## 🏗️ 架构与组件概述
该实验室在运行于原生 Windows 主机上的轻量级 Docker 隔离环境中运行:
```
graph TD
A[Automated Test Suite
test_rules.py] --> B1[Alpine ICMP] A --> B2[Nmap SYN Scan] A --> B3[Wget SQLi] B1 -->|Traffic Generation| C[Suricata NIDS Engine
rules/local.rules] B2 -->|Traffic Generation| C B3 -->|Traffic Generation| C C -->|Ingestion & Filtering| D[logs/fast.log
Normalized Stream] ``` ### Stack 组件: * **检测引擎:** 作为原生 Docker 容器运行的 Suricata NIDS。 * **编排:** 使用 `docker-compose` 为规则和日志映射卷挂载。 * **测试自动化:** 自定义 Python 脚本 (`test_rules.py`),执行受控的 `docker run` 触发器以测试网络接口。 * **日志检查:** 使用 PowerShell 实时日志监控 (`Get-Content -Wait`)。 ## 📝 签名工程 (`rules/local.rules`) 定制的签名集解决了三个不同的检测层,并进行了优化以消除冗余信息: ``` # 1. ICMP 网络发现检测 # 仅捕获出站 ICMP Echo Requests (Type 8),过滤掉返回的回复。 alert icmp any any -> any any (msg:"[IDS ALERT] ICMP Network Discovery Detected"; itype:8; threshold: type limit, track by_src, count 1, seconds 30; classtype:not-suspicious; sid:1000001; rev:4;) # 2. Nmap SYN 端口扫描检测 # 由快速的 SYN flag 序列触发,忽略来自本地 host 接口的单包 TCP 握手。 alert tcp any any -> any !2376 (msg:"[IDS ALERT] Nmap SYN Port Scan Detected"; flags:S; threshold: type limit, track by_src, count 1, seconds 10; classtype:attempted-recon; sid:1000002; rev:6;) # 3. SQL Injection 攻击检测 # 检测 HTTP TCP 流上的 'UNION' payloads,限制为每个会话突发最多 1 个告警。 alert tcp any any -> any any (msg:"[IDS ALERT] SQL Injection Attempt Detected"; flow:to_server,established; content:"UNION"; nocase; threshold: type limit, track by_src, count 1, seconds 10; classtype:web-application-attack; sid:1000003; rev:11;) ``` ## ⚡ 警报调优与降噪方法 在初始执行期间,由于多数据包 HTTP TCP 负载、ICMP 双向回复和后台接口活动,原始检测规则生成了冗余的日志条目。 | 签名 ID | 目标事件 | 初始问题 | 应用的调优策略 | 结果 | |---|---|---|---|---| | SID: 1000001 | ICMP Ping | 每次 ping 触发两次(请求 + 回复)。 | 添加 `itype:8` 以隔离出站请求。 | 每次 ping 序列仅产生单个警报。 | | SID: 1000002 | Nmap SYN 扫描 | 被正常的出站连接触发。 | 集成了 `threshold: type limit, rate control`。 | 抑制了接口冗余信息。 | | SID: 1000003 | SQL Injection | 每次单独的 wget 请求生成 6 个以上的重复日志。 | 应用了 `track by_src, count 1, seconds 10`。 | 减少为 1 个高优先级警报。 | ## 🧪 验证与证据 ### 1. 自动化测试套件 该实验室使用 `test_rules.py` 按顺序触发所有 3 个攻击向量: ``` python test_rules.py ``` ### 2. 高保真警报遥测 检查 `logs/fast.log` 展示了干净的 1:1 事件映射,没有重复的噪音: ``` 07/30/2026-00:40:30.401620 [**] [1:1000001:4] [IDS ALERT] ICMP Network Discovery Detected [**] [Classification: Not Suspicious Traffic] [Priority: 3] {ICMP} 192.168.65.3:8 -> 1.1.1.1:0 07/30/2026-00:40:35.006630 [**] [1:1000002:6] [IDS ALERT] Nmap SYN Port Scan Detected [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.65.3:41423 -> 1.1.1.1:443 07/30/2026-00:40:39.814250 [**] [1:1000003:11] [IDS ALERT] SQL Injection Attempt Detected [**] [Classification: Web Application Attack] [Priority: 1] {TCP} 192.168.65.1:58641 -> 192.168.65.7:2376 ``` ## 🗂️ 仓库结构 ``` suricata-ids-rule-tuning/ ├── docker-compose.yml # Suricata container orchestration ├── rules/ │ └── local.rules # Custom tuned Suricata signatures ├── logs/ │ └── fast.log # NIDS alert log output ├── test_rules.py # Automated attack simulation script └── README.md # Project documentation ``` ## 🧠 关键技术要点 - **SOC 效率:** 减轻了日志膨胀,证明了适当的阈值控制如何直接改善 SIEM 的摄取成本和分析师的响应速度。 - **签名设计:** 掌握了 Snort/Suricata 语法选项(`itype`、`flags`、`nocase`、`classtype`、`threshold`)。 - **容器安全:** 管理 Docker 网络隔离和主机卷绑定,以进行实时遥测分析。 ## 许可证与法律免责声明 ### 许可证 本项目基于 MIT 许可证授权 - 有关详细信息,请参阅 [LICENSE](LICENSE) 文件。您可以出于教育和防御性安全目的自由使用、修改和分发这些材料。 ### 法律与教育免责声明
test_rules.py] --> B1[Alpine ICMP] A --> B2[Nmap SYN Scan] A --> B3[Wget SQLi] B1 -->|Traffic Generation| C[Suricata NIDS Engine
rules/local.rules] B2 -->|Traffic Generation| C B3 -->|Traffic Generation| C C -->|Ingestion & Filtering| D[logs/fast.log
Normalized Stream] ``` ### Stack 组件: * **检测引擎:** 作为原生 Docker 容器运行的 Suricata NIDS。 * **编排:** 使用 `docker-compose` 为规则和日志映射卷挂载。 * **测试自动化:** 自定义 Python 脚本 (`test_rules.py`),执行受控的 `docker run` 触发器以测试网络接口。 * **日志检查:** 使用 PowerShell 实时日志监控 (`Get-Content -Wait`)。 ## 📝 签名工程 (`rules/local.rules`) 定制的签名集解决了三个不同的检测层,并进行了优化以消除冗余信息: ``` # 1. ICMP 网络发现检测 # 仅捕获出站 ICMP Echo Requests (Type 8),过滤掉返回的回复。 alert icmp any any -> any any (msg:"[IDS ALERT] ICMP Network Discovery Detected"; itype:8; threshold: type limit, track by_src, count 1, seconds 30; classtype:not-suspicious; sid:1000001; rev:4;) # 2. Nmap SYN 端口扫描检测 # 由快速的 SYN flag 序列触发,忽略来自本地 host 接口的单包 TCP 握手。 alert tcp any any -> any !2376 (msg:"[IDS ALERT] Nmap SYN Port Scan Detected"; flags:S; threshold: type limit, track by_src, count 1, seconds 10; classtype:attempted-recon; sid:1000002; rev:6;) # 3. SQL Injection 攻击检测 # 检测 HTTP TCP 流上的 'UNION' payloads,限制为每个会话突发最多 1 个告警。 alert tcp any any -> any any (msg:"[IDS ALERT] SQL Injection Attempt Detected"; flow:to_server,established; content:"UNION"; nocase; threshold: type limit, track by_src, count 1, seconds 10; classtype:web-application-attack; sid:1000003; rev:11;) ``` ## ⚡ 警报调优与降噪方法 在初始执行期间,由于多数据包 HTTP TCP 负载、ICMP 双向回复和后台接口活动,原始检测规则生成了冗余的日志条目。 | 签名 ID | 目标事件 | 初始问题 | 应用的调优策略 | 结果 | |---|---|---|---|---| | SID: 1000001 | ICMP Ping | 每次 ping 触发两次(请求 + 回复)。 | 添加 `itype:8` 以隔离出站请求。 | 每次 ping 序列仅产生单个警报。 | | SID: 1000002 | Nmap SYN 扫描 | 被正常的出站连接触发。 | 集成了 `threshold: type limit, rate control`。 | 抑制了接口冗余信息。 | | SID: 1000003 | SQL Injection | 每次单独的 wget 请求生成 6 个以上的重复日志。 | 应用了 `track by_src, count 1, seconds 10`。 | 减少为 1 个高优先级警报。 | ## 🧪 验证与证据 ### 1. 自动化测试套件 该实验室使用 `test_rules.py` 按顺序触发所有 3 个攻击向量: ``` python test_rules.py ``` ### 2. 高保真警报遥测 检查 `logs/fast.log` 展示了干净的 1:1 事件映射,没有重复的噪音: ``` 07/30/2026-00:40:30.401620 [**] [1:1000001:4] [IDS ALERT] ICMP Network Discovery Detected [**] [Classification: Not Suspicious Traffic] [Priority: 3] {ICMP} 192.168.65.3:8 -> 1.1.1.1:0 07/30/2026-00:40:35.006630 [**] [1:1000002:6] [IDS ALERT] Nmap SYN Port Scan Detected [**] [Classification: Attempted Information Leak] [Priority: 2] {TCP} 192.168.65.3:41423 -> 1.1.1.1:443 07/30/2026-00:40:39.814250 [**] [1:1000003:11] [IDS ALERT] SQL Injection Attempt Detected [**] [Classification: Web Application Attack] [Priority: 1] {TCP} 192.168.65.1:58641 -> 192.168.65.7:2376 ``` ## 🗂️ 仓库结构 ``` suricata-ids-rule-tuning/ ├── docker-compose.yml # Suricata container orchestration ├── rules/ │ └── local.rules # Custom tuned Suricata signatures ├── logs/ │ └── fast.log # NIDS alert log output ├── test_rules.py # Automated attack simulation script └── README.md # Project documentation ``` ## 🧠 关键技术要点 - **SOC 效率:** 减轻了日志膨胀,证明了适当的阈值控制如何直接改善 SIEM 的摄取成本和分析师的响应速度。 - **签名设计:** 掌握了 Snort/Suricata 语法选项(`itype`、`flags`、`nocase`、`classtype`、`threshold`)。 - **容器安全:** 管理 Docker 网络隔离和主机卷绑定,以进行实时遥测分析。 ## 许可证与法律免责声明 ### 许可证 本项目基于 MIT 许可证授权 - 有关详细信息,请参阅 [LICENSE](LICENSE) 文件。您可以出于教育和防御性安全目的自由使用、修改和分发这些材料。 ### 法律与教育免责声明
标签:AI合规, CISA项目, Docker, Metaprompt, PB级数据处理, Suricata, 入侵检测系统, 安全数据湖, 安全运维, 安全防御评估, 插件系统, 版权保护, 现代安全运营, 网络安全, 请求拦截, 逆向工具, 隐私保护