achrafElFaiq/ai-red-teaming-framework

GitHub: achrafElFaiq/ai-red-teaming-framework

一个模块化 LLM 红队框架,通过一次触发与多轮攻击系统化发现 AI 模型漏洞。

Stars: 0 | Forks: 0

# 红队框架 一个基于 Python 的框架,用于针对 HTTP/JSON 聊天机器人目标运行红队演练,使用 `PyRIT` 和 `Garak`,随后将结果标准化为统一的报告模型。 ## 概述 此仓库提供: - 基于 YAML 文件的演练驱动执行 - `PyRIT` 攻击(`dataset`、`crescendo`、`red_teaming`) - 基于 `Garak` 探针的攻击 - 写入 `reports/` 目录的标准化 JSON 报告 - 用于报告浏览的 Streamlit 仪表板 - CLI 命令:`run` 和 `dashboard` ## 支持的框架 - `pyrit` - `garak` ## 快速开始 ### 1. 安装 `uv`(如果尚未安装) ``` curl -LsSf https://astral.sh/uv/install.sh | sh ``` ### 2. 创建虚拟环境并安装 ``` uv venv .venv --python 3.13 source .venv/bin/activate uv pip install -e ".[dev]" ``` ### 3. 复制环境模板 ``` cp .env.example .env ``` 对于 PyRIT 演练,至少需要填写: ``` PYRIT_ATTACKER_ENDPOINT=... PYRIT_ATTACKER_MODEL=... PYRIT_ATTACKER_API_KEY=... PYRIT_SCORER_ENDPOINT=... PYRIT_SCORER_MODEL=... PYRIT_SCORER_API_KEY=... ``` ### 4. 运行演练 ``` redteaming run examples/campaigns/R1-prompt-leakage/prompt_leakage.yaml ``` 仓库入口点: ``` python main.py run examples/campaigns/R1-prompt-leakage/prompt_leakage.yaml ``` ## CLI ``` redteaming run redteaming dashboard ``` 实用的变体命令: ``` redteaming run campaigns/my_campaign.yaml --log-level DEBUG redteaming run campaigns/my_campaign.yaml --skip-checks redteaming run campaigns/my_campaign.yaml --no-dashboard redteaming dashboard ``` ## 演练模型 演练 YAML 定义了: - 一个目标 - 有序的攻击 YAML 文件列表 - 可选的演练元数据 参考模板位于: - `examples/templates/campaign.yaml` - `examples/templates/attack_pyrit_dataset.yaml` - `examples/templates/attack_pyrit_crescendo.yaml` - `examples/templates/attack_pyrit_red_teaming.yaml` - `examples/templates/attack_garak.yaml` ## 目标契约摘要 目前,目标被建模为 HTTP JSON 聊天 endpoint。 该框架发送: ``` { "": "" } ``` 并期望接收: ``` { "": "" } ``` 目前支持的目标特性: - HTTP POST 聊天 endpoint - 可配置的输入字段 - 可配置的输出字段 - 可选的重置 endpoint - 可选的元数据(`model`、`architecture_type`) 有关完整的目标契约,请参阅 `docs/target-contract.md`。 ## 架构概览 当前的高层结构: ``` src/redteaming/ ├── application/ # campaign loading, orchestration, health checks ├── domain/ # models and contracts ├── infrastructure/ # config, HTTP target, persistence ├── plugins/ # pyrit and garak integrations └── ui/ # streamlit dashboard ``` 执行流程: ``` campaign YAML → target + attack definitions → plugin runner execution (PyRIT / Garak) → normalized AttackResult objects → JSON reports in reports/ → dashboard analysis ``` ## 报告 标准化报告将写入: ``` reports/ ``` 报告模型记录于: - `docs/report-model.md` 仪表板会读取这些标准化的 JSON 文件。 ## 开发 运行完整的测试套件: ``` pytest -q ``` 示例: ``` pytest tests/frameworks/test_pyrit_runner.py -q pytest tests/frameworks/test_garak_runner.py -q ``` ## 限制 当前的假设和约束: - 目标仅限 HTTP/JSON 聊天 endpoint - 目标的请求/响应语义为简单的基于字段的 JSON - 特定框架的依赖项必须单独安装 - PyRIT 和 Garak 的执行模型有所不同,但都会被标准化到统一的报告层中 - 报告始终写入 `reports/` 目录 - Garak runtime 配置是内部的,并在 `.runtime/` 目录下自动生成 ## 仓库结构 建议优先阅读的顶层目录: - `src/redteaming/` - `examples/` - `docs/` - `schemas/` - `tests/` ## 文档 如需了解更深入的细节,请参阅: - `docs/architecture.md` - `docs/campaign-spec.md` - `docs/target-contract.md` - `docs/report-model.md` - `docs/plugin-development.md`
标签:AES-256, AI安全, Chat Copilot, LLM测试, Python, 无后门, 漏洞评估, 红队工具