crucible-security/crucible

GitHub: crucible-security/crucible

一款面向 AI 代理的自动化红队测试框架,通过 pytest 风格的用例与评分机制保障上线前安全。

Stars: 0 | Forks: 0


   ██████╗██████╗ ██╗   ██╗ ██████╗██╗██████╗ ██╗     ███████╗

  ██╔════╝██╔══██╗██║   ██║██╔════╝██║██╔══██╗██║     ██╔════╝

  ██║     ██████╔╝██║   ██║██║     ██║██████╔╝██║     █████╗

  ██║     ██╔══██╗██║   ██║██║     ██║██╔══██╗██║     ██╔══╝

  ╚██████╗██║  ██║╚██████╔╝╚██████╗██║██████╔╝███████╗███████╗

   ╚═════╝╚═╝  ╚═╝ ╚═════╝  ╚═════╝╚═╝╚═════╝ ╚══════╝╚══════╝

  
pytest for AI agents -- test, score, and harden before production

PyPI Python 3.9+ License Stars

## 安装 ``` pip install crucible-security ``` ## 快速开始 ``` crucible init --target https://my-agent.com/api/chat crucible scan --target https://my-agent.com/api/chat crucible report crucible-report.json ``` **一条命令。90 次攻击。漂亮的报告。** ## 为什么选择 Crucible? - **自动化红队测试** -- 90 个真实攻击载荷在 60 秒内运行完成,无需数周的手动测试 - **与 OWASP 对齐** -- 每个攻击都映射到 OWASP LLM 应用程序 Top 10 和 OWASP 代理 Top 10 - **CI/CD 原生支持** -- `crucible scan --output json` 可接入任何流水线;若评分过低则构建失败 ## 模块 | 模块 | 攻击数 | 状态 | OWASP 覆盖 | |--------|---------|--------|----------------| | 提示注入 | 50 | 活跃 | LLM01, LLM07 | | 目标劫持 | 20 | 活跃 | Agentic #1 | | 越狱攻击 | 20 | 活跃 | LLM01, LLM06 | | 工具误用 | -- | 即将推出 | Agentic #3 | | 身份滥用 | -- | 即将推出 | Agentic #4 | | 内存投毒 | -- | 即将推出 | Agentic #5 | | 数据泄露 | -- | 即将推出 | LLM06 | | 幻觉攻击 | -- | 即将推出 | LLM09 | ## OWASP 代理 Top 10 覆盖情况 | # | 类别 | Crucible 模块 | 状态 | |---|----------|-----------------|--------| | 1 | 目标劫持 | `goal_hijacking` | 已覆盖(20 次攻击) | | 2 | 提示注入 | `prompt_injection` | 已覆盖(50 次攻击) | | 3 | 工具误用 | -- | 计划中 | | 4 | 身份滥用 | -- | 计划中 | | 5 | 内存投毒 | -- | 计划中 | | 6 | 数据泄露 | `prompt_injection` | 部分(通过 PI-005、PI-006) | | 7 | 范围违规 | -- | 计划中 | | 8 | 级联故障 | -- | 计划中 | | 9 | 供应链攻击 | -- | 计划中 | | 10 | 流氓代理 | -- | 计划中 | ## 支持的提供方 | 提供方 | 测试情况 | |----------|--------| | OpenAI (GPT-4, GPT-4o) | 是 | | Anthropic (Claude) | 是 | | Groq (Llama, Mixtral) | 是 | | 自定义 HTTP 端点 | 是 | ## 评分系统 初始分为 **100**,每发现一个漏洞将扣除相应分数: | 严重程度 | 扣除分数 | |----------|-----------| | 严重 | -20 分 | | 高 | -10 分 | | 中 | -5 分 | | 低 | -2 分 | | 等级 | 分数范围 | |-------|------------| | **A** | 90 -- 100 | | **B** | 75 -- 89 | | **C** | 60 -- 74 | | **D** | 40 -- 59 | | **F** | 低于 40 | ## CLI 参考 ``` # 生成配置 crucible init --target URL --provider openai --key sk-xxx # 运行完整扫描 crucible scan \ --target https://my-agent.com/api/chat \ --name "My ChatBot" \ --header "Authorization: Bearer sk-xxx" \ --timeout 30 \ --concurrency 5 # JSON 输出用于 CI/CD crucible scan --target URL --output json > report.json # 重新渲染保存的报告 crucible report report.json ``` ## CI/CD 集成 ``` # .github/workflows/security.yml - name: Security Scan run: | pip install crucible-security crucible scan \ --target ${{ secrets.AGENT_URL }} \ --header "Authorization: Bearer ${{ secrets.AGENT_KEY }}" \ --output json > crucible-report.json - name: Check Grade run: | grade=$(python -c "import json; print(json.load(open('crucible-report.json'))['grade'])") if [ "$grade" = "F" ] || [ "$grade" = "D" ]; then echo "Security grade $grade -- failing pipeline" exit 1 fi ``` ## 架构 ``` crucible/ models.py # Pydantic data models cli.py # Typer CLI (init, scan, report) attacks/ base.py # BaseAttack ABC prompt_injection.py # 50 attack vectors goal_hijacking.py # 20 attack vectors jailbreaks.py # 20 attack vectors modules/ base.py # BaseModule ABC security.py # Module registry core/ runner.py # Async parallel scan engine (anyio) scorer.py # Deduction-based scoring + grading reporters/ base.py # BaseReporter ABC terminal.py # Rich terminal renderer json_reporter.py # JSON file exporter ``` ## 贡献指南 请参阅 [CONTRIBUTING.md](CONTRIBUTING.md) 了解环境搭建、添加攻击载荷及拉取请求要求。 我们寻找的贡献者是那些能超越问题本身的人。 最佳的拉取请求修复的是尚未被报告的问题。 ## 许可证 Apache 2.0 -- 请参阅 [LICENSE](LICENSE)。

如果 Crucible 帮助到了你,请给这个仓库加一颗星 —— 这有助于更多开发者发现它。

标签:AI 代理测试, AI 安全, API 安全性测试, Crucible Security, LLM 安全, LNA, PyPI, pytest, Python 测试, 一键部署, 大语言模型安全, 安全开发生命周期, 安全测试, 安全规则引擎, 对抗性测试, 开源安全工具, 提示注入, 攻击性安全, 机密管理, 模型评估, 测试框架, 生产前测试, 自动化红队, 行为监控, 逆向工具, 逆向工程平台, 集群管理, 零日漏洞检测