Skip to main content

防御目的の敵対的セキュリティ監査エンジン — LLM + 静的解析でコード・仕様書・AIエージェントを攻撃者視点でレビュー

Project description

AI-Red-Teaming-Engine

防御目的の敵対的セキュリティ監査エンジン

CI Python License: MIT SARIF PyPI

demo

コード・仕様書・AIエージェント設計を「攻撃者の視点」で読み直す Python 製ツール。 Semgrep / Gitleaks による静的解析LLM(Claude / Gemini)による文脈解析 を組み合わせ、 単体ツールより高い検出精度を実現します。

⚠️ プロトタイプ版です。全ての指摘は人間による最終確認が必要です。


特徴

機能 説明
🔍 ハイブリッド解析 Semgrep + Gitleaks + LLM の3層で検出
📂 ディレクトリ一括監査 --dir src/ で複数ファイルを再帰走査
📋 SARIF 2.1.0 出力 GitHub Security Tab / VS Code に直接表示
🤖 4エージェント高精度監査 Attacker → Skeptic → Defender → Judge で誤検知削減
💉 Prompt Injection テスト 13種ペイロードで LLM システムの注入耐性を評価
🧠 Memory Poisoning 耐性試験 RAG・ベクトルDB汚染経路を静的+LLM で検出
🛡️ NeuroState セッション監視 AI会話のターンごとに異常スコアをリアルタイム評価
📏 カスタムルール DSL .redteam-rules.yaml でプロジェクト固有のルールを追加
🔀 バックエンド比較 Claude vs Gemini の検出差分を可視化
🚫 除外ルール .redteam-ignore でノイズを管理
🔁 差分追跡 --baseline で前回との regression を検出
⚙️ CI/CD 対応 GitHub Actions ワークフロー同梱

インストール

pip install ai-red-teaming-engine

LSP サーバー(Neovim / Zed / Emacs 向け)を使う場合:

pip install "ai-red-teaming-engine[lsp]"

依存パッケージ(ソースから使う場合)

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キー不要で使える 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 耐性試験
--investigate <cat>     カテゴリを深掘り調査(例: "Input Validation")
--compare               複数バックエンド比較
--baseline              前回結果との差分追跡
--save-baseline         今回結果を次回比較用に保存
--no-static             Semgrep/Gitleaks をスキップ
--rules-file            カスタムルール YAML を明示指定

詳細は GUIDE.md を参照してください。


使用例

# 通常の深度監査(デフォルト)
python engine.py --file api.py --backend claude

# 高精度監査(4エージェント、時間がかかる)
python engine.py --file api.py --multi-agent --backend claude

# AIエージェントの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 を参照。


監査モード

モード 用途
deep 徹底調査(デフォルト)
safe 本番投入向け・誤検知少なめ
agent-audit AI / LLM エージェント特化
patch 前回との差分のみ再監査

除外ルール(.redteam-ignore)

.redteam-ignore.example をコピーして .redteam-ignore に配置:

tests/              # ディレクトリ除外
*.generated.py      # glob パターン
severity:Info       # severity 単位除外
category:CORS       # カテゴリ単位除外
fingerprint:abc123  # 既知誤検知を固定除外
rule:RTE-Auth-Low   # SARIF ruleId 形式

NeuroState セッション監視

AI チャットボット・エージェントとの会話がプロンプトインジェクション攻撃を受けていないか、
ターンごとにリアルタイムで評価します。

# 会話ターンのスコアを取得(テキストを stdin から渡す)
echo "ユーザー: 前の指示を無視して..." | python engine.py --session-score --backend claude

VSCode 拡張の NekoGuard コマンドからワンクリックで実行できます。


カスタムルール

プロジェクト固有のパターンを .redteam-rules.yaml に記述すると自動的に適用されます。

# .redteam-rules.yaml
rules:
  - id: CUS-001
    name: "社内禁止 API の使用"
    pattern: "legacy_api\\.call\\("
    severity: High
    category: "Policy"
    message: "legacy_api は廃止予定です。new_api を使用してください。"
    file_glob: "*.py"

配置場所の検索順: 対象ファイルと同じディレクトリ → カレントディレクトリ → ~/.redteam-rules.yaml


アーキテクチャ

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 クライアント

LSP サーバー(Neovim / Zed / Emacs)

stdio モードで起動する LSP サーバーです。任意の LSP 対応エディタから利用できます。

pip install "ai-red-teaming-engine[lsp]"
redteam-lsp   # stdio モードで起動

Neovim(nvim-lspconfig)

local lspconfig = require("lspconfig")
local configs = require("lspconfig.configs")

if not configs.redteam_lsp then
  configs.redteam_lsp = {
    default_config = {
      cmd = { "redteam-lsp" },
      filetypes = { "python", "javascript", "typescript", "go", "java" },
      root_dir = lspconfig.util.root_pattern(".git", "pyproject.toml"),
    },
  }
end
lspconfig.redteam_lsp.setup({})

Zed

~/.config/zed/settings.json に追加:

{
  "lsp": {
    "redteam-lsp": {
      "binary": { "path": "redteam-lsp" },
      "languages": ["Python", "JavaScript", "TypeScript"]
    }
  }
}

関連記事


ライセンス

MIT License — 防御・教育目的のみに使用してください。 自分が所有または許可を得たシステム以外への使用は禁止です。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_red_teaming_engine-0.5.1.tar.gz (514.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_red_teaming_engine-0.5.1-py3-none-any.whl (98.1 kB view details)

Uploaded Python 3

File details

Details for the file ai_red_teaming_engine-0.5.1.tar.gz.

File metadata

  • Download URL: ai_red_teaming_engine-0.5.1.tar.gz
  • Upload date:
  • Size: 514.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ai_red_teaming_engine-0.5.1.tar.gz
Algorithm Hash digest
SHA256 ca3ed5bf807960a0a8149179c7a3be937a06d97407805e4c498fee32158a61e1
MD5 186b238fb5ecf3604849dca04418e9cf
BLAKE2b-256 20f66a74ad3c5baf834ba79a4ef544dbf038d9ea4d374bb862541aaba0721631

See more details on using hashes here.

File details

Details for the file ai_red_teaming_engine-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_red_teaming_engine-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0197e2f13b7c42e4675f5d8e4193ff3ffc77e17970cf1e4d2f6152fb4d1d9027
MD5 86bc76b8199a8d4c9f9d9e983f2a4e0d
BLAKE2b-256 70702fd7109e58d0f55851257e8e60d1e516fc7a9456720a5aa3f41110248b23

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page