kagioneko/ai-red-teaming-engine

GitHub: kagioneko/ai-red-teaming-engine

融合静态分析与LLM语义理解的对抗性安全审计引擎,支持AI系统特有的Prompt注入和记忆投毒测试。

Stars: 0 | Forks: 0

# AI-Red-Teaming-Engine **面向防御的对抗性安全审计引擎** [![CI](https://github.com/kagioneko/ai-red-teaming-engine/actions/workflows/security-audit.yml/badge.svg)](https://github.com/kagioneko/ai-red-teaming-engine/actions) [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![SARIF](https://img.shields.io/badge/output-SARIF%202.1.0-orange)](https://sarifweb.azurewebsites.net/) 这是一款用 Python 构建的工具,旨在从“攻击者的视角”重新审视代码、规范文档和 AI Agent 设计。 它结合了 **Semgrep / Gitleaks 的静态分析** 与 **LLM(Claude / Gemini)的上下文分析**, 实现了比单一工具更高的检测精度。 ## 特征 | 功能 | 说明 | |------|------| | 🔍 **混合解析** | Semgrep + Gitleaks + LLM 三层检测 | | 📂 **目录批量审计** | 通过 `--dir src/` 递归扫描多个文件 | | 📋 **SARIF 2.1.0 输出** | 直接在 GitHub Security Tab / VS Code 中显示 | | 🤖 **4 Agent 高精度审计** | 通过 Attacker → Skeptic → Defender → Judge 流程减少误报 | | 💉 **Prompt Injection 测试** | 使用 13 种 Payload 评估 LLM 系统的注入抵抗力 | | 🧠 **Memory Poisoning 耐受性测试** | 通过静态分析 + LLM 检测 RAG 和向量数据库的污染路径 | | 🔀 **后端对比** | 可视化 Claude 与 Gemini 的检测差异 | | 🚫 **排除规则** | 通过 `.redteam-ignore` 管理噪音 | | 🔁 **差异追踪** | 通过 `--baseline` 检测与上次的 regression(回归) | | ⚙️ **CI/CD 支持** | 附带 GitHub Actions 工作流 | ## 安装 ### 依赖包 ``` pip install click pydantic anthropic ``` ### 静态分析工具(推荐) ``` # Semgrep pip install semgrep # Gitleaks(Linux) wget -qO- https://github.com/gitleaks/gitleaks/releases/latest/download/gitleaks_linux_x64.tar.gz | tar xz sudo mv gitleaks /usr/local/bin/ ``` ### LLM 后端 推荐使用无需 API Key 的 **Claude Code CLI**: ``` # Claude Code CLI がインストール済みなら追加設定不要 claude --version # 或 Anthropic API 密钥 export ANTHROPIC_API_KEY="sk-ant-..." ``` ## 快速开始 ``` git clone https://github.com/kagioneko/ai-red-teaming-engine.git cd ai-red-teaming-engine # 単一ファイルを監査 python engine.py --file app.py --backend claude # ディレクトリ丸ごと監査 python engine.py --dir src/ --backend claude # GitHub Security Tab 用 SARIF 出力 python engine.py --dir src/ --format sarif -o results.sarif ``` ## 主要选项 ``` --file / --dir 監査対象(ファイル or ディレクトリ) --mode safe / deep(default)/ agent-audit / patch --backend claude / gemini / codex / api --format text / json / sarif / both --output / -o 出力ファイルパス --fail-on Critical/High/Medium 以上で exit 1(CI用) --multi-agent 4エージェント高精度監査 --injection-test Prompt Injection シミュレーション --memory-poison Memory Poisoning 耐性試験 --compare 複数バックエンド比較 --baseline 前回結果との差分追跡 --save-baseline 今回結果を次回比較用に保存 --no-static Semgrep/Gitleaks をスキップ ``` 详情请参阅 [GUIDE.md](GUIDE.md)。 ## 使用示例 ``` # 通常の深度監査(デフォルト) python engine.py --file api.py --backend claude # 高精度監査(4エージェント、時間がかかる) python engine.py --file api.py --multi-agent --backend claude # AI Agent 的 Prompt Injection 测试 python engine.py --file agent.py --injection-test --backend claude # RAGシステムのMemory Poisoning 耐性試験 python engine.py --file rag_system.py --memory-poison --backend claude # CI/CD: High以上で失敗・SARIF出力 python engine.py --dir src/ --format sarif -o results.sarif --fail-on High # 2回目以降: 前回との差分のみ確認 python engine.py --dir src/ --baseline prev.json --save-baseline prev.json --mode patch ``` ## 通过 GitHub Actions 进行自动审计 请参考 `.github/workflows/security-audit.yml`。 1. 将 `ANTHROPIC_API_KEY` 注册到 GitHub Secrets 2. 在 push / PR 时自动执行审计 3. 指出的问题将显示在 **Security 标签页 → Code scanning** 中 详情请参阅 [GUIDE.md#CI](GUIDE.md#cicd-への組み込み)。 ## 审计模式 | 模式 | 用途 | |--------|------| | `deep` | 彻底调查(默认) | | `safe` | 面向生产环境部署・误报较少 | | `agent-audit` | 专注于 AI / LLM Agent | | `patch` | 仅重新审计与上次的差异 | ## 排除规则 复制 `.redteam-ignore.example` 并将其放置为 `.redteam-ignore`: ``` tests/ # ディレクトリ除外 *.generated.py # glob パターン severity:Info # severity 単位除外 category:CORS # カテゴリ単位除外 fingerprint:abc123 # 既知誤検知を固定除外 rule:RTE-Auth-Low # SARIF ruleId 形式 ``` ## 架构 ``` engine.py (CLI) └── redteam/ ├── pipeline.py # 4層パイプライン統合 ├── multi_agent.py # Attacker/Skeptic/Defender/Judge ├── prompt_injection.py # Prompt Injection シミュレータ ├── memory_poisoning.py # Memory Poisoning 耐性試験 ├── comparator.py # バックエンド比較 ├── ignorer.py # .redteam-ignore 解析 ├── static_tools.py # Semgrep + Gitleaks ├── analyzer.py # LLM 敵対的分析 ├── fixer.py # 修正案生成 ├── scorer.py # 優先度スコアリング ├── formatters.py # JSON / Markdown / SARIF 出力 └── llm_client.py # 統一 LLM クライアント ``` ## 许可证 MIT License — 请仅用于防御和教育目的。 禁止用于自己拥有或获得许可的系统以外的任何系统。
标签:AI红队, CI/CD安全, Claude, CVE检测, DevSecOps, DNS 反向解析, Gemini, GitHub Actions, Gitleaks, Llama, LLM, Prompt注入, PyRIT, Python, RAG安全, Red Canary, SARIF, SAST, Semgrep, Unmanaged PE, WordPress安全扫描, 上游代理, 多智能体系统, 大模型安全, 攻击模拟, 无后门, 混合分析, 盲注攻击, 自动化渗透测试, 自动笔记, 误报过滤, 逆向工具, 配置审计, 错误基检测, 防御性安全, 静态代码分析, 驱动签名利用