B2TheEe/vulnerable-ai-agent-lab

GitHub: B2TheEe/vulnerable-ai-agent-lab

一个故意设计为不安全的 LLM Agent 实验环境,用于练习 AI 红队攻防并量化评估多层防御策略对 OWASP LLM Top 10 攻击的拦截效果。

Stars: 0 | Forks: 0

# 漏洞 AI Agent 实验环境 ![Python](https://img.shields.io/badge/python-3.12-blue.svg) ![Ollama](https://img.shields.io/badge/Ollama-llama3.1%20%7C%20qwen2.5-black) ![OWASP](https://img.shields.io/badge/OWASP-LLM%20Top%2010-red) ![Status](https://img.shields.io/badge/status-week%203%20complete-brightgreen) ![Educational](https://img.shields.io/badge/use-educational%20only-orange) ![License](https://img.shields.io/badge/license-MIT-lightgrey) 一个故意设计为不安全的 LLM agent,用于练习 prompt injection、 tool abuse、通过 AI 工具进行 RCE/LFI/SSRF,并与 OWASP LLM Top 10 进行映射。 ## 状态 | 周 | 挑战 | OWASP LLM | 测试模型 | Stack 拦截率 (最佳防御) | Writeup | |------|------------------------------------|-------------|------------------------|-----------------------------------------|----------------------------------| | 1 | 通过 Direct Prompt Injection 进行 RCE | LLM01 | llama3.1:8b, qwen2.5:7b | **−85 %** (使用 regex+judge+allowlist 后 2/30 PWNED) | [docs/results-week1.md](docs/results-week1.md) | | 2 | 通过 File-Read Tool 进行 LFI | LLM06 | llama3.1:8b, qwen2.5:7b | **−100 %** (使用 regex+judge+path_allowlist 后 0/16 PWNED) | [docs/results-week2.md](docs/results-week2.md) | | 3 | 通过 HTTP-Fetch Tool 进行 SSRF | LLM01+LLM02 | llama3.1:8b, qwen2.5:7b | **−100 %** (使用 regex+judge+url_allowlist 后 0/16 PWNED) | [docs/results-week3.md](docs/results-week3.md) | | 4 | 通过 Web Browse 进行 Indirect Injection | LLM01 | — | — | — | **第 1→2→3 周的主要洞察:** 相同的 `allowlist` 防御从 -50 % 的降低(第 1 周,shell-tool)变成了 **0 % 的降低**(第 2 周 file_read,第 3 周 http_fetch), 纯粹是因为改变了 tool-context。通过数据三次确认: 防御必须**按工具**设计,而不是按应用。第 3 周的额外发现: **tool-confusion** — 一个适用于某个工具的防御如果没有覆盖其他 工具,只会将模型推向未受防御的工具 ([docs/results-week3.md §2](docs/results-week3.md))。 ## 快速开始 ``` # 1. Ollama 安装(一次性) curl -fsSL https://ollama.com/install.sh | sh ollama pull llama3.1:8b ollama pull qwen2.5:7b # voor cross-model vergelijking # 2. Python 环境 python -m venv venv source venv/bin/activate pip install -r requirements.txt # 3. 交互式 REPL python -m agent.main # 4. 一次性输出整个 payload 矩阵(第3周及以后): python -m tests.run_payloads challenges/02-lfi-via-file-read/payloads.yaml \ --models llama3.1:8b,qwen2.5:7b \ --defenses all \ --out-prefix results-week2 python -m tests.summarize_results results-week2-*.txt ``` ## 挑战 | # | 名称 | OWASP LLM | 难度 | 状态 | |---|------|-----------|------------|--------| | 01 | 通过 Direct Prompt Injection 进行 RCE | LLM01 | ⭐ | ✅ 完成 | | 02 | 通过 File-Read Tool 进行 LFI | LLM06 | ⭐⭐ | ✅ 完成 | | 03 | 通过 HTTP-Fetch Tool 进行 SSRF | LLM01+LLM02 | ⭐⭐ | ✅ 完成 | | 04 | 通过 Web Browse 进行 Indirect Injection *(第 4 周)* | LLM01 | ⭐⭐⭐ | ⏳ 计划中 | | 05 | 通过 Markdown Rendering 进行 Data Exfil *(第 4 周)* | LLM02 | ⭐⭐ | ⏳ 计划中 | ## 防御层 | 层级 | 名称 | 作用于 | 引入于 | |-------|-----------------|--------------------|----------------| | 1 | `regex` | user input | 第 1 周 | | 2 | `judge` | user input (LLM) | 第 1 周 | | 3 | `allowlist` | shell binary | 第 1 周 | | 4 | `path_allowlist`| file_read path | 第 2 周 | | 5 | `url_allowlist` | http_fetch URL | 第 3 周 | | stack | 全部组合 | input + tool | 第 1 周 (在第 2 周和第 3 周扩展) | ## 架构 ``` user ──► main.py (REPL) ──► LLMClient (Ollama) │ │ │◄─── tool_calls ──────┘ ▼ AVAILABLE_TOOLS │ ┌──────┼─────────┐ ▼ ▼ ▼ execute_shell read_file (week 3: http_fetch) ▲ ▲ │ │ defenses: regex (L1) → judge (L2) → allowlist (L3) → path_allowlist (L4) ``` ## 仓库布局 ``` agent/ # LLM-client, tools, defenses, REPL challenges/ # per challenge: README + payloads.yaml 01-rce-via-shell/ 02-lfi-via-file-read/ tests/ run_payloads.py # bulk runner (single + matrix mode) merge_results.py # txt → yaml verdicts terug-merge summarize_results.py # PWNED-matrix print docs/ # weekly writeups + cross-challenge analyse ``` ## Writeups - [`docs/blog-post-week3-tool-confusion.md`](docs/blog-post-week3-tool-confusion.md) — 第 3 周 tool-confusion 发现(`url_allowlist` 未被绕过;模型 转向了 `execute_shell`)。英语,约 450 字。 - [`docs/blog-post-week3-tool-confusion-nl.md`](docs/blog-post-week3-tool-confusion-nl.md) — 上述内容的荷兰语版本。 ## 免责声明 本项目旨在教导防御者和渗透测试人员 agentic LLM 系统是如何 失效的。请勿将其用于未经明确许可的系统。
标签:AI安全, AI风险缓解, Chat Copilot, CISA项目, DLL 劫持, Python, 大语言模型, 安全靶场, 数据展示, 无后门, 红队, 网络安全审计, 逆向工具