agentprey/agentprey

GitHub: agentprey/agentprey

面向开发者的 Rust CLI 工具,专注检测 AI Agent 的 Prompt Injection 漏洞并支持 CI/CD 流水线门控。

Stars: 0 | Forks: 0

# agentprey `agentprey` 是一款面向开发者的 AI Agent 安全扫描器。 本仓库目前包含第 5 天的垂直切片版本: - Rust CLI,支持 `scan` 和 `vectors list` 命令 - 通过 `init` 进行项目配置初始化 - 本地认证命令,支持实时权益刷新(`auth activate`、`auth status`、`auth refresh`、`auth logout`) - 通过 `vectors sync --pro` 进行 Pro 向量同步权益控制 - 使用 YAML 定义的 Prompt Injection 向量进行 HTTP 端点测试 - 配置与 CLI 合并的扫描设置(CLI 覆盖配置) - 向量列表和扫描的分类过滤 - 单向量终端输出,包含置信度和指标匹配 - 通过 `--json-out` 输出 JSON 产物 - 通过 `--html-out` 输出 HTML 产物 - 重试/退避、限速和有界并发控制 - 响应脱敏默认开启 - 有意义的退出码 ## Beta 版本安装与验证(15 分钟) 选项 A:使用 Beta 版本二进制文件。 ``` # 1) 从此处下载并解压发布归档: # https://github.com/agentprey/agentprey/releases # 2) 从解压目录运行 ./agentprey --help ./agentprey init ``` 选项 B:从 crates.io 安装。 ``` cargo install agentprey agentprey --help agentprey init ``` 更新现有的 crates.io 安装: ``` cargo install agentprey --locked --force ``` 安装特定版本(用于回退或固定版本): ``` cargo install agentprey --locked --version --force ``` 选项 C:从源码构建。 ``` git clone https://github.com/agentprey/agentprey.git cd agentprey cargo build --manifest-path cli/Cargo.toml --release ./cli/target/release/agentprey --help ``` 验证步骤: ``` # 快速基线检查 bash scripts/beta_smoke.sh # 手动运行与 artifacts agentprey scan \ --target http://127.0.0.1:8787/chat \ --category prompt-injection \ --json-out ./scan.json \ --html-out ./scan.html ``` ## 快速入门(仓库工作流) 启动本地 Mock 目标: ``` python3 scripts/mock_agent.py --mode vulnerable --port 8787 ``` 检查可用向量: ``` cargo run --manifest-path cli/Cargo.toml -- vectors list --category prompt-injection ``` 生成默认项目配置: ``` cargo run --manifest-path cli/Cargo.toml -- init cargo run --manifest-path cli/Cargo.toml -- auth activate --key apy_example_key cargo run --manifest-path cli/Cargo.toml -- auth status cargo run --manifest-path cli/Cargo.toml -- auth refresh cargo run --manifest-path cli/Cargo.toml -- vectors sync --pro cargo run --manifest-path cli/Cargo.toml -- auth logout ``` 权益 API 默认为 `https://PLACEHOLDER.convex.site/api/entitlement`。 使用 `AGENTPREY_API_URL` 或 `.agentprey.toml` 进行覆盖: ``` [auth] api_url = "https://your-convex-host.convex.site" ``` 运行扫描器: ``` cargo run --manifest-path cli/Cargo.toml -- scan --target http://127.0.0.1:8787/chat --category prompt-injection ``` 从配置文件默认值运行: ``` cargo run --manifest-path cli/Cargo.toml -- scan --config .agentprey.toml ``` 输出 JSON 以供 CI 或脚本使用: ``` cargo run --manifest-path cli/Cargo.toml -- scan --target http://127.0.0.1:8787/chat --category prompt-injection --json-out ./scan.json ``` 输出 HTML 以分享报告: ``` cargo run --manifest-path cli/Cargo.toml -- scan --target http://127.0.0.1:8787/chat --category prompt-injection --html-out ./scan.html ``` 通过 CLI 参数调整弹性控制: ``` cargo run --manifest-path cli/Cargo.toml -- scan \ --target http://127.0.0.1:8787/chat \ --category prompt-injection \ --retries 2 \ --retry-backoff-ms 250 \ --max-concurrent 2 \ --rate-limit-rps 10 ``` 尝试具有抵抗性的 Mock: ``` python3 scripts/mock_agent.py --mode resistant --port 8787 cargo run --manifest-path cli/Cargo.toml -- scan --target http://127.0.0.1:8787/chat --category prompt-injection ``` ## 校准健全性检查 - 易受攻击的 Mock 应产生大部分或完全易受攻击的发现。 - 具有抵抗性的 Mock 应保持抵抗性,假阳性应接近于零。 您可以快速运行这两项检查: ``` # 易受攻击基线 python3 scripts/mock_agent.py --mode vulnerable --port 8787 cargo run --manifest-path cli/Cargo.toml -- scan --target http://127.0.0.1:8787/chat --category prompt-injection # 抗性基线 python3 scripts/mock_agent.py --mode resistant --port 8787 cargo run --manifest-path cli/Cargo.toml -- scan --target http://127.0.0.1:8787/chat --category prompt-injection ``` ## CI/CD 使用 `agentprey` 对 CI 友好,因为它返回稳定的退出码: - `0` 表示扫描干净 - `2` 表示检测到漏洞 - `1` 表示运行时/工具错误 这种行为使其与 GitHub Actions 以及任何基于进程退出状态控制构建的 CI 系统兼容。 GitHub Actions 工作流示例: ``` name: AgentPrey Scan on: pull_request: workflow_dispatch: jobs: security-scan: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable - name: Install agentprey run: cargo install agentprey - name: Run scan and gate build env: TARGET_URL: ${{ secrets.AGENTPREY_TARGET_URL }} run: | set +e agentprey scan --target "$TARGET_URL" --category prompt-injection exit_code=$? set -e if [ "$exit_code" -eq 2 ]; then echo "agentprey found vulnerabilities" exit 1 fi exit "$exit_code" ``` ## 退出码 - `0`:未发现漏洞 - `2`:检测到一个或多个漏洞 - `1`:运行时/工具错误 ## 当前限制 - 仅支持 HTTP 目标 - 单轮 Payload 执行(每个向量首个 Payload) - 仅支持 Prompt Injection 向量(20 个向量) ## 备注 - 默认 `max_concurrent` 为 `2`。 - 响应脱敏默认开启。使用 `--no-redact-responses` 可将其禁用。 - 配置输出默认值可在 `[output]` 下同时包含 `json_out` 和 `html_out`。 - crates.io 包捆绑了免费向量,因此无需克隆仓库即可运行 `cargo install agentprey`。 ## Beta 反馈 - Bug 报告:`https://github.com/agentprey/agentprey/issues/new?template=bug-report.md` - 假阳性报告:`https://github.com/agentprey/agentprey/issues/new?template=false-positive-report.md` - 提交报告时请包含命令、版本以及 JSON/HTML 产物。
标签:Agent 安全, AI 安全, ChatGPT 安全, CI/CD 安全, CISA项目, CLI, Crates.io, DAST, DevSecOps, DNS 反向解析, GraphQL安全矩阵, HTML 报告, IP 地址批量处理, JSON 报告, LLM, LNA, Rust, SAST, Unmanaged PE, WiFi技术, 上游代理, 可视化界面, 大模型安全, 威胁情报, 安全扫描器, 开发者工具, 恶意软件分析, 数据投毒防御, 文档结构分析, 盲注攻击, 结构化查询, 网络安全, 网络流量审计, 自动化安全, 负载测试, 通知系统, 隐私保护