gfelobes/llm-redteam-helixpay

GitHub: gfelobes/llm-redteam-helixpay

该项目通过对一个故意脆弱的LLM客服代理进行红队测试与加固,演示了LLM应用中提示注入等漏洞的攻防全流程。

Stars: 0 | Forks: 0

## 目标:“HelixPay” | 文件 | 用途 | |------|------------| | [`app/vulnerable_app.py`](app/vulnerable_app.py) | 幼稚的“将 LLM 连接到工具”的构建版本。prompt 中包含 secret,检索到的内容被拼接到 context 中,tool calls 被原封不动地执行,输出以原始格式返回。 | | [`app/hardened_app.py`](app/hardened_app.py) | 相同的模型,相同的工具——但被 [`app/defenses.py`](app/defenses.py) 中的控制措施所包裹:输入 guardrail、spotlighting、**代码强制 tool authorization** 以及输出 sanitization。 | 如果你只读一个文件,那就读 [`app/defenses.py`](app/defenses.py) — 以真实代码形式呈现的缓解措施。 ## 快速开始 ``` # No dependencies, no API key — the default backend is a deterministic offline # model that reproduces documented LLM failure modes. python -m redteam.runner # runs 11 probes against both apps, writes results/ python -m unittest # 12 tests proving the mitigations hold ``` 试玩一下: ``` python scripts/demo.py --agent vulnerable --attack P07 # watch an attack land python scripts/demo.py --agent hardened --attack P07 # watch it get blocked python scripts/demo.py --agent hardened # interactive chat ``` ### 针对真实模型运行它 所有的攻击和防御也都可以在真实的 Claude API 上运行——无需修改代码: ``` pip install anthropic export ANTHROPIC_API_KEY=sk-... HELIX_BACKEND=live python -m redteam.runner ``` ## 离线后端为何是合理的 这里演示的漏洞存在于**应用程序**中——缺少 tool authorization,context 中存在 secret,将不受信任的内容视为指令, 未转义的输出——而**不是**存在于模型的权重中。离线后端 ([`app/model.py`](app/model.py))是一个脚本化的替代品,能可靠地重现 攻击者从真实的 LLM 中诱骗出的行为(遵循注入的指令, 泄露其 prompt,过度调用工具)。这让任何审查者都能在无需密钥和无需网络的情况下, 逐字重现每一个发现——并且让测试框架能够证明 **无论背后是哪种模型,防御措施都能起作用**。切换 `HELIX_BACKEND=live` 以确认相同的控制措施在面对真实模型时依然有效。 ## 目录结构 ``` app/ model.py # backend: offline mock (default) + live Claude API vulnerable_app.py # the target — intentionally insecure hardened_app.py # the fix — same model, wrapped in controls defenses.py # ★ the mitigations, as reusable code tools.py # tools + fake datastore + side-effect ledger knowledge_base.py # RAG docs incl. one poisoned support ticket redteam/ probes.py # the attack catalog (11 probes, OWASP-mapped) scorer.py # impact-based success detection runner.py # runs probes vs both apps → results/ report.py # renders the comparison table tests/ # unittest suite (no third-party deps) scripts/demo.py # interactive / one-shot CLI results/ # generated findings.json + results.md (checked in) REPORT.md # ★ the red-team report ``` ## 范围与道德规范 这是一个防御性安全的教学产物,针对的是作者控制的虚构应用程序。 所谓的“攻击”是 prompt-injection 和访问控制的测试用例;其核心在于 缓解措施。请勿将此测试框架指向你未经授权测试的系统。
标签:逆向工具