MuriloChianfa/isp-ddos-auto-detector

GitHub: MuriloChianfa/isp-ddos-auto-detector

基于真实ISP Transit网络NetFlow数据,系统评估四种无监督异常检测算法在高速环境下DDoS检测中的表现。

Stars: 3 | Forks: 0

高速网络中的无监督 DDoS 检测:
基于真实 Transit 提供商数据的评估

[![Python](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![License: CC BY 4.0](https://img.shields.io/badge/License-CC_BY_4.0-lightgrey.svg)](https://creativecommons.org/licenses/by/4.0/) [![Platform](https://img.shields.io/badge/platform-Linux-lightgrey.svg)](https://www.linux.org/) [![Conda](https://img.shields.io/badge/conda-env-green.svg)](https://docs.conda.io/) [![TensorFlow](https://img.shields.io/badge/TensorFlow-2.16-orange.svg)](https://www.tensorflow.org/) [![Scikit-learn](https://img.shields.io/badge/sklearn-1.6-blue.svg)](https://scikit-learn.org/)
在过去的十年中,学术界对分布式拒绝服务攻击的检测进行了广泛的研究。尽管取得了一些进展,但近期的调查表明,由于高速环境的限制,在 Internet Transit Provider (ITP) 等环境中的检测仍然具有挑战性。本研究使用从运营中的 ITP 在确认发生 DDoS 攻击期间收集的三个数据集,评估了四种异常检测算法,即 Autoencoder、Isolation Forest、Local Outlier Factor 和 One Class Support Vector Machine。评估考虑了四个时间聚合窗口和三种特征选择配置,旨在分析算法在不同时间和特征选择设置下的预测能力。结果表明,Autoencoder 在使用最激进的特征选择配置和最短的时间聚合窗口时获得了最佳的检测结果。 ## README 结构 1. [**标题与摘要**](#abstract):研究概述与目标 2. [**README 结构**](#agenda):文档组织说明 3. [**基本信息**](#basic-information):硬件与执行环境要求 4. [**申请徽章**](#badges-considered):评审申请的徽章声明 5. [**依赖项**](#dependencies):所需库和工具的完整列表 6. [**安全问题**](#security-concerns):潜在风险与安全操作规程 7. [**安装说明**](#installation):环境配置的分步指南 8. [**最小化测试**](#minimal-test):用于验证安装的简单命令 9. [**实验**](#experiments):复现论文中展示的主要结果 10. [**数据集**](#datasets):实验中使用的数据说明 11. [**致谢**](#acknowledgments):感谢合作机构 12. [**LICENSE**](#license):双重许可(代码采用 MIT / 数据集采用 CC BY 4.0) ### 仓库结构 项目文件和目录的组织结构: ``` isp-ddos-auto-detector/ ├── config.py # Configuration and dataset definitions ├── main.py # CLI entry point ├── environment.yml # Conda environment specification ├── framework/ # Core framework modules │ ├── pipeline.py # Main analysis pipeline │ ├── models/ # Anomaly detection models │ │ ├── isolation_forest.py │ │ ├── one_class_svm.py │ │ ├── local_outlier_factor.py │ │ └── autoencoder.py │ ├── features.py # Feature engineering │ ├── evaluation.py # Model evaluation metrics │ ├── optimization.py # Hyperparameter tuning │ ├── versioning.py # Run versioning and management │ ├── comparison.py # Run comparison utilities │ ├── visualization/ # Plotting utilities │ └── ... ├── datasets/ # NetFlow datasets │ ├── itp-downstream-http-flood/ │ ├── itp-multivector-udp-100gbps-peak/ │ └── itp-synack-customer-outage/ └── results/ # Evaluation results and plots ├── summary/ ├── cross_evaluation/ ├── versions/ # Versioned runs for comparison ├── comparisons/ # Comparison reports └── runs_index.json # Index of all saved runs ``` ## 申请徽章 本制品申请:**Available**、**Functional**、**Sustainable** 和 **Reproducible** 徽章。 | 徽章 | 理由 | |-------|---------------| | **Available** | 完整的源代码、数据集和结果均在此仓库中公开提供 | | **Functional** | 可完全执行,附带详细的设置、验证测试和固定版本的依赖项 | | **Sustainable** | 模块化架构,组件清晰并带有内联文档 | | **Reproducible** | 提供自动化脚本和详细说明以复现论文的主要结果 | ## 基本信息 ### 硬件要求 实验在具有以下规格的机器上执行: - **处理器**:Dual Intel Xeon E5-2683 v4 @ 2.10 GHz - **内存 (RAM)**:128 GB DDR4 2133MHz RDIMM ECC - **显卡 (GPU)**:NVIDIA GeForce GTX 1050 Ti,配备 4 GB VRAM - **存储**:数据集至少需要 20 GB 的可用空间 - **操作系统**:Linux Debian 12 Kernel 6.1.0-26-amd64 ### 软件要求 - **Python**:最新可用版本 3.12.2 - **Conda**:Miniconda 或 Anaconda(用于环境管理) - **Git 和 Git LFS**:用于克隆仓库并下载衍生数据集 ## 依赖项 该框架具有定义明确的依赖项,通过 Conda 进行管理。所有依赖项都会通过 `environment.yml` 文件自动安装,该文件包含: - 固定版本的包以确保可复现性 - Conda 频道配置(pytorch、nvidia、conda-forge、defaults) - 针对 Conda 中不可用包的额外 pip 依赖项 ## 安全问题 ### 潜在风险 1. **计算资源消耗**: - 模型训练在超参数优化期间会消耗大量 RAM - 批量执行可能需要数小时(所有 144 个完整场景最多需要 96 小时) - 建议在执行期间使用 `htop`/`nvidia-smi` 监控 CPU/GPU/RAM 使用情况 2. **大文件下载**: - `git lfs pull` 命令将下载总容量可能达数 GB 的衍生数据集 - 请确保拥有稳定的连接和足够的磁盘空间 - 在带宽受限的环境中,请考虑仅下载特定的数据集 ### 注意事项 - 该框架**绝不**修改项目目录之外的系统文件 - 该框架**绝不**收集或将数据传输到外部服务器 - 所有结果和训练好的模型均保存在本地的 `results/` 和 `cache/` 中 ## 安装说明 ### 第 1 步:安装 Git LFS 下载衍生数据集(大文件)需要使用 Git LFS。 ``` # Ubuntu/Debian sudo apt install git-lfs git lfs install # 验证安装 git lfs version ``` ### 第 2 步:克隆仓库 ``` git clone https://github.com/MuriloChianfa/isp-ddos-auto-detector.git cd isp-ddos-auto-detector ``` ### 第 3 步:下载衍生数据集 ``` # 根据网络连接情况,此命令可能需要几分钟 git lfs pull ``` ### 第 4 步:安装 Miniconda 请按照适用于您操作系统的官方安装指南进行操作: [https://www.anaconda.com/docs/getting-started/miniconda/install/overview](https://www.anaconda.com/docs/getting-started/miniconda/install/overview)
快速参考:Linux x86_64 上的非交互式安装(点击展开) ``` # 下载适用于 linux x86_64 的最新 Miniconda 安装程序 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/Miniconda3-latest-Linux-x86_64.sh # 以 batch(非交互)模式运行安装程序至 ~/miniconda3 bash ~/Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda3 # 使 conda 在当前 shell 中可用 source $HOME/miniconda3/etc/profile.d/conda.sh # (可选)为未来的 shell 会话初始化 conda conda init bash # 接受默认 channels 的 Anaconda Terms of Service conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r # 验证安装 conda --version ```
### 第 5 步:创建 Conda 环境 ``` # 从 specification file 创建环境 conda env create -f environment.yml ``` ### 第 6 步:激活环境 ``` conda activate nf-ae ``` **重要提示**:在执行任何框架命令之前,请始终激活 `nf-ae` 环境。 ### 第 7 步:验证安装 完成上述步骤后,该框架即可投入使用。 请前往 [**最小化测试**](#minimal-test) 部分以验证安装。 ### (可选)从原始数据中提取特征 如果您拥有原始的 NetFlow 数据并希望提取特征: ``` # 设置环境变量 export FILTER="dst as 65550" # ASN65550 reserved for examples (RFC5398) export DATASET_DIR=/path/to/raw/dataset export OUTPUT_DIR=./datasets/dataset-name # 运行转换脚本 ./datasets/convert-to-csv.sh ``` ## 最小化测试 本节介绍用于验证安装是否成功的简单命令。以下测试可在 1 分钟内执行完毕,且不需要大量的计算资源。 ### 第 1 步:显示帮助 验证 CLI 是否成功加载以及所有依赖项是否解析完毕。 ``` python main.py --help ``` ### 第 2 步:列出可用模型 验证模型工厂是否正确连接。 ``` python main.py --list-models ``` ### 第 3 步:运行最小化的端到端检测 这将为单个(数据集、模型、窗口)组合运行**完整的 pipeline**,完全确定性,并且与论文具有直接可比性:在 DS2 数据集上使用 Δt = 1s 的 One-Class SVM。该组合正是 [**表 5**](#expected-results-table) 中针对 itp-downstream-http-flood x One-Class SVM 所报告的内容。 在参考硬件上的典型耗时:**不到 30 秒**。 ``` python main.py -d itp-downstream-http-flood -m one_class_svm -t 1 --force-retrain ``` 预期控制台输出(最后几行): ``` Confusion Matrix: Predicted Normal Attack Actual Normal 138860 331 Attack 21 298 Basic Performance Metrics: Accuracy: 0.9975 Precision: 0.4738 Recall: 0.9342 F1-Score: 0.6287 F2-Score: 0.7822 Advanced Performance Metrics: Matthews Correlation Coefficient: 0.6643 ROC AUC Score: 0.9659 Miss Rate (FNR): 0.0658 Fallout (FPR): 0.0024 Sample Distribution: Total Samples: 139,510 Attack Periods: 319 Detected Anomalies: 629 ``` ## 实验 本节提供了复现论文主要结果的详细说明。实验按声明组织,这些声明与所展示的表格和图表相对应。 ### 数据集背景 该框架使用了从运营中的 Internet Transit Provider (ITP) 网络收集的三个真实 DDoS 攻击数据集进行评估: | 数据集 | 攻击类型 | 特征 | |---------|-------------|------------------| | **itp-downstream-http-flood** | HTTP Flood | 针对下游客户的第七层 (Layer 7) 攻击 | | **itp-multivector-udp-100gbps-peak** | Multi-vector UDP | 峰值超过 100 Gbps 的流量型攻击 | | **itp-synack-customer-outage** | SYN-ACK Reflection | 导致服务中断长达两小时的攻击 | 每个数据集均包含带有衍生特征的 NetFlow v9 遥测数据,这些特征包括 Shannon 熵、统计矩、协议指示器以及时间/流量指标。 ### 实验配置 所有实验均使用以下配置: - **时间窗口 (Δt)**:1s, 10s, 60s, 300s - **PCC 截止值 (θ)**:0.50, 0.70, 0.90 - **模型**:Autoencoder, Isolation Forest, One-Class SVM, Local Outlier Factor - **指标**:Accuracy, Precision, Recall, F₁-Score, FPR, MCC, Average Precision ### 声明 #1:模型性能指标 (Δt=1s, θ=0.50) **目标**:复现在使用 1 秒时间窗口和 0.50 PCC 阈值的情况下,三个数据集上四个模型的性能指标表。 #### 执行命令 ``` # 运行 PCC 特征选择分析 python main.py --analyze-correlation --correlation-threshold 0.50 # 对所有 datasets 和 models 运行批量分析 python main.py --batch --batch-time-spans 1 --force --force-retrain ``` #### 结果可视化 要生成汇总摘要: ``` python main.py --summary --summary-no-optimal-params --summary-no-stats --summary-time-spans 1 ``` #### 预期结果表 | 数据集 | 模型 | Accuracy | Precision | Recall | F₁ | FPR | MCC | |---------|-------|----------|-----------|--------|-------|--------|--------| | **itp-downstream-http-flood** | Autoencoder | **0.9992** | **0.7772** | 0.9404 | **0.8511** | **0.0006** | **0.8546** | | | Isolation Forest | 0.9875 | 0.1440 | 0.9060 | 0.2485 | 0.0123 | 0.3584 | | | Local Outlier Factor | 0.9889 | 0.1702 | **0.9906** | 0.2904 | 0.0111 | 0.4082 | | | One-Class SVM | 0.9975 | 0.4738 | 0.9342 | 0.6287 | 0.0024 | 0.6643 | | **itp-multivector-udp-100gbps-peak** | Autoencoder | **0.9969** | **0.9138** | 0.6628 | **0.7683** | **0.0005** | **0.7768** | | | Isolation Forest | 0.9897 | 0.4012 | 0.6672 | 0.5011 | 0.0078 | 0.5127 | | | Local Outlier Factor | 0.9961 | 0.8718 | 0.5768 | 0.6943 | 0.0007 | 0.7074 | | | One-Class SVM | 0.9796 | 0.2679 | **0.9444** | 0.4174 | 0.0202 | 0.4972 | | **itp-synack-customer-outage** | Autoencoder | **0.9901** | **0.9177** | 0.7063 | 0.7983 | 0.0018 | 0.8004 | | | Isolation Forest | 0.9750 | 0.8029 | 0.1348 | 0.2309 | **0.0009** | 0.3229 | | | Local Outlier Factor | 0.9792 | 0.5888 | 0.8360 | 0.6910 | 0.0167 | 0.6918 | | | One-Class SVM | 0.9893 | 0.7897 | **0.8377** | **0.8130** | 0.0064 | **0.8079** | *加粗数值表示在每个数据集中各项指标的最佳性能。*