dimasqiramadhani/dns-tunneling-detection

GitHub: dimasqiramadhani/dns-tunneling-detection

基于Wazuh平台构建的DNS隧道检测实验环境,实现了从流量捕获、字段解析到分层告警的完整检测工程管道。

Stars: 0 | Forks: 0

# 🔍 Wazuh DNS 隧道检测实验 ## 📋 简短描述 本项目演示了如何使用 **Wazuh**、`tcpdump`、自定义日志收集和检测工程,从零开始构建 DNS 隧道检测管道。它涵盖了从在 Linux 端点上捕获原始 DNS 流量到在 Wazuh Dashboard 中触发警报的所有内容——使其成为一个完整的、可放入作品集的实验项目,主要侧重于**检测工程**和**SIEM 定制化**。 ## 🏗️ 实验概述 | 组件 | 角色 | |-------------------|-----------------------------------------------------------| | Wazuh Server | SIEM 核心 — 规则引擎,警报生成,仪表板 | | Ubuntu Endpoint | 安装了 Wazuh Agent 的受监控主机 | | tcpdump | 捕获 53 端口上的 DNS 数据包 | | dns_monitor.sh | 运行 tcpdump 并将输出通过管道传递到日志文件的 Bash 脚本 | | systemd | 保持 dns-monitor 运行的服务管理器 | | Wazuh Agent | 读取 `/var/log/dns_monitoring.log` 并发送给管理器 | | 自定义 Decoder | 解析 DNS 日志字段:query, type, src/dst IP | | 自定义 Rules | 通过字段级条件检测隧道指标 | | Wazuh Dashboard | 可视化和过滤 DNS 隧道警报 | ## 🧭 架构图 ``` flowchart TD A[Ubuntu Endpoint] -->|tcpdump port 53| B[dns_monitoring.log] B -->|localfile config| C[Wazuh Agent] C -->|encrypted log shipping| D[Wazuh Manager] D -->|decoder parsing| E[Custom Decoder: dns_monitor.xml] E -->|field extraction| F[Custom Rules: dns_monitor_rules.xml] F -->|alert generation| G[Wazuh Dashboard] G -->|filter rule.groups: dns_tunneling| H[Analyst Review] ``` ## 🎯 检测覆盖范围 | Rule ID | 指标 | 严重程度 | |---------|---------------------------------------|----------| | 101200 | 基础 DNS 监控事件 | 低 | | 101201 | 编码 / 高熵查询 | 中 | | 101202 | 深层子域结构 | 中 | | 101203 | 可疑 DNS 记录类型 | 中 | | 101204 | 编码查询 + 可疑类型 | 高 | | 101205 | 深层子域 + 可疑类型 | 高 | | 101206 | 编码查询 + 深层子域 | 高 | | 101207 | 完整隧道指标组合 | 严重 | ## 📁 仓库结构 ``` dns-tunneling-lab/ ├── README.md ├── LICENSE ├── .gitignore ├── docs/ │ ├── 01-overview.md │ ├── 02-lab-architecture.md │ ├── 03-dns-tunneling-concept.md │ ├── 04-installation-and-configuration.md │ ├── 05-wazuh-decoder-and-rules.md │ ├── 06-attack-simulation.md │ ├── 07-detection-result-and-analysis.md │ ├── 08-troubleshooting.md │ └── 09-improvement-ideas.md ├── scripts/ │ └── dns_monitor.sh ├── wazuh/ │ ├── decoders/ │ │ └── dns_monitor.xml │ └── rules/ │ └── dns_monitor_rules.xml ├── systemd/ │ └── dns-monitor.service ├── logrotate/ │ └── dns-monitor └── screenshots/ └── README.md ``` ## ⚙️ 要求 - Wazuh Server (v4.x) — OVA 或自托管 - 安装了 Wazuh Agent 的 Ubuntu 20.04 / 22.04 端点 - 端点上已安装 `tcpdump` - 受监控主机上的 root 或 sudo 权限 - 基本熟悉 Wazuh Manager 配置 ## 🚀 快速开始 ### 1. 部署 DNS 监控脚本 ``` # 复制脚本到 endpoint sudo cp scripts/dns_monitor.sh /usr/local/bin/dns_monitor.sh sudo chmod +x /usr/local/bin/dns_monitor.sh # 创建 log 目录 sudo touch /var/log/dns_monitoring.log sudo chmod 644 /var/log/dns_monitoring.log ``` ### 2. 设置 systemd 服务 ``` sudo cp systemd/dns-monitor.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable dns-monitor sudo systemctl start dns-monitor ``` ### 3. 配置 Wazuh Agent 在端点上的 `/var/ossec/etc/ossec.conf` 中添加: ``` syslog /var/log/dns_monitoring.log ``` 重启 agent: ``` sudo systemctl restart wazuh-agent ``` ### 4. 部署自定义 Decoder 和 Rules ``` # 在 Wazuh Manager 上 sudo cp wazuh/decoders/dns_monitor.xml /var/ossec/etc/decoders/ sudo cp wazuh/rules/dns_monitor_rules.xml /var/ossec/etc/rules/ # 重载 ruleset sudo /var/ossec/bin/wazuh-logtest -V sudo systemctl restart wazuh-manager ``` ## 🧪 测试 从端点运行模拟的 DNS 隧道查询: ``` # 模拟编码 subdomain 查询 dig $(python3 -c "import base64; print(base64.b64encode(b'testpayload').decode())").a.b.c.d.example.com TXT # 深度 subdomain 模拟 dig level1.level2.level3.level4.level5.example.com A ``` ## 📊 检测结果 成功检测后,警报将出现在 Wazuh Dashboard 中,包含: - `rule.id`: 101201–101207 - `rule.groups`: `dns_tunneling` - 字段: `dns_query`、`dns_type`、`src_ip`、`dst_ip` 在仪表板中过滤: `rule.groups: dns_tunneling` ## 🖼️ 截图 查看 [`screenshots/README.md`](screenshots/README.md) 以获取为您的作品集捕获的完整证据截图列表。 ## 🗺️ MITRE ATT&CK 映射 | 技术 | ID | 描述 | |---------------------------------|-----------|-------------------------------------------| | Application Layer Protocol: DNS | T1071.004 | 使用 DNS 作为隐蔽通信通道 | | Exfiltration Over C2 Channel | T1041 | 通过 DNS 查询传出数据 | | Fallback Channels | T1008 | DNS 隧道作为备用 C2 路径 | | Ingress Tool Transfer | T1105 | 通过 DNS 隧道拉取工具 | ## 🧠 经验总结 - 如何在 Linux 上使用 `tcpdump` + systemd 构建自定义日志收集管道 - 使用基于正则表达式的字段提取编写 Wazuh decoder - 设计具有复合条件的检测规则以实现更高置信度的警报 - 了解 DNS 隧道在日志中的表现形式以及如何调整规则以最大限度地减少误报 - 将检测逻辑映射到 MITRE ATT&CK 框架以实现结构化的威胁覆盖 ## 📚 参考 - [Wazuh 博客:使用 Wazuh 检测 DNS 隧道攻击](https://wazuh.com/blog/detecting-dns-tunneling-attacks-with-wazuh/) - [MITRE ATT&CK T1071.004](https://attack.mitre.org/techniques/T1071/004/) - [Wazuh 文档:自定义 Decoder](https://documentation.wazuh.com/current/user-manual/ruleset/custom.html) - [DNS 隧道概述 - SANS](https://www.sans.org/reading-room/whitepapers/dns/) ## ⚖️ 免责声明 本项目仅供**教育和作品展示目的**。所有攻击模拟均在一个受控的、隔离的实验环境中进行。此处演示的技术绝不应用于您不拥有或未获得明确书面授权进行测试的系统。 ## 👤 作者 **Dimas Qi Ramadhani** — 网络安全工程师 | 红队 & 检测工程 GitHub: [@dimasqiramadhani](https://github.com/dimasqiramadhani)
标签:AMSI绕过, Cloudflare, DNS安全, DNS隧道, IP 地址批量处理, MITRE ATT&CK, SIEM定制化, Wazuh, 包捕获, 威胁检测, 安全实验室, 安全运营, 应用安全, 扫描框架, 流量监控, 端口53, 网络安全, 自定义规则, 自定义解码器, 隐私保护