Leomez17/Zeek-NSM-Threat-Detection

GitHub: Leomez17/Zeek-NSM-Threat-Detection

一个在 Kali Linux 上从源码部署 Zeek 网络安全监控器的实验室项目,演示实时流量捕获、日志分析与基于 Intel Framework 的恶意 IP 威胁检测。

Stars: 0 | Forks: 0

Zeek 网络安全监控器 — 威胁检测实验室 [![Zeek](https://img.shields.io/badge/Zeek-9.0.0--dev.453-0E7C7B?style=flat-square&logo=zeek&logoColor=white)](https://zeek.org) [![Platform](https://img.shields.io/badge/Platform-Kali%20Linux-557C94?style=flat-square&logo=kali-linux&logoColor=white)](https://kali.org) [![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)](LICENSE) [![Status](https://img.shields.io/badge/Status-Completed-22C55E?style=flat-square)]() [![MITRE](https://img.shields.io/badge/MITRE%20ATT%26CK-T1071.001%20%7C%20T1046-red?style=flat-square)](https://attack.mitre.org/) ## 目录 - [概述](#-overview) - [实验室架构](#-lab-architecture) - [工具与技术](#-tools--technologies) - [实验指南](#-lab-walkthrough) - [阶段 1 — 安装依赖](#phase-1--dependency-installation) - [阶段 2 — 克隆与构建](#phase-2--clone--build) - [阶段 3 — 实时 HTTP 捕获](#phase-3--live-http-capture) - [阶段 4 — Intel Framework 检测](#phase-4--intel-framework-detection) - [关键发现](#-key-findings) - [MITRE ATT&CK 映射](#-mitre-attck-mapping) - [日志分析](#-log-analysis) - [挑战与解决](#-challenges--resolutions) - [展示技能](#-skills-demonstrated) - [作者](#-author) ## 概述 本实验室演示了 **Zeek(前身为 Bro)** —— 业界标准的开源网络安全监控器 —— 在 Kali Linux 上从源码编译到使用 **Intel Framework** 进行实时威胁检测的部署过程。 该项目涵盖: - 包含所有子模块的 Zeek 9.0.0 完整源码编译 - 在生产级网络接口上进行实时数据包捕获 - 结构化日志的生成与分析(http.log、conn.log、dns.log、ssl.log 以及其他 10 个日志) - 部署 Zeek Intel Framework 以检测模拟的恶意 IP - 使用 VirtualBox 桥接网络进行跨虚拟机威胁模拟 该实验室直接支持 **NHS Band 7 网络安全分析师** 职位所需的能力,并映射到涉及网络入侵检测、日志管道管理和基于 IOC 的威胁狩猎的真实 SOC 工作流程。 ## 实验室架构 ``` ┌─────────────────────────────────────────────────┐ │ Windows 11 Host Machine │ │ VirtualBox 7.x │ │ │ │ ┌─────────────────┐ ┌──────────────────┐ │ │ │ Kali Linux VM │ │ Ubuntu 24.04 VM │ │ │ │ │ │ │ │ │ │ Zeek 9.0.0 │◄─────│ Simulated │ │ │ │ Apache2 │ HTTP │ Threat Actor │ │ │ │ 192.168.0.57 │ │ 192.168.0.139 │ │ │ │ (NSM Sensor) │ │ (Malicious IP) │ │ │ └─────────────────┘ └──────────────────┘ │ │ │ │ Network: Bridged Adapter │ Subnet: 192.168.0/24 │ └─────────────────────────────────────────────────┘ ``` | 组件 | 详情 | |-----------|--------| | **Kali Linux** | NSM 传感器 — Zeek 9.0.0-dev.453, Apache2, eth0 @ 192.168.0.57 | | **Ubuntu 24.04** | 模拟威胁行为者 — curl HTTP 客户端 @ 192.168.0.139 | | **网络** | VirtualBox 桥接适配器, 192.168.0.0/24 子网 | | **宿主机操作系统** | Windows 11 | ## 工具与技术 | 工具 | 版本 | 用途 | |------|---------|---------| | **Zeek NSM** | 9.0.0-dev.453 | 网络安全监控器 | | **Kali Linux** | Rolling (6.18.12+kali-amd64) | NSM 传感器平台 | | **Ubuntu** | 24.04 LTS | 威胁模拟虚拟机 | | **Apache2** | 2.4.x | HTTP 目标服务器 | | **libpcap** | 1.10.6 | 数据包捕获库 | | **VirtualBox** | 7.x + Extension Pack | 虚拟化 | | **GCC / CMake** | 最新 Kali Rolling 版本 | C++ 构建工具链 | ## 实验指南 ### 阶段 1 — 安装依赖 在 Kali Linux 上安装所有必需的构建和运行时依赖: ``` sudo apt update && sudo apt install -y \ cmake make gcc g++ flex bison \ libpcap-dev libssl-dev zlib1g-dev \ python3 python3-dev swig \ libcaf-dev libmaxminddb-dev libgeoip-dev \ libcurl4-openssl-dev libjsoncpp-dev \ libjemalloc-dev libzstd-dev \ libnode-dev nodejs \ libczmq-dev libzmq3-dev git ``` **关键依赖:** - `libpcap-dev` — 用于实时流量监控的底层数据包捕获 - `libssl-dev` — 用于加密流量分析的 SSL/TLS 支持 - `libcaf-dev` — 用于 Zeek 的 Broker 通信层的 C++ Actor Framework - `libmaxminddb-dev` — 用于 IP 地理位置丰富的 GeoIP 数据库 - `flex / bison` — 用于 Zeek 脚本语言的词法分析器/解析器生成器 ### 阶段 2 — 克隆与构建 **克隆 Zeek 及其所有子模块:** ``` git clone --recursive https://github.com/zeek/zeek.git cd zeek ``` **配置构建:** ``` ./configure # 配置完成 (42.8s) | 构建文件已写入: /home/leonard/zeek/build ``` 启用的构建选项: `Broker: ON` | `ZeroMQ: ON` | `SQLite: ON` | `Kerberos: ON` **编译并安装:** ``` make -j$(nproc) # Utilises all CPU cores — ~20-60 min sudo make install # Installs to /usr/local/zeek/ ``` **添加到 PATH 并验证:** ``` echo 'export PATH=/usr/local/zeek/bin:$PATH' >> ~/.zshrc source ~/.zshrc zeek --version # zeek 版本 9.0.0-dev.453 ``` ### 阶段 3 — 实时 HTTP 捕获 **创建日志目录并启动 Zeek:** ``` mkdir -p ~/zeek-logs cd ~/zeek-logs sudo /usr/local/zeek/bin/zeek -i eth0 local # 正在监听 eth0 ``` **生成 HTTP 流量**(从另一个终端或虚拟机): ``` curl http://192.168.0.57 ``` **停止捕获并检查日志:** ``` # 按 Ctrl+C 停止 Zeek ls ~/zeek-logs/ cat http.log ``` **捕获统计信息:** | 指标 | 数值 | |--------|-------| | 捕获的数据包 | 26,855 | | 丢包率 | 0.56% | | 生成的日志文件 | 14 | | HTTP 200 响应 | 3 | | 丢弃的数据包 | 0% | **生成的日志文件:** ``` capture_loss.log conn.log dns.log files.log http.log notice.log ntp.log ocsp.log packet_filter.log reporter.log ssl.log stats.log telemetry.log weird.log x509.log ``` ### 阶段 4 — Intel Framework 检测 **Zeek Intel Framework** 加载威胁情报指标(IP、域名、哈希值),并在这些指标出现在实时流量中时自动生成警报。 **步骤 1 — 创建 intel 文件**(`malicious-ip.intel`): ``` # 字段必须以制表符分隔 — 空格会导致解析失败 printf '#fields\tindicator\tindicator_type\tmeta.source\n192.168.0.139\tIntel::ADDR\tLocalTest\n' > malicious-ip.intel cat malicious-ip.intel # #fields indicator indicator_type meta.source # 192.168.0.139 Intel::ADDR LocalTest ``` **步骤 2 — 创建 Zeek 脚本**(`load_intel.zeek`): ``` @load policy/frameworks/intel/seen redef Intel::read_files += { "/home/leonard/zeek-logs/malicious-ip.intel" }; event zeek_init() { print "Intel file loaded for malicious IP detection."; } ``` **脚本解析:** - `@load policy/frameworks/intel/seen` — 在所有连接事件上激活指标匹配 - `redef Intel::read_files` — 在 Zeek 启动时注册 intel 文件路径 - 使用绝对路径是因为 `getenv("PWD")` 在 `sudo` 执行上下文中无法解析 **步骤 3 — 运行带有 Intel 脚本的 Zeek:** ``` sudo /usr/local/zeek/bin/zeek -C -i eth0 local ./load_intel.zeek # 正在监听 eth0 # 已加载 Intel 文件用于恶意 IP 检测。 ``` **步骤 4 — 模拟恶意流量**(来自 192.168.0.139 的 Ubuntu 虚拟机): ``` curl http://192.168.0.57 # Repeat 3x ``` **步骤 5 — 检查检测日志:** ``` cat intel.log ``` ## 关键发现 ``` intel.log — Confirmed Detections ───────────────────────────────────────────────────────── seen.indicator 192.168.0.139 ← Malicious IP matched seen.indicator_type Intel::ADDR ← IP address type seen.where Conn::IN_ORIG ← IP was connection initiator seen.node zeek ← Detection by local Zeek instance matched Intel::ADDR ← Indicator type that fired sources LocalTest ← Intel source label ───────────────────────────────────────────────────────── Total detections: 3 connections flagged ``` **`Conn::IN_ORIG`** 是关键字段 — 它确认了恶意 IP 是**发起者**(攻击者)而不是响应者,直接映射到攻击者发起的连接模式。 ## MITRE ATT&CK 映射 | 技术 ID | 名称 | 战术 | 检测方法 | |-------------|------|--------|-----------------| | [T1071.001](https://attack.mitre.org/techniques/T1071/001/) | 应用层协议:Web | 命令与控制 | http.log 中来自 192.168.0.139 的 HTTP 流量 | | [T1046](https://attack.mitre.org/techniques/T1046/) | 网络服务发现 | 发现 | conn.log 中的多个连接 | | [T1595.001](https://attack.mitre.org/techniques/T1595/001/) | 主动扫描:IP 块 | 侦察 | intel.log 中标记的重复源连接 | | [TA0011](https://attack.mitre.org/tactics/TA0011/) | 命令与控制 | 战术 | Intel Framework C2 IP 黑名单执行 | ## 日志分析 ### http.log — 关键字段 | 字段 | 描述 | 观察到的值 | |-------|-------------|----------------| | `id.orig_h` | 源 IP(客户端) | 192.168.0.139 | | `id.resp_h` | 目标 IP | 192.168.0.57 | | `id.resp_p` | 目标端口 | 80 | | `method` | HTTP 方法 | GET | | `uri` | 请求的 URI | / | | `version` | HTTP 版本 | 1.1 | | `status_code` | 响应码 | 200 | ### intel.log — 关键字段 | 字段 | 描述 | |-------|-------------| | `seen.indicator` | 在流量中匹配到的 IOC 值 | | `seen.indicator_type` | Intel 类型常量(`Intel::ADDR`) | | `seen.where` | 匹配位置(`Conn::IN_ORIG` = 攻击者发起) | | `matched` | 触发警报的已确认指标类型 | | `sources` | 情报来源标签(`LocalTest`) | ### 支持的 Intel 指标类型 ``` Intel::ADDR IPv4/IPv6 addresses ← Used in this lab Intel::SUBNET CIDR subnets Intel::URL URLs Intel::SOFTWARE Software signatures Intel::EMAIL Email addresses Intel::DOMAIN Domain names Intel::FILE_HASH MD5/SHA1/SHA256 hashes ``` ## 挑战与解决 | 挑战 | 根本原因 | 解决方案 | |-----------|-----------|------------| | Ubuntu 位于错误的子网 (10.0.2.x) | VirtualBox 默认使用 NAT 适配器 | 在虚拟机网络设置中更改为桥接适配器 | | Kali 虚拟机不稳定 | 同时运行两台虚拟机耗尽了宿主机资源 | 顺序使用虚拟机 — Kali 仅在设置期间运行 | | apt 镜像失败 | 特定软件包的镜像网络错误 | `sudo apt clean && apt update --fix-missing` | | Intel 文件 `cannot open` 错误 | `getenv("PWD")` 在 sudo 上下文中为空 | 替换为硬编码的绝对路径 | | 数据包被校验和丢弃 | VirtualBox 网卡卸载产生了不完整的校验和 | 在 Zeek 命令中添加了 `-C` 标志 | | `intel::read_files` 解析错误 | 大小写敏感 — Zeek 标识符区分大小写 | 更正为 `Intel::read_files`(大写 I) | ## 展示技能 | 能力 | 证据 | |-----------|---------| | **源码级工具部署** | 包含所有子模块的 Zeek C++ 源码编译 | | **网络数据包分析** | 捕获 26,855 个数据包并生成结构化日志 | | **威胁情报整合** | 通过 Intel Framework 在数据包层面应用 IOC | | **日志管道管理** | 14 个准备好供 SIEM 摄取的结构化 TSV 日志 | | **事件证据收集** | 取证级质量的 http.log, conn.log, intel.log | | **MITRE ATT&CK 映射** | 将检测映射到 T1071.001, T1046, T1595.001 | | **SOC 故障排除** | 对虚拟机、网络和工具问题的系统诊断 | | **多虚拟机网络实验室设计** | 带有桥接网络的隔离 2 虚拟机环境 | ## 生产环境扩展(后续步骤) ``` Zeek → Filebeat → Elasticsearch → Kibana ↓ MISP/OpenCTI (automated IOC feeds) ↓ SOAR (Microsoft Sentinel / Splunk SOAR) ↓ Automated Response Playbooks ``` - **Zeek → Filebeat → Elasticsearch** — 集中式日志摄取和长期保留 - **MISP / OpenCTI 集成** — 自动化的 IOC feed 更新至 Intel Framework - **Zeek 集群部署** — 用于高吞吐量网段的 Manager + Worker 架构 - **SOAR 集成** — 由 `intel.log` 警报触发的自动化响应剧本 ## 作者 **Leonard Abanobi** 网络安全顾问与 SOC 分析师 | Amdari [![LinkedIn](https://img.shields.io/badge/LinkedIn-leonard--abanobi-0077B5?style=flat-square&logo=linkedin)](https://linkedin.com/in/leonard-abanobi) [![GitHub](https://img.shields.io/badge/GitHub-Leomez17-181717?style=flat-square&logo=github)](https://github.com/Leomez17) [![Portfolio](https://img.shields.io/badge/Portfolio-leomez17.github.io-0E7C7B?style=flat-square&logo=github-pages)](https://leomez17.github.io/Cybersecurity-Portfolio/) **认证:** CompTIA Security+ | 管理学硕士 (南威尔士大学, 2024) *属于[网络安全作品集](https://leomez17.github.io/Cybersecurity-Portfolio/)的一部分 — 涵盖网络安全监控、威胁狩猎和 SOC 操作的实践实验室。*
标签:Bash脚本, Rootkit, Zeek, 威胁情报, 开发者工具, 插件系统, 网络安全监控, 驱动开发