Skip to content
프로젝트

소개

승인된 평가를 위한 실전형 AI 침투 테스트 엔지니어입니다. AWS, Azure, GCP와 Alibaba Cloud, Tencent Cloud, Huawei Cloud를 지원하는 클라우드 모듈이 내장되어 있습니다. Claude Agent SDK를 기반으로 구축되었습니다.

보안 및 개인정보 보호

이 수치를 측정하는 방법

What you can do

  • 🎯 Real-world Focus: Business-logic flaws, auth chains, cloud misconfigurations
  • ☁️ Cloud Native: AWS / Azure / GCP / 阿里云 / 腾讯云 / 华为云 coverage
  • 🔒 Safety First: Read-only by default, scope enforcement, credential redaction
  • 🤖 AI-Powered: Claude Agent SDK with deterministic orchestration

측정된 스타 증가

in 24h
-1
in 7 days
+7
in 15 days
+11
in 1 month
+18

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Cain — Real-world AI Penetration Testing Engineer

CI

Cain is an AI penetration-testing engineer built for real-world authorized security assessments — not a CTF toy. It walks a deterministic attack pipeline, enforces scope with engineering constraints (not AI self-discipline), and ships a cloud penetration module covering AWS / Azure / GCP / 阿里云 / 腾讯云 / 华为云 — including the Chinese clouds nobody else covers.

🚧 Actively developed. Star & watch for updates.

Built on the Claude Agent SDK.


Why Cain

CTF/靶场型 Agent Cain (实战型)
Target Static labs, preset flags Real enterprise assets, bug bounty, authorized engagements
Vulnerability focus Known syntax-pattern vulns Business-logic flaws, auth chains, cloud misconfigurations
Environment No WAF, no rate limiting Real WAF / risk control with dynamic strategy adjustment
Deliverable A flag Auditable evidence chain + reproducible PoC + remediation advice

Features

  • 🎯 Real-world Focus: Business-logic flaws, auth chains, cloud misconfigurations
  • ☁️ Cloud Native: AWS / Azure / GCP / 阿里云 / 腾讯云 / 华为云 coverage
  • 🔒 Safety First: Read-only by default, scope enforcement, credential redaction
  • 🤖 AI-Powered: Claude Agent SDK with deterministic orchestration
  • 📊 Benchmark: self-built vulnerable-terraform evaluation, four-metric scoring
  • 🛡️ OWASP Top 10: SQLi, XSS, SSRF, CSRF, File Upload, XXE, Command Injection, Path Traversal

Quick Start

git clone https://github.com/cdxiaodong/cain-agent
cd cain-agent
pip install -e .          # or: uv pip install -e .
pip install -e ".[cloud]" # optional AWS S3, Huawei OBS, and Kubernetes checks

cain-agent --version

For AI Agents — One-Click Install Prompt

"安装 cain-agent 到用户本地 Python 环境,克隆仓库 https://github.com/cdxiaodong/cain-agent,用 pip/uv 装 editable 模式,验证 CLI 可执行"

This single prompt instructs any AI agent to:

  1. Clone the repository
  2. Install in editable mode (pip install -e . or uv pip install -e .)
  3. Verify installation by running cain-agent --version

Run against a target

The target is written into scope.yaml and enforced on every tool call:

cain-agent run \
  --target https://app.example.com \
  --total-budget 1800

Flags: --target (required) · --workspace (state dir, default ./workspace) · --total-budget (wall-clock seconds) · --idle-timeout (per-step seconds)

Choose an execution backend

Cain uses the default claude backend unless --backend pi is specified. The pi backend requires Node.js 20 or newer and a one-time bridge installation:

npm ci --prefix toolchain/pi
export ANTHROPIC_API_KEY="your-api-key"
cain-agent run --target https://app.example.com --backend pi

Choose another supported provider and model with --pi-provider and --pi-model; its standard API-key environment variable must be set (for example, OPENAI_API_KEY, GEMINI_API_KEY, DEEPSEEK_API_KEY, or OPENROUTER_API_KEY). For an Anthropic Messages-compatible gateway, set PI_BASE_URL and use ANTHROPIC_AUTH_TOKEN as its bearer credential:

export PI_BASE_URL="https://gateway.example.com"
export ANTHROPIC_AUTH_TOKEN="your-gateway-token"
cain-agent run --target https://app.example.com \
  --backend pi --pi-model your-gateway-model-id

See the pi bridge guide for the complete provider and gateway configuration.

Per-stage model routing

Reconnaissance is mostly repetitive enumeration, while the test stage needs a high-capability model for vulnerability judgment — the two discovery stages can each run their own engine and model:

# recon on the pi backend with a cheap gateway model, test keeps high-capability claude
cain-agent run --target https://app.example.com \
  --recon-backend pi --recon-provider anthropic --recon-model your-gateway-model-id \
  --test-backend claude

Flags and fallback rules:

  • --recon-backend / --test-backend: per-stage engine override (claude / pi), falling back to --backend;
  • --recon-provider / --recon-model, --test-provider / --test-model: provider and model of that stage's pi channel, falling back to --pi-provider / --pi-model respectively (ignored by the claude backend);
  • the report stage keeps its independent channel through the existing --pi-validation-provider / --pi-validation-model (likewise falling back to --pi-provider / --pi-model), so all three pipeline stages — recon / test / report — can be routed separately.

Behavioral guarantees:

  • Zero default change: with no --recon-* / --test-* flags at all, the two stages share the same discovery session — behavior identical to configuring --backend alone;
  • No scope downgrade: whatever the mix, every execution channel mounts the same ScopeGuardHook — hard scope enforcement and the finder≠validator dual-session semantics are fully preserved.

