Trigger-45/DMZ

GitHub: Trigger-45/DMZ

使用 Containerlab 自动化构建包含多防火墙、Suricata IDS、WAF 与 ELK SIEM 的企业 DMZ 网络实验室。

Stars: 3 | Forks: 0

# DMZ – 企业网络实验室 **使用 Containerlab 自动化部署的完整企业网络环境,包含 DMZ 架构、多层防火墙、Suricata IDS 和 ELK SIEM 堆栈。** [![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black)](https://www.linux.org/) [![Docker](https://img.shields.io/badge/Docker-24.0%2B-2496ED?style=for-the-badge&logo=docker&logoColor=white)](https://www.docker.com/) [![Containerlab](https://img.shields.io/badge/Containerlab-0.48%2B-FF6600?style=for-the-badge&logo=linux-containers&logoColor=white)](https://containerlab.dev/) [![Bash](https://img.shields.io/badge/Bash-4EAA25?style=for-the-badge&logo=gnu-bash&logoColor=white)](https://www.gnu.org/software/bash/) [![Elasticsearch](https://img.shields.io/badge/Elastic-9.2.1-005571?style=for-the-badge&logo=elasticsearch&logoColor=white)](https://www.elastic.co/) [![Suricata](https://img.shields.io/badge/Suricata-IDS-E5311A?style=for-the-badge&logo=suricata&logoColor=white)](https://suricata.io/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow?style=for-the-badge)](./LICENSE)
## 目录 - [概述](#-overview) - [架构](#-architecture) - [功能特性](#-features) - [先决条件](#-prerequisites) - [快速开始](#-quick-start) - [用法](#-usage) - [网络拓扑](#-network-topology) - [组件](#-components) - [攻击场景](#-attack-scenarios) - [测试](#-testing) - [项目结构](#-project-structure) - [许可证](#-license) ## 概述 **DMZ** 是一个一键部署工具,使用 [Containerlab](https://containerlab.dev/) 创建一个完整的企业网络环境。它模拟了一个跨四个网络段的真实企业基础设施: | 段 | 子网 | 描述 | |----|------|------| | **内部网络** | `192.168.10.0/24` | 包含客户端机器的企业局域网 | | **DMZ** | `10.0.2.0/24` | 包含 Web 服务器、WAF 和数据库的隔离区 | | **SIEM** | `10.0.3.0/30` | 包含完整 ELK 堆栈的安全监控区 | | **互联网 / 边缘** | `200.168.1.0/24` | 包含攻击节点的模拟互联网 | 适用于: - 安全培训与教育 - 渗透测试练习 - IDS/IPS 规则开发 - SIEM 日志分析与仪表板 - 网络取证 ## 架构 ``` ┌─────────────┐ │ Attacker │ │ (Kali Linux)│ └──────┬──────┘ │ 200.168.1.0/24 ┌──────┴──────┐ │ Router │ │ Internet │ └──────┬──────┘ │ 172.168.2.0/30 ┌──────┴──────┐ │ Router │ │ Edge │ └──────┬──────┘ │ 172.168.3.0/30 ┌──────────┴──────────┐ │ External FW │ │ (iptables + ulogd2) │ └───┬─────────┬───────┘ │ │ ┌─────────────┴─┐ ┌─┴──────────────┐ │ DMZ Zone │ │ Internal Zone │ │ 10.0.2.0/24 │ │ 192.168.10.0/24 │ │ │ │ │ │ ┌───────────┐ │ │ ┌─────────────┐ │ │ │Proxy / WAF│ │ │ │Internal FW │ │ │ │(ModSec) │ │ │ │(iptables) │ │ │ └─────┬─────┘ │ │ └──────┬──────┘ │ │ ┌─────┴─────┐ │ │ ┌──────┴──────┐ │ │ │ Flask Web │ │ │ │ Switch │ │ │ └─────┬─────┘ │ │ │ (FRR Bridge)│ │ │ ┌─────┴─────┐ │ │ └──┬──────┬───┘ │ │ │ PostgreSQL│ │ │ │ │ │ │ └───────────┘ │ │ Client1 Client2 │ │ ┌───────────┐ │ │ ┌─────────────┐ │ │ │ DMZ IDS │ │ │ │Internal IDS │ │ │ │(Suricata) │ │ │ │(Suricata) │ │ │ └───────────┘ │ │ └─────────────┘ │ └───────────────┘ └─────────────────┘ │ │ ┌───┴─────────┴───┐ │ SIEM FW │ │ 10.0.3.0/30 │ └───┬───┬───┬─────┘ │ │ │ ┌─────────┘ │ └─────────┐ ┌─────┴─────┐ ┌────┴────┐ ┌──────┴──────┐ │ Logstash │ │Elastic- │ │ Kibana │ │ :5044 │ │search │ │ :5601 │ │ │ │ :9200 │ │ │ └───────────┘ └─────────┘ └─────────────┘ ``` ## 功能特性 ### 网络安全 - **多层防火墙架构** — 内部防火墙、外部防火墙、SIEM 防火墙(iptables + NFLOG) - **入侵检测** — DMZ 和内部网络中的 Suricata IDS(通过桥接实现流量镜像) - **Web 应用防火墙** — 带有 OWASP ModSecurity CRS 的 NGINX 反向代理 - **网络分段** — 严格隔离互联网、DMZ、内部网络和 SIEM 区域 ### 应用栈 - **易受攻击的网络应用** — 使用 Flask + PostgreSQL 构建的登录系统 - **反向代理** — 支持 SSL/TLS 终止 - **数据库** — 包含示例数据(用户、报告、访问控制)的 PostgreSQL 16 ### 安全监控(SIEM) - **Elasticsearch 9.2.1** — 集中化日志存储与搜索 - **Logstash** — 日志采集管道(分别处理防火墙和 IDS 日志) - **Kibana** — 可视化、仪表板与分析 - **Filebeat** — 从防火墙和 IDS 节点收集日志 - **ulogd2** — 通过 NFLOG 记录防火墙日志 ### 自动化 - **一键部署** — 单命令部署整个环境 - **模块化设计** — 每个组件独立脚本 - **自动清理** — 一键清除整个实验室 - **预配置攻击场景** — SQL 注入、DoS、XSS 与目录遍历 ## 先决条件 | 软件 | 版本 | 描述 | |------|------|------| | **Linux** | — | 已在 Ubuntu / Debian 上测试 | | **Docker** | 24.0+ | 容器运行时 | | **Containerlab** | 0.48+ | 实验室编排 | | **sudo** | — | 网络操作所需的 root 权限 | ### 安装依赖 ``` bash install_dependencies.sh ``` ## 快速开始 ``` # 克隆仓库 git clone https://github.com/Trigger-45DMZ.git cd DMZ # 安装依赖(一次性) bash install_dependencies.sh # 完整部署 sudo bash main.sh ``` 部署完成后,以下服务可访问: | 服务 | URL | 描述 | |------|-----|------| | **Kibana** | `http://localhost:5601` | SIEM 仪表板 | | **Elasticsearch** | `http://localhost:9200` | 搜索 API | | **Web 应用(WAF)** | `http://localhost:8080` | 通过 ModSecurity 访问的 Web 应用 | ## 用法 ``` # 完整部署(默认) sudo bash main.sh # 仅部署拓扑(不配置) sudo bash main.sh --topology-only # 部署前不清理 sudo bash main.sh --skip-cleanup # 销毁实验室(停止容器) sudo bash main.sh --destroy # 销毁实验室并移除 Docker 镜像 sudo bash main.sh --purge ``` ### 检查拓扑 ``` sudo containerlab inspect --topo topology/DMZ.yml ``` ## 网络拓扑 ### 子网 | 子网 | CIDR | 用途 | |------|------|------| | 内部网络 | `192.168.10.0/24` | 客户端与内部交换机 | | 防火墙之间 | `192.168.20.0/24` | 内部防火墙 ↔ 外部防火墙 | | DMZ | `10.0.2.0/24` | WAF、Web 服务器、数据库、IDS | | SIEM | `10.0.3.0/24` | ELK 堆栈、SIEM 防火墙、管理员工作站 | | 边缘 1 | `172.168.2.0/30` | 互联网路由器 ↔ 边缘路由器 | | 边缘 2 | `172.168.3.0/30` | 边缘路由器 ↔ 外部防火墙 | | 互联网 | `200.168.1.0/24` | 攻击者 | ### 节点(19 个容器) | 节点 | 镜像 | 角色 | |------|-------|------| | `Internal_Client1` | Alpine | 内部客户端 | | `Internal_Client2` | Alpine | 内部客户端 | | `Internal_Switch` | FRR | 带有流量镜像功能的桥接 | | `Internal_FW` | Ubuntu | 防火墙(iptables + ulogd2 + Filebeat) | | `Internal_IDS` | Suricata | 内部网络 IDS | | `DMZ_Switch` | FRR | 带有流量镜像功能的桥接 | | `Proxy_WAF` | ModSecurity | OWASP WAF + NGINX 反向代理 | | `Flask_Webserver` | NGINX | Flask Web 应用 | | `Database` | PostgreSQL 16 | 数据库服务器 | | `DMZ_IDS` | Suricata | DMZ 区域 IDS | | `External_FW` | Ubuntu | 带有 NAT 的外部防火墙 | | `SIEM_FW` | Ubuntu | SIEM 防火墙(限制性强) | | `logstash` | Elastic 9.2.1 | 日志管道 | | `elasticsearch` | Elastic 9.2.1 | 日志存储与搜索 | | `kibana` | Elastic 9.2.1 | 可视化 | | `siem_pc` | Alpine | SIEM 管理工作站 | | `router-edge` | FRR | 边缘路由器 | | `router-internet` | FRR | 互联网路由器 | | `Attacker` | Kali Linux | 攻击者节点 | ## 组件 ### 防火墙 - **内部防火墙** — 允许内部流量访问 Web 服务器(端口 80),阻止 DMZ → 内部网络,通过 NFLOG + ulogd2 + Filebeat 记录日志- **外部防火墙** — 对传入 Web 流量执行 DNAT,对传出流量执行 MASQUERADE,通过 NFLOG + ulogd2 + Filebeat 记录日志 - **SIEM 防火墙** — 限制性规则:仅允许已定义的连接(Filebeat → Logstash、管理员 → Kibana 等),其余全部 DROP ### IDS(Suricata) - 规则涵盖:SQL 注入、SSH 暴力破解、端口扫描、ICMP 泛洪 - 日志路径:`/var/log/suricata/eve.json` → Filebeat → Logstash → Elasticsearch - 每个 IDS 独立索引:`suricata-dmz-*`、`suricata-internal-*` ### SIEM(ELK 堆栈) - **Logstash 管道**:`firewall.conf`(NFLOG 解析)、`ids.conf`(Suricata eve.json) - **Elasticsearch 索引**:`firewall-internal-*`、`firewall-external-*`、`suricata-dmz-*`、`suricata-internal-*` - **Kibana**:在 `http://localhost:5601` 可访问 ### Web 应用 - Flask 应用包含登录系统(管理员/用户角色) - PostgreSQL 后端包含示例数据(用户、报告、访问控制) - 受 OWASP ModSecurity CRS(WAF)和 NGINX 反向代理保护 ## 攻击场景 `attacks/` 目录中的预配置脚本: | 脚本 | 攻击类型 | 执行来源 | |------|----------|----------| | `attack_sql.sh` | SQL 注入攻击登录表单 | 攻击者容器 | | `attack_dos.sh` | DoS(ICMP 泛洪、SYN 泛洪、HTTP/S 泛洪) | 攻击者容器 | | `attack_xss_path.sh` | XSS 与目录遍历 | Internal_Client2 | ### 示例:运行 SQL 注入 ``` # 部署攻击脚本 bash attacks/attack_sql.sh # 在 Attacker 容器内执行 sudo docker exec -it clab-MaJuVi-Attacker bash /root/sql_attack_simple.sh ``` ### 示例:运行 DoS 攻击 ``` bash attacks/attack_dos.sh sudo docker exec -it clab-MaJuVi-Attacker python3 /root/dos.py ``` 所有攻击都会生成日志,通过 SIEM 管道采集到 Elasticsearch,并可在 Kibana 中可视化。 ## 测试 ``` bash scripts/tests/test-connectivity.sh ``` 测试套件验证以下内容: - 所有网络段之间的连接性 - 服务可用性(Elasticsearch、Kibana、Logstash) - 运行进程(Filebeat、Suricata、ulogd2) - 防火墙规则(默认拒绝策略) - WAF 功能(ModSecurity 启用) ## 项目结构 ``` DMZ/ ├── main.sh # Main entry point ├── install_dependencies.sh # Dependency installer ├── attacks/ # Pre-configured attack scripts │ ├── attack_sql.sh # SQL Injection │ ├── attack_dos.sh # Denial of Service │ └── attack_xss_path.sh # XSS & Directory Traversal ├── config/ # Configuration files │ ├── variables.sh # Central variables (IPs, images, subnets) │ ├── logstash/ # Logstash pipeline configurations │ ├── suricata/ # Suricata rules & configuration │ └── webserver-details/ # Flask app (app.py) ├── topology/ # Containerlab topology │ └── topology-generator.sh # Generates the YAML topology ├── scripts/ │ ├── setup/ # Setup & deployment │ │ ├── 01-cleanup.sh # Clean up previous environments │ │ ├── 02-docker-prep.sh # Prepare Docker images │ │ └── 03-deploy-topology.sh # Deploy Containerlab topology │ ├── configure/ # Component configuration │ │ ├── firewalls/ # Internal FW, External FW, SIEM FW │ │ ├── dmz/ # Web server, Proxy/WAF, Database │ │ ├── ids/ # Suricata IDS (DMZ + Internal) │ │ ├── siem/ # ELK stack configuration │ │ └── network/ # Routers, switches, clients │ ├── tests/ # Connectivity & functional tests │ └── lib/ # Helper libraries (logging) ├── docs/ # Documentation │ └── diagramm.puml # PlantUML network diagram └── LICENSE # MIT License ``` ## 许可证 本项目根据 [MIT 许可证](LICENSE) 授权。
标签:Bash, Containerlab, DMZ, Docker, Elasticsearch, ELK SIEM, IDS/IPS, Metaprompt, NIDS, Suricata IDS, WAF, 企业级安全, 企业网络安全, 多层次防火墙, 安全测试, 安全防御评估, 容器化, 容器网络, 应用安全, 攻击性安全, 攻击模拟, 流量捕获, 测试用例, 特权提升, 网络实验室, 网络拓扑, 自动化部署, 请求拦截, 驱动签名利用