Model Context Protocol server for real-time 5G DDoS detection and response
Powered by the NCSRD-DS-5GDDoS dataset — a physical 3GPP-compliant 5G testbed from the EU Horizon PRIVATEER project
______________________________________________________________________
它的作用
赋予任何LLM代理检测、解释和响应5G DDoS攻击的能力:
| 工具 | 它做什么 |
|---|---|
detect_anomaly | 将实时5G遥测分类为良性/攻击型——返回类型、置信度、严重性 |
explain_attack | 通过配置的LLM生成自然语言事件报告 |
recommend_response | 带有通用REST API调用示例的切片软件缓解计划 |
query_history | 搜索过去的事件+数据集参考模式,用于少镜头LLM推理 |
支持 SYN、UDP、ICMP、DNS和GTP-U洪泛 (最后一个是5G特定的严重性)。
______________________________________________________________________
快速开始
选择您的LLM后端并遵循匹配的路径。服务器运行在 演示模式 (基于规则的启发式),没有经过训练的模型,因此您可以立即尝试所有工具。
______________________________________________________________________
方案A-克劳德(API无烟煤)
事件报告和建议的最佳输出质量。
# 1. Clone and install
git clone https://github.com/ncsrd/5g-ddos-mcp
cd 5g-ddos-mcp
pip install -r requirements.txt
# 2. Configure
cp .env.example .env
# Set: LLM_BACKEND=claude
# Set: ANTHROPIC_API_KEY=sk-ant-...
# 3. Run
python -m src.server连接 claude_desktop_config.json:
{
"mcpServers": {
"5g-ddos": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/path/to/5g-ddos-mcp",
"env": {
"LLM_BACKEND": "claude",
"ANTHROPIC_API_KEY": "sk-ant-..."
}
}
}
}______________________________________________________________________
选项B——Ollama(本地开源LLM,完全离线)
最适合气隙或隐私敏感部署。没有数据离开你的机器。
步骤1--安装Olama
# macOS / Linux
curl -fsSL https://ollama.com/install.sh | sh
# Windows: download from https://ollama.com/download第二步——拉一个模型
ollama pull llama3.2 # 3B (fast) or 8B (balanced) — recommended default
ollama pull mistral # 7B — strong reasoning
ollama pull phi4 # 14B — best structured output
ollama pull gemma3 # Google Gemma 3, 4B–27B
ollama pull deepseek-r1 # 8B chain-of-thought distill
ollama pull qwen2.5 # 7B / 14B / 72B步骤3--运行MCP服务器
cp .env.example .env
# Set: LLM_BACKEND=ollama
# Set: OLLAMA_MODEL=llama3.2 (or whichever you pulled)
# OLLAMA_BASE_URL defaults to http://localhost:11434
python -m src.server连接 claude_desktop_config.json:
{
"mcpServers": {
"5g-ddos": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/path/to/5g-ddos-mcp",
"env": {
"LLM_BACKEND": "ollama",
"OLLAMA_MODEL": "llama3.2"
}
}
}
}______________________________________________________________________
选项C——OpenAI兼容端点
与vLLM、LM Studio、Groq、Together.ai、Mistral API、Perplexity和任何其他与OpenAI兼容的提供商配合使用。
cp .env.example .env
# Set: LLM_BACKEND=openai_compatible
# Set: OPENAI_BASE_URL=
# Set: OPENAI_MODEL=
# Set: OPENAI_API_KEY=
python -m src.server提供商示例:
| 供应商 | OPENAI_BASE_URL | OPENAI_MODEL |
|---|---|---|
| vLLM (自托管) | http://localhost:8080/v1 | 您部署的模型 |
| LM 工作室 (本地) | http://localhost:1234/v1 | LM Studio中加载的模型 |
| 格罗克 | https://api.groq.com/openai/v1 | llama-3.3-70b-versatile |
| Together.ai | https://api.together.xyz/v1 | meta-llama/Llama-3-70b-chat-hf |
| API米斯特拉尔 | https://api.mistral.ai/v1 | mistral-large-latest |
| 困惑度 | https://api.perplexity.ai | llama-3.1-sonar-large-128k-online |
| 开放人工智能 | https://api.openai.com/v1 | gpt-4o |
______________________________________________________________________
选项D——Docker(任何后端)
# Build
docker build -t 5g-ddos-mcp .
# Run with Claude
docker run --env-file .env -p 8000:8000 \
-v $(pwd)/models:/app/models:ro \
-v $(pwd)/data:/app/data:ro \
5g-ddos-mcp
# Run with Ollama (Ollama running on host)
docker run -p 8000:8000 \
-e LLM_BACKEND=ollama \
-e OLLAMA_BASE_URL=http://host.docker.internal:11434 \
-e OLLAMA_MODEL=llama3.2 \
5g-ddos-mcp
# Full stack: MCP server + Ollama side-by-side
docker compose --profile with-ollama up
# Then pull a model inside the Ollama container:
docker exec -it ollama ollama pull llama3.2
# Full stack with InfluxDB + Grafana (mirrors the NCSRD testbed pipeline)
docker compose --profile full up______________________________________________________________________
选项E——Kubernetes
# 1. Apply namespace, storage, and config
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/pvc.yaml
kubectl apply -f k8s/configmap.yaml
# 2. Create secrets (replace with real values)
kubectl create secret generic 5g-ddos-mcp-secrets \
--from-literal=ANTHROPIC_API_KEY=sk-ant-... \
-n 5g-ddos-mcp
# 3. Deploy (set LLM_BACKEND in k8s/deployment.yaml before applying)
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
# 4. Train the model inside the cluster (after populating the data PVC)
kubectl apply -f k8s/train-job.yaml
kubectl logs -f job/train-classifier -n 5g-ddos-mcp
# 5. Check status
kubectl get pods -n 5g-ddos-mcp要将Ollama部署为完全自包含集群的sidecar:
# Ollama deployment + service are already included in k8s/deployment.yaml
# Set LLM_BACKEND=ollama and OLLAMA_BASE_URL=http://ollama-service:11434 in configmap.yaml
kubectl apply -f k8s/deployment.yaml # deploys both mcp-server and ollama
kubectl apply -f k8s/service.yaml
# Then exec into the Ollama pod to pull a model:
kubectl exec -it deploy/ollama -n 5g-ddos-mcp -- ollama pull llama3.2______________________________________________________________________
数据集设置
ML模型需要 NCSRD-DS-5GDOS v3.0 数据集(约620 MB),必须单独下载。服务器在没有它的情况下以启发式演示模式运行。
# Automatic download from Zenodo (DOI: 10.5281/zenodo.13900057)
chmod +x scripts/download_dataset.sh
./scripts/download_dataset.sh
# Then train the classifier (~5–15 min depending on hardware)
python scripts/train_model.py
# Quick smoke-test with 100k rows
python scripts/train_model.py --nrows 100000看 data/DATASET_INSTRUCTIONS.md 有关文件和手动下载的完整详细信息。
目标指标 (来自此数据集的已发表结果):
| 指标 | 目标 | 已发布 |
|---|---|---|
| 二进制F1 | >0.95 | 0.98 |
| AUC-ROC | >0.99 | 0.999 |
| 多级加权F1 | >0.95 | 0.98 |
______________________________________________________________________
命令行界面
这 5g-ddos 命令允许您直接从终端运行检测、查询历史、获取建议和管理数据集,无需MCP客户端。
pip install -e ".[all]" # installs the 5g-ddos entry point
5g-ddos --helpserver --启动MCP服务器
5g-ddos server # uses LLM_BACKEND from .env
5g-ddos server --backend ollama --model phi4
5g-ddos server --backend claudedetect --对5G遥测技术进行分类
# Inline single-sample detection
5g-ddos detect --ul-bitrate 9500000 --dl-bitrate 1200000 \
--ul-retx 0.42 --pdu-session-setup-request 95 \
--ue-id UE-007
# Batch detection from a CSV file (matches NCSRD dataset schema)
5g-ddos detect --input telemetry.csv --format table
5g-ddos detect --input telemetry.csv --format csv --output results.csv
# Output formats: table (default) | json | csvexplain --生成事件报告
5g-ddos explain --attack-type gtp_u_flood --severity critical \
--slice URLLC --ue-ip 10.45.0.3 --cells "1,2"
5g-ddos explain --attack-type syn_flood --severity high \
--imeisv 3533890312345678 --format json --output report.jsonrecommend --获取缓解建议
5g-ddos recommend --attack-type udp_flood --severity high --slice eMBB
# Preview auto-execute REST API commands (does not call any API without RESPONSE_API_URL set)
5g-ddos recommend --attack-type gtp_u_flood --severity critical \
--ue-ip 10.45.0.5 --imeisv 3533890312345678 \
--auto-executehistory --查询事件历史记录
5g-ddos history # last 10 incidents
5g-ddos history --attack-type syn_flood --limit 20
5g-ddos history --severity critical --slice URLLC --time-range 24train --训练XGBoost分类器
5g-ddos train # full dataset (~5–15 min)
5g-ddos train --nrows 100000 # quick smoke-test with 100k rowsdataset --管理NCSRD数据集
5g-ddos dataset status # show which files are present / missing
5g-ddos dataset download # print download instructions
5g-ddos dataset download --auto # run scripts/download_dataset.sh automaticallyversion --显示环境信息
5g-ddos version
# ┌──────────────────────┬───────────────────────────────┐
# │ 5g-ddos-mcp │ 1.0.0 │
# │ LLM Backend │ claude (claude-sonnet-4-6) │
# │ ML Model │ loaded (binary + multi-class) │
# │ Dataset records │ 7 files present │
# └──────────────────────┴───────────────────────────────┘______________________________________________________________________
建筑
┌──────────────────────────────────────────────┐
│ MCP Client (any LLM) │
└──────────────────┬───────────────────────────┘
│ MCP Protocol (stdio / HTTP)
┌──────────────────▼───────────────────────────┐
│ 5G-DDoS MCP Server │
│ │
│ ┌─────────────┐ ┌──────────────────────┐ │
│ │ ML Layer │ │ LLM Layer │ │
│ │ XGBoost │ │ Claude │ Ollama │ │
│ │ Classifier │ │ OpenAI-compatible │ │
│ └──────┬──────┘ └──────────────────────┘ │
│ │ │
│ ┌──────▼────────────────────────────────┐ │
│ │ MCP Tools │ │
│ │ detect_anomaly │ explain_attack │ │
│ │ recommend_response │ query_history │ │
│ └───────────────────────────────────────┘ │
└──────────────────────────────────────────────┘
│
┌──────────▼──────────┐
│ NCSRD Dataset │
│ (local CSV) │
└─────────────────────┘第1层——感知: XGBoost分类器(在NCSRD-DS-5GDOS上训练)检测来自实时遥测的攻击。
第2层——推理: LLM生成情境事件报告和缓解建议。
第3级——行动: 用于自动响应的通用REST API集成(黑名单UE、隔离切片、速率限制)。与Open5GS、free5GC、OAI或任何自定义NMS兼容 RESPONSE_API_URL 以启用。
______________________________________________________________________
配置参考
所有设置均通过环境变量进行。复制 .env.example 到 .env 开始吧。
| 变量 | 默认值 | 描述 | ||
|---|---|---|---|---|
LLM_BACKEND | claude | claude | ollama | openai_compatible |
ANTHROPIC_API_KEY | -- | 需要时 LLM_BACKEND=claude | ||
CLAUDE_MODEL | claude-sonnet-4-6 | 人体模型ID | ||
OLLAMA_BASE_URL | http://localhost:11434 | Ollama服务器URL | ||
OLLAMA_MODEL | llama3.2 | 任何通过拉取的模型 ollama pull | ||
OPENAI_API_KEY | -- | 需要时 LLM_BACKEND=openai_compatible | ||
OPENAI_BASE_URL | https://api.openai.com/v1 | 任何与OpenAI兼容的端点URL | ||
OPENAI_MODEL | gpt-4o-mini | 端点处的模型名称 | ||
LLM_MAX_TOKENS | 2048 | LLM完成的最大令牌数 | ||
LLM_TEMPERATURE | 0.3 | 发电温度 | ||
ANOMALY_THRESHOLD | 0.5 | 攻击置信阈值(0.0–1.0) | ||
RESPONSE_API_URL | - | 用于自动执行的网络管理API(可选) | ||
RESPONSE_API_KEY | - | 响应API的承载令牌(可选) | ||
MCP_PORT | 8000 | 服务器端口 | ||
LOG_LEVEL | INFO | 日志记录级别 |
______________________________________________________________________
数据集
NCSRD-DS-5GDOS v3.0 — DOI:10.5281/zenodo.13900057
| 文件 | 大小 | 描述 |
|---|---|---|
amari_ue_data_merged_with_attack_number.csv | 241.5毫巴 | 主ML文件 --标记,6类 |
amari_ue_data_classic_tabular.csv | 143.6 MB | UE指标,经典小区 |
amari_ue_data_mini_tabular.csv | 87.3 MB | UE指标,迷你小区 |
enb_counters_data_classic_tabular.csv | 72.2 MB | 小区级eNB计数器 |
enb_counters_data_mini_tabular.csv | 38.2 MB | 迷你手机计数器 |
mme_counters.csv | 37.1 MB | NAS层MME计数器 |
summary_report.xlsx | 18.0 kB | 每个UE的攻击摘要 |
攻击标签(attack_number 列): 0 良性· 1 SYN洪水· 2 UDP洪水· 3 ICMP洪水· 4 DNS洪水· 5 GTP-U洪水
______________________________________________________________________
项目对齐
| 欧盟项目 | 一体化 |
|---|---|
| 海 | 5G安全的代理人工智能 |
______________________________________________________________________
引用
@dataset{ncsrd_5gddos_2024,
title = {NCSRD-DS-5GDDoS: 5G Radio & Core Metrics -- DDoS Attack Dataset},
author = {NCSRD and Space Hellas},
year = {2024},
doi = {10.5281/zenodo.13900057},
publisher = {Zenodo},
license = {CC BY 4.0},
note = {EU Horizon PRIVATEER project, Grant 101096110}
}______________________________________________________________________
许可证
MCP服务器代码:MIT。数据集:CC BY 4.0(引用上面的DOI)。