Output Artifacts

When a run finishes, the workspace report/ directory holds three artifacts:

  • report.md — the human-readable report: an executive summary (target / authorized scope / per-stage timings / finding counts), a findings table with severity markers, confidence, and evidence-chain digests, per-finding details, an evidence-hash index (evidence plaintext is never persisted — hashes only), per-issue-type remediation advice, and a legal disclaimer;
  • aggregated-report.json — the machine-readable aggregate (schema_version 1), same source data as report.md for downstream systems;
  • validation-summary.json — the validation-pipeline summary (four-state counts and failure details).

report.md is rendered by a pure-Python template (zero new dependencies) — same aggregate data in, same report out; see src/cain_agent/report_markdown.py.


Architecture

Deterministic engineering constrains agent freedom — stage transitions, scope enforcement and dangerous-operation circuit breakers are hard constraints; path selection and evidence analysis are left to the agent.

                    ┌──────────────────────────────────────────────┐
                    │                 Cain CLI                     │
                    │   cain-agent run --target <t> [--dry-run]    │
                    └───────────────────┬──────────────────────────┘
                                        │
                            ┌───────────▼───────────┐
                            │    Scope Bootstrap     │  target → scope.yaml
                            └───────────┬───────────┘
                                        │
                            ┌───────────▼───────────┐
                            │      Orchestrator      │  deterministic state machine
                            │  recon → test → report │  crash-resumable · scoped
                            └──┬────────┬────────┬──┘
                               │        │        │
              ┌────────────────▼┐   ┌───▼────┐  ┌▼──────────────┐
              │  Recon  Handler │   │  Test  │  │    Report      │
              │  (skill-guided) │   │Handler │  │   Handler      │
              └────────┬────────┘   └───┬────┘  └───────┬────────┘
                       │                │                │
                       └────────┬───────┴───────┬────────┘
                                │               │
                    ┌───────────▼──────┐   ┌────▼───────────────┐
                    │   SDK Executor    │   │  Findings Pipeline  │
                    │ (Planner/Executor)│   │ finder → validator  │  distinct sessions
                    │  allowed_tools=[] │   │ (never shared)      │
                    └─────────┬─────────┘   └─────────────────────┘
                              │
        ┌─────────────────────┼──────────────────────┐
        │                     │                      │
┌───────▼────────┐  ┌─────────▼─────────┐  ┌─────────▼────────┐
│  PreToolUse     │  │   Readonly Guard   │  │   Cloud Module    │
│  Scope Guard    │  │  46 read-only      │  │  IAM privesc ·    │
│  + Cred redact  │  │  security tools    │  │  storage · SSRF   │
└─────────────────┘  └────────────────────┘  └──────────────────┘

All state lives as files in the Workspace (external memory) —
crash-resumable and auditable end-to-end.

Safety is structural, not behavioral:

  • Scope enforcement — a PreToolUse hook blocks any tool call whose target falls outside scope.yaml; scope is enforced by configuration, not by the model's good behavior.
  • Read-only toolchain — 46 built-in security tools (recon / scan / verify / post / report), each with a per-tool dangerous_flags blacklist; write/exploit/persist operations (POST, PUT, DELETE, aws rm/mv/cp, …) are rejected before execution.
  • Finder ≠ Validator — discovery and validation run in separate agent sessions that never share context, so a finding can't be self-confirmed. Verdicts are 4-state structured output.
  • Credential redaction — a redaction hook strips secrets before anything is persisted.

Cloud Module — the part nobody else does

aws_s3 · azure_blob · gcp_gcs · aliyun_oss · tencent_cos · huawei_obs   →  storage exposure
aws IAM · tencent_cam · aliyun_ram                                        →  privilege-escalation path analysis
k8s_rbac · docker_image                                                 →  cluster & image posture
cloud metadata SSRF (IMDS / 169.254.169.254 across 7 providers)

IAM / RAM privilege-escalation graph — models entities → escalation actions → high-privilege targets as a directed graph, exports DOT / JSON for rendering, and finds escalation paths via BFS. Driven by the existing aliyun_ram / tencent_cam rule sets.

Benchmark — prove it, don't claim it

  • Self-built vulnerable-terraform range (bench/aliyun-vuln-tf/) with per-scene expected-detection fixtures.
  • Benchmark executor (bench/run_benchmark.py) scores each scene against four metrics: detection rate, false-positive rate, wall time, token cost — no hallucinated percentages; untested results are marked untested.
  • 44 test files covering the cloud modules, skills, pipeline and CLI.

Measured results

vuln-tf static sweep (offline, zero credentials — full report):

Scene Expected Detected False positives Missed
OSS public bucket (public-read) 1 1 0 0
RAM over-granted policy 2 2 0 0
RAM AdministratorAccess user 5 5 0 0

Clean controls (private bucket, read-only user) stay at zero hits.

Dual-backend sweep (same scenes via claude and pi execution engines — full report): both backends complete the orchestrated pipeline with identical scope-enforcement semantics; per-backend timing and token numbers are in the report.


⚠️ Legal & Ethical Use

Cain is strictly for authorized security testing — your own environments or engagements with written authorization. Core features run with read-only credentials; scope is enforced by configuration, not by AI self-discipline. You are responsible for complying with applicable laws.

Status

Core MVP is functional — deterministic pipeline, safety hooks, cloud module and benchmark are in place. See ROADMAP.md for what's next and CHANGELOG.md for recent work.

License

Apache-2.0. See LICENSE.

관련 프로젝트 살펴보기

불러오는 중…