Jeanmatozo/AI-security-training-lab
GitHub: Jeanmatozo/AI-security-training-lab
一个专业级AI安全训练实验室,提供针对LLM、RAG和Agent系统的实战靶场、结构化攻击剧本及审计级证据采集与报告生成流程。
Stars: 0 | Forks: 0
# AI-security-training-lab
一个专业的 AI 安全训练实验室,用于对 LLM、RAG 和基于 Agent 的系统进行实战测试——包含结构化的攻击 playbook、证据采集管道以及咨询级的报告工作流。
本实验室重点关注以下领域的现实世界漏洞:
- 大语言模型
- 检索增强生成 (RAG) 系统
- AI Agent 和启用工具的模型
攻击覆盖范围与 **OWASP Top 10 for LLM Applications (2025)** 保持一致,并映射到 **MITRE ATLAS** 对抗技术 ID。
目标是建立一个**可重复、有证据支撑的框架**——而不仅仅是一堆 prompt 集合。每次攻击都会生成一个签名 artifact,可向前追溯到发现报告。
## 实现状态
| 组件 | 状态 | 备注 |
|---|---|---|
| `environments/chatbot` | ✅ 功能正常 | FastAPI,存在 intentional vulnerabilities |
| `environments/rag-pipeline` | ✅ 功能正常 | LangChain + ChromaDB,命名卷 |
| `environments/agent` | ✅ 功能正常 | 启用工具,存在 SSRF 向量 |
| `attacks/prompt-injection` | ✅ 功能正常 | 直接、间接、越狱、SPE payload |
| `attacks/rag-attacks` | ✅ 功能正常 | 投毒 + 上下文操纵 |
| `attacks/agent-attacks` | ✅ 功能正常 | 工具滥用 + 权限提升 |
| `tools/fuzzer.py` | ✅ 功能正常 | 运行所有 payloads.json 文件 |
| `tools/collect_evidence.py` | ✅ 功能正常 | SHA-256 签名,证据提升 |
| `playbooks/` | ✅ 完成 | LLM01, LLM03, LLM08 + 2 条攻击链 |
| `reports/findings/` | 🔄 进行中 | 正在记录第一个发现 |
## 仓库结构
```
AI-security-training-lab/
├── README.md
├── LICENSE
├── .gitignore
├── .env.example
├── docker-compose.yml # chatbot + rag-pipeline + agent
│ # lab-internal + lab-external networks
│ # rag-vector-store named volume
│
├── environments/
│ ├── chatbot/
│ │ ├── app.py
│ │ ├── Dockerfile
│ │ ├── requirements.txt
│ │ ├── prompts/
│ │ └── memory/ # Bind-mounted JSONL session store
│ │
│ ├── rag-pipeline/
│ │ ├── ingest.py
│ │ ├── rag_api.py
│ │ ├── Dockerfile
│ │ └── requirements.txt
│ │
│ └── agent/
│ ├── agent.py
│ ├── Dockerfile
│ ├── requirements.txt
│ └── tools/ # tool.py + tool.schema.json pairs
│
├── attacks/
│ ├── README.md # Payload schema + ID prefix table
│ ├── prompt-injection/
│ │ ├── payloads.json # Direct, indirect, jailbreak, SPE
│ │ └── payloads.md
│ ├── rag-attacks/
│ │ ├── payloads.json
│ │ └── payloads.md
│ └── agent-attacks/
│ ├── payloads.json
│ └── payloads.md
│
├── tools/
│ ├── fuzzer.py # payloads.json → artifacts/results/
│ └── collect_evidence.py # artifacts/results/ → evidence/transcripts/
│
├── playbooks/
│ ├── LLM01-prompt-injection.md
│ ├── LLM03-training-data-poisoning.md
│ ├── LLM08-excessive-agency.md
│ └── chains/
│ ├── chain-01-rag-exfiltration.md
│ └── chain-02-agent-escalation.md
│
├── methodology/
│ ├── attack-surface-map.md # OWASP coverage matrix + NIST AI RMF mapping
│ ├── threat-model.md
│ └── rules-of-engagement.md
│
├── artifacts/
│ └── results/ # Raw fuzzer output — never cited directly in reports
│
├── evidence/
│ ├── transcripts/ # SHA-256 signed, promoted by collect_evidence.py
│ └── screenshots/
│
└── reports/
├── templates/
│ └── finding-template.md
└── findings/ # Completed reports: AI-SEC-YYYY-NNN.md
```
## 证据管道
自动输出和审计就绪的证据被严格分开:
```
attacks/*/payloads.json
→ tools/fuzzer.py
→ artifacts/results/ ← raw output, never cited directly
→ tools/collect_evidence.py ← SHA-256 hash + metadata header
→ evidence/transcripts/ ← signed, reportable
→ reports/findings/ ← cites evidence ID
```
`collect_evidence.py` 是唯一写入 `evidence/` 的机制。
原始 artifact 留在 `artifacts/results/` 中,直到经过审查并提升。
## 快速入门
### 克隆仓库
```
git clone https://github.com/Jeanmatozo/AI-security-training-lab.git
cd AI-security-training-lab
```
### 选项 1 — Docker (推荐)
**前置条件:** [Docker Desktop](https://www.docker.com/products/docker-desktop/) (macOS / Windows) 或 Docker Engine (Linux),在继续之前保持运行。
**1. 复制并配置环境文件**
```
cp .env.example .env
```
在启动容器之前打开 `.env` 并设置你的 API key:
```
OPENAI_API_KEY=your_api_key_here
MODEL_NAME=gpt-4.1-mini
```
**2. 构建并启动所有环境**
```
docker-compose up --build
```
当所有三个服务准备就绪时,你会看到类似以下的行:
```
chatbot | INFO: Uvicorn running on http://0.0.0.0:8000
rag-pipeline | INFO: Uvicorn running on http://0.0.0.0:8001
agent | INFO: Uvicorn running on http://0.0.0.0:8002
```
三个实验室环境现已在以下地址运行:
- Chatbot — `http://localhost:8000/docs`
- RAG pipeline — `http://localhost:8001/docs`
- Agent — `http://localhost:8002/docs`
**3. 停止环境**
```
docker-compose down # stops containers, preserves RAG vector store
docker-compose down -v # stops containers AND wipes the vector store
```
### 选项 2 — 本地,单环境 (无需 Docker)
**前置条件:** Python 3.10 或更高版本
**1. 复制环境文件**
从仓库根目录:
```
cp .env.example .env
```
打开 `.env` 并设置你的 API key:
```
OPENAI_API_KEY=your_api_key_here
MODEL_NAME=gpt-4.1-mini
```
**2. 创建虚拟环境**
```
python -m venv .venv
source .venv/bin/activate # macOS / Linux
.venv\Scripts\activate # Windows
```
**3. 安装依赖**
```
cd environments/chatbot
pip install -r requirements.txt
```
**4. 启动服务器**
```
uvicorn app:app --reload
```
你应该看到:
```
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process
```
**5. 打开攻击界面**
访问 `http://127.0.0.1:8000/docs` ——这将打开 FastAPI Swagger UI,你可以在其中手动发送 prompt 并观察模型响应。
你现在已准备好运行 prompt injection playbook:
`playbooks/LLM01-prompt-injection.md`
## 运行攻击
```
# 运行所有 prompt injection payloads 针对 chatbot
python tools/fuzzer.py \
--payloads attacks/prompt-injection/payloads.json \
--output artifacts/results/PI_$(date +%Y%m%d_%H%M%S).json
# 将结果提升为 signed evidence
python tools/collect_evidence.py \
--input artifacts/results/PI_20250115_143022.json \
--output evidence/transcripts/
```
## 涵盖的实验室主题
- **Prompt injection** — 直接注入,通过 RAG 进行的间接注入,越狱
- **RAG exploitation** — 文档投毒,上下文操纵,检索滥用
- **Agent tool abuse** — 工具误用,通过 HTTP 工具进行的 SSRF,权限提升
- **Multi-step attack chains** — 跨环境的现实对抗序列
## 使用的工具
| 类别 | 技术 |
|---|---|
| 语言 | Python |
| API framework | FastAPI |
| 容器化 | Docker + Docker Compose |
| LLM orchestration | LangChain |
| Vector store | ChromaDB |
| LLM provider | OpenAI API |
| 攻击运行器 | `tools/fuzzer.py` (自定义) |
| 证据 pipeline | `tools/collect_evidence.py` (自定义) |
## 负责任的使用
本仓库仅用于**教育和防御性安全研究目的**。
所有测试必须在获得明确授权的隔离、受控环境中进行。请勿将这些技术用于你不拥有或未获得测试许可的系统。
## 许可证
MIT License — 详情见 `LICENSE`。
## 致谢
- [OWASP Top 10 for LLM Applications (2025)](https://owasp.org/www-project-top-10-for-large-language-model-applications/)
- [MITRE ATLAS](https://atlas.mitre.org/)
- [NIST AI Risk Management Framework](https://www.nist.gov/itl/ai-risk-management-framework))
由 [jeanmatozo](https://github.com/Jeanmatozo) 构建
标签:AI安全, AV绕过, Chat Copilot, ChromaDB, Docker, ESC漏洞, FastAPI, LangChain, MITRE ATLAS, OPA, OWASP Top 10, Petitpotam, RAG安全, Red Canary, SSRF, TGT, 人工智能, 大语言模型安全, 安全合规, 安全培训, 安全实验室, 安全防御评估, 攻防演练, 智能体安全, 机密管理, 权限管理, 模型越狱, 版权保护, 用户模式Hook绕过, 网络代理, 网络安全, 证据收集, 请求拦截, 轻量级, 逆向工具, 配置审计, 隐私保护, 靶场