ahhmedmostafaa/AI_Powered_Cybersecurity_Lab
GitHub: ahhmedmostafaa/AI_Powered_Cybersecurity_Lab
一个融合机器学习、IDS 与自动化防火墙缓解的全自动多层网络防御系统,旨在消除企业网络中的检测盲区、警报泛滥与响应滞后问题。
Stars: 2 | Forks: 0
# 🛡️ 基于 AI 的网络安全实验室
**一个集成了机器学习、入侵检测和自动化防火墙缓解的多层网络防御系统**
## 🎯 项目概述
一个部署在仿真虚拟化企业网络中的全自动化、多层网络防御系统。该系统在 240 次实时攻击试验中实现了 **100% 的检测率**,**平均缓解时间 (MTTM) 为 872 毫秒** —— 且无需任何人工干预。
### 它解决的问题
现代企业网络面临着三个相互交织的安全缺口,没有任何单一解决方案能够解决这些问题:
1. **检测覆盖盲区** — 基于特征的 IDS 会漏检行为威胁;仅依赖 ML 的模型在处理真实流量时容易失效
2. **警报泛滥** — 缺乏去重机制的多个引擎会让分析师应接不暇
3. **缺乏自动化补救** — 大多数系统仅停留在生成警报阶段;手动响应需要耗费数小时
该系统能够同时解决这三个问题。
## ⚡ 关键结果
| 指标 | 数值 |
|--------|-------|
| AI 检测准确率 | **98.94%** |
| 攻击检测与缓解率 | **100%** (240/240 次试验) |
| 平均缓解时间 (MTTM) | **872 毫秒** |
| 实时攻击试验 | **240** 次 (每类 30 次) |
| 自定义数据集大小 | **80,000** 个标注的流量样本 |
| 覆盖的攻击类别 | **8** 类 |
## 🏗️ 系统架构
```
┌─────────────────────────────────────────────────────────┐
│ WAN ZONE │
│ Kali Linux Adversary │
│ 192.168.180.130 / .131 │
└──────────────────────┬──────────────────────────────────┘
│ Attack Traffic
▼
┌─────────────────────────────────────────────────────────┐
│ DMZ / EDGE │
│ pfSense Firewall 2.7.2 │
│ 192.168.180.129 │
│ [EasyRuleBlockHostsWAN alias] │
└──────────────────────┬──────────────────────────────────┘
│ Mirrored Traffic
▼
┌─────────────────────────────────────────────────────────┐
│ DEFENSE ZONE — Ubuntu AI Server │
│ 192.168.150.10 │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌────────────────┐ │
│ │ XGBoost ML │ │ Suricata IDS│ │ Zeek Monitor │ │
│ │ 98.94% acc │ │ ET Open rules│ │ Protocol analysis│ │
│ └──────┬──────┘ └──────┬──────┘ └───────┬────────┘ │
│ │ │ │ │
│ └────────────────┼──────────────────┘ │
│ ▼ │
│ ┌─────────────────────┐ │
│ │ Orchestration │ │
│ │ Engine (Python) │ │
│ │ 3-Tier Escalation │ │
│ │ 30s/180s Dedup │ │
│ └──────────┬──────────┘ │
│ │ SSH pfctl block │
└─────────────────────────┼───────────────────────────────┘
▼
pfSense firewall BLOCKED ✓
```
### 四层检测
| 层级 | 技术 | 可捕获内容 |
|-------|-----------|-----------------|
| ML 分类器 | XGBoost (基于行为) | 僵尸网络、数据外发、SlowLoris 以及全部 8 个类别 |
| 特征 IDS | Suricata + ET Open 规则 | 已知攻击特征 (6/8 个类别) |
| 协议监控器 | Zeek | 行为异常、C2 模式 |
| 规则启发式 | 自定义 Python 引擎 | SYN 泛洪、快速扫描、暴力破解 |
### 三级置信度升级机制
- **第一级:** 单引擎警报 → 记录日志 + 加强监控
- **第二级:** 30 秒内双引擎触发 → 结构化警报 (不执行自动拦截)
- **第三级:** 高置信度 (ML ≥65%) + 多引擎 → **自主通过 pfSense SSH 进行拦截**
## 🗂️ 仓库结构
```
AI-Cybersecurity-Lab/
│
├── scripts/
│ ├── script0_attack_generator.py # Automated Threat Orchestration Engine (Kali side)
│ ├── script1_data_collection.py # Live traffic capture with Scapy (Ubuntu side)
│ ├── script2_model_training.py # XGBoost training pipeline
│ └── ai_defense_orchestration.py # Final 4-layer defense system (production)
│
├── config/
│ └── network_configuration.md # Full network topology & IP addressing
│
├── results/
│ └── performance_metrics.md # All results: accuracy, MTTM, per-class metrics
│
├── docs/ # Research paper / documentation
│
├── requirements.txt
├── .gitignore
└── README.md
```
## 🚀 快速开始
### 前置条件
- Ubuntu 24.04 LTS (AI 防御服务器)
- Python 3.10+
- 已安装 Suricata 8.x + Zeek 8.x
- 可通过 SSH 访问 pfSense
- GNS3 网络拓扑 (参见 `config/network_configuration.md`)
### 安装
```
# 克隆仓库
git clone https://github.com/ahhmedmostafaa/AI-Cybersecurity-Lab.git
cd AI-Cybersecurity-Lab
# 安装 Python 依赖
pip install -r requirements.txt
# 安装 Suricata (Ubuntu)
sudo apt install suricata -y
sudo suricata-update # Download ET Open rules
# 安装 Zeek (Ubuntu)
sudo apt install zeek -y
```
### 配置
运行前,请编辑 `scripts/ai_defense_orchestration.py` 并更新:
```
class Config:
PFSENSE_IP = "YOUR_PFSENSE_IP" # e.g. 192.168.180.129
PFSENSE_USER = "admin"
PFSENSE_PASS = "YOUR_PASSWORD" # ⚠️ Never commit credentials!
LOCAL_IF = "ens33" # Your capture interface
```
### 运行系统
```
# 步骤 1 — 为数据集生成攻击流量 (Kali Linux)
sudo python3 scripts/script0_attack_generator.py --target 192.168.50.11
# 步骤 2 — 捕获实时流量 (Ubuntu AI Server)
sudo python3 scripts/script1_data_collection.py --iface ens33 --samples 10000
# 步骤 3 — 训练 XGBoost 模型
python3 scripts/script2_model_training.py
# 步骤 4 — 启动防御系统
sudo python3 scripts/ai_defense_orchestration.py
```
## 📊 数据集
该模型在**自定义的 80,000 个样本数据集**上进行了训练,该数据集是使用真实的攻击工具(Nmap、hping3、Hydra、Metasploit、Slowloris)从 GNS3/VMware 环境中实时捕获的 —— 而非脚本模拟器。
| 类别 | 样本数 | 使用的工具 |
|---------------|---------|------------------------|
| BENIGN | 10,000 | curl / FTP / DNS |
| PortScan | 10,000 | Nmap (-sS, -sV) |
| DDoS | 10,000 | hping3 --flood |
| BruteForce | 10,000 | Hydra SSH/RDP |
| Botnet | 10,000 | Metasploit Meterpreter |
| DataExfil | 10,000 | curl POST bulk |
| WebAttack | 10,000 | SQLi 遍历 |
| SlowLoris | 10,000 | Python Slowloris |
## 🛠️ 技术栈
| 类别 | 技术 |
|----------|-----------|
| 网络仿真 | GNS3 + VMware Workstation 16 Pro |
| 企业级路由 | Cisco IOS 15.2 (C7200) + OSPF |
| 交换机 | Cisco IOU L2 (802.1Q VLANs) |
| 防火墙 | pfSense 2.7.2 (FreeBSD) |
| ML 引擎 | Python + XGBoost 2.0.3 |
| 流量捕获 | Scapy 2.5.0 |
| 特征 IDS | Suricata 8.0.3 + ET Open 规则 |
| 协议监控器 | Zeek 8.1.1 |
| 攻击者 OS | Kali Linux 2025.2 |
| 防御服务器 | Ubuntu 24.04.3 LTS |
## 📈 模型性能
```
Overall Accuracy: 98.94%
Macro Precision: 98.93%
Macro Recall: 98.92%
Macro F1-Score: 98.92%
Inference Speed: ~11,200 samples/second
Per-sample latency: ~0.089 ms
```
有关详细的分类细分和 MTTM 结果,请参见 `results/performance_metrics.md`。
## ⚠️ 合理使用声明
本项目**严格仅用于网络安全研究**。
- 所有攻击仿真均在**隔离的虚拟实验室环境**中进行
- 未针对任何真实网络或系统发起攻击
- 提供攻击脚本 (`script0_attack_generator.py`) 仅为**保证研究的可复现性**
- **请勿**将本项目的任何部分用于您未拥有或未获得明确测试授权的系统
## 📄 许可证
MIT License — © 2025 Ahmed Mostafa Hussein
## 📬 联系方式
- **GitHub:** [ahhmedmostafaa](https://github.com/ahhmedmostafaa)
- **Website:** [ahhmedmostafaa.github.io/AI_Powered_Cybersecurity_Lab](https://ahhmedmostafaa.github.io/AI_Powered_Cybersecurity_Lab)
- **LinkedIn:** [ahmedmostafahussein](https://www.linkedin.com/in/ahmedmostafahussein)
- **Email:** a7medmostafa7777@gmail.com
标签:Apex, Metaprompt, 插件系统, 机器学习, 网络安全, 网络流量分析, 自动化防御, 逆向工具, 配置错误, 隐私保护