面向 AI 代理系统的 332 项安全测试,覆盖 24 个模块。支持 4 种 wire 协议(MCP、A2A、L402、x402),20+ 企业平台,GTG-1002 APT 仿真,误报率测试,供应链溯源,越狱抵抗,AIUC-1 认证准备。核心协议模块零外部依赖。
当前版本:v3.8.1 | PyPI | GitHub | Apache 2.0
v3.8.1 新增: MCP Server(将 harness 暴露为 MCP 工具供任意 AI 代理调用)、Attestation Registry(可选,Ed25519 签名)、Telemetry(可选,GDPR 合规)、GitHub Action 用于 CI/CD、免费 MCP 安全扫描、AIUC-1 认证准备、月度安全报告管道、Discord 扫描机器人。
在 HRAO-E 146 项测试中验证通过率达 97.9%,Wilson 95% CI [0.943, 0.994]。经过 22 轮关键评估,最终得分 10/10。
安全
默认非破坏性。全部 332 项测试仅发送构造输入并分析响应,不会修改目标状态、删除数据或执行写操作。
未经明确授权,切勿针对生产系统运行。请使用隔离的 staging/测试环境和测试账户,尤其是支付端点(L402、x402)。
支付测试(L402/x402):仅发送构造的支付挑战并分析响应,不会执行真实交易、转移资金或与实时支付网络交互。
所需环境
需要 Python 3.10+ 和 pip。
环境变量:
| 变量 | 是否必需 | 用途 |
|---|
| (默认无) | - | 大多数测试仅需通过 CLI --url 标志传入目标 URL |
PLATFORM_API_KEY | 仅企业适配器测试需要 | 平台专用 API 密钥(SAP、Salesforce、Workday 等)——仅使用限定范围的测试凭据 |
ALPACA_PAPER_API_KEY | 否 | 仅用于交易相关集成测试 |
标准协议测试(MCP、A2A、L402、x402、over-refusal、provenance、jailbreak)无需任何环境变量。目标 URL 通过 CLI 参数传入,而非环境变量。
凭据指引:若使用需要 API 密钥的企业适配器测试,请通过环境变量或 .env 文件安全存储凭据。切勿将 API 密钥提交到版本控制。仅提供限定范围的测试凭据,绝不用生产密钥。
安装
# 从 PyPI 安装(推荐固定版本)
pip install agent-security-harness==3.8.1# 验证安装
agent-security version
# 预期输出:3.8.1
源码验证:
依赖:核心协议模块(MCP、A2A、L402、x402、over-refusal、provenance、jailbreak)仅使用 Python 标准库(零外部依赖)。应用层套件需要 requests 和 geopy。
快速参考
# 列出所有 harness 与测试
agent-security list
agent-security list mcp# 测试 MCP server(仅需 URL)
agent-security test mcp --transport http --url http://localhost:8080/mcp
# 测试 A2A 代理
agent-security test a2a --url https://agent.example.com
# 测试 L402 支付端点(Lightning)——非破坏性
agent-security test l402 --url https://l402-endpoint.com
# 测试 x402 支付端点(Coinbase/USDC)——非破坏性
agent-security test x402 --url https://x402-endpoint.com
# 测试 x402 并指定付费端点路径
agent-security test x402 --url https://apibase.pro --paid-path /api/v1/tools/geo.geocode/call
# 测试误报率(over-refusal)
agent-security test over-refusal --url http://localhost:8080/mcp
# 测试供应链溯源与证明
agent-security test provenance --url http://localhost:8080/mcp
# 测试越狱抵抗
agent-security test jailbreak --url http://localhost:8080/mcp
# 测试能力边界画像
agent-security test capability-profile --url https://agent.example.com
# 测试有害输出防护
agent-security test harmful-output --url https://agent.example.com
# 测试 CBRN 内容防护
agent-security test cbrn --url https://agent.example.com
# 测试事件响应就绪
agent-security test incident-response --url https://agent.example.com
# 统计置信区间(符合 NIST AI 800-2)
agent-security test mcp --url http://localhost:8080/mcp --trials 10
# 对生产端点限速(测试间毫秒延迟)
agent-security test a2a --url https://agent.example.com --delay 1000
# 无需服务器(使用捆绑的 mock MCP server)
python -m testing.mock_mcp_server # 终端 1:启动在 8402 端口
agent-security test mcp --transport http --url http://localhost:8402/mcp # 终端 2
MCP Server 模式
将 harness 作为 MCP 工具供任意 AI 代理调用:
# stdio(用于 Cursor、Claude Desktop)
python -m mcp_server# HTTP
python -m mcp_server --transport http --port 8400
工具:scan_mcp_server(快速扫描)、full_security_audit(332 项测试)、aiuc1_readiness、get_test_catalog、validate_attestation。
Harness 模块(24 模块,332 项测试)
| 命令 | 测试数 | 测试内容 |
|---|
test mcp | 13 | MCP wire-protocol(JSON-RPC 2.0):工具投毒、能力升级、协议降级、资源遍历、采样劫持、上下文位移 |
test a2a | 12 | A2A 协议:Agent Card 欺骗、任务注入、推送通知重定向、技能注入、上下文隔离 |
test l402 | 14 | L402 支付:macaroon 篡改、原像重放、条款升级、发票验证 |
test x402 | 25 | x402 支付:接收方操纵、会话窃取、中介信任、跨链混淆、支出限额、健康检查。包含 Agent 自主性风险评分(0-100) |
test enterprise | 31 | 一线企业:SAP、Salesforce、Workday、Oracle、ServiceNow、Microsoft、Google、Amazon、OpenClaw |
test extended-enterprise | 27 | 二线企业:IBM Maximo、Snowflake、Databricks、Pega、UiPath、Atlassian、Zendesk、IFS、Infor、HubSpot、Appian |
test framework | 11 | 框架适配器:LangChain、CrewAI、AutoGen、OpenAI Agents SDK、Bedrock |
test identity | 18 | NIST NCCoE 代理身份:识别、认证、授权、审计、数据流、标准合规 |
test gtg1002 | 17 | GTG-1002 APT 仿真:6 个战役阶段 + 幻觉检测 |
test advanced | 10 | 高级模式:多态注入、有状态升级、多域链、越狱持久化 |
test over-refusal | 25 | 误报率:所有协议下应不被阻止的合法请求。用 Wilson CI 测量 FPR |
test provenance | 15 | 供应链:伪造溯源、欺骗性证明、市场完整性、CVE-2026-25253 攻击模式 |
test jailbreak | 25 | 越狱抵抗:DAN 变体、token 走私、权威冒充、上下文操纵、持久化 |
test return-channel | 8 | 返回通道投毒:输出注入、ANSI 转义、上下文溢出、编码走私、结构化数据投毒 |
test capability-profile | 10 | 执行器能力边界验证、画像升级防护 |
test harmful-output | 10 | 毒性、偏见、范围违规、欺骗(AIUC-1 C003/C004) |
test cbrn | 8 | 化学/生物/放射/核内容防护(AIUC-1 F002) |
test incident-response | 8 | 告警触发、熔断开关、日志完整性、恢复(AIUC-1 E001-E003) |
test aiuc1 | 12 | AIUC-1 合规:全部 24 项认证要求映射 |
test cloud | 25 | 云代理平台:AWS Bedrock、Azure AI、GCP Vertex、Anthropic、OpenAI |
test cve-2026 | 8 | CVE-2026-25253 复现:大规模供应链工具投毒 |
CI/CD 集成(v3.8+)
# GitHub Action - 放入任意工作流
- uses: msaleme/red-team-blue-team-agent-fabric@v3.8
with:
target_url: http://localhost:8080/mcp
# 免费快速扫描(5 项测试,A-F 评级)
python scripts/free_scan.py --url http://server:port/mcp --format markdown# AIUC-1 认证就绪报告
python scripts/aiuc1_prep.py --url http://server:port --simulate
# 多目标的月度安全报告
python scripts/monthly_security_report.py
输出格式
所有 harness 均输出 JSON 报告,包含:
- 每项测试的通过/失败及测试 ID 与 OWASP ASI 映射
- 完整的请求/响应记录供审计
- 每项测试耗时
- Wilson 得分置信区间(使用
--trials N)
- x402 harness 额外包含:CSG 映射、财务影响估算、Agent 自主性风险评分
何时使用各 Harness
- 构建 MCP server?部署前运行
test mcp
- 对外暴露 A2A 代理?运行
test a2a 检查 Agent Card 与任务安全
- 添加代理支付?上线前运行
test l402(Lightning)或 test x402(USDC)
- 部署到企业平台?用平台名运行
test enterprise
- 对代理系统红队?运行
test gtg1002 进行完整 APT 战役仿真
- 需要合规证据?使用
--trials 10 获取符合 NIST AI 800-2 的统计报告
- 准备 AIUC-1 认证?运行全部 harness 以收集 B001/C010/D004 证据
- 检查误报率?运行
test over-refusal 验证安全控制不阻断合法使用
- 验证供应链完整性?运行
test provenance(CVE-2026-25253 后尤其相关)
- 测试越狱抵抗?运行
test jailbreak 覆盖 DAN 变体与编码逃逸
- 检查代理能力边界?运行
test capability-profile 验证升级防护
- 验证安全控制?运行
test harmful-output 与 test cbrn 进行内容防护
- 测试事件响应?运行
test incident-response 验证熔断与恢复
研究
本 harness 属于已发表的自主 AI 代理治理研究计划:
实证证据表明,网关防御对代理协议攻击无显著缓解作用
代理决策治理框架,77 天生产数据
测量 AI 代理监督的认知负荷
源码与溯源
332 security tests across 24 modules for AI agent systems. 4 wire protocols (MCP, A2A, L402, x402), 20+ enterprise platforms, GTG-1002 APT simulation, false positive rate testing, supply chain provenance, jailbreak resistance, AIUC-1 certification prep. Zero external dependencies for core protocol modules.
Current version: v3.8.1 | PyPI | GitHub | Apache 2.0
New in v3.8.1: MCP Server (expose harness as MCP tools for any AI agent), Attestation Registry (opt-in, Ed25519 signed), Telemetry (opt-in, GDPR compliant), GitHub Action for CI/CD, Free MCP Security Scan, AIUC-1 Certification Prep, Monthly Security Report pipeline, Discord Scan Bot. Validated at 97.9% pass rate (HRAO-E, 146 tests, Wilson 95% CI [0.943, 0.994]). 22 rounds of critical evaluation, 10/10 final score.
Safety
Non-destructive by default. All 332 tests send crafted inputs and analyze responses. No tests modify target state, delete data, or execute write operations.
Do NOT run against production systems without explicit authorization. Use isolated staging/test environments and test accounts, especially for payment endpoints (L402, x402).
Payment tests (L402/x402): Send crafted payment challenges and analyze responses. They do NOT execute real transactions, transfer funds, or interact with live payment networks.
Required Environment
Python 3.10+ and pip are required.
Environment variables:
| Variable | Required | Purpose |
|---|
| (none by default) | - | Most tests only need a target URL passed via CLI --url flag |
PLATFORM_API_KEY | Only for enterprise adapter tests | Platform-specific API key (SAP, Salesforce, Workday, etc.) - use scoped test credentials only |
ALPACA_PAPER_API_KEY | No | Only for trading-related integration tests |
No environment variables are required for standard protocol testing (MCP, A2A, L402, x402, over-refusal, provenance, jailbreak). The target URL is passed as a CLI argument, not an environment variable.
Credential guidance: If you use enterprise adapter tests that require API keys, store credentials securely using environment variables or .env files. Never commit API keys to version control. Only provide scoped test credentials, never production keys.
Install
# Install from PyPI (pinned version recommended)
pip install agent-security-harness==3.8.1# Verify installation
agent-security version
# Expected output: 3.8.1
Source verification:
Dependencies: Core protocol modules (MCP, A2A, L402, x402, over-refusal, provenance, jailbreak) use Python stdlib only (zero external dependencies). Application-layer suite requires requests and geopy.
Quick Reference
# List all harnesses and tests
agent-security list
agent-security list mcp# Test an MCP server (requires only a URL)
agent-security test mcp --transport http --url http://localhost:8080/mcp
# Test an A2A agent
agent-security test a2a --url https://agent.example.com
# Test L402 payment endpoint (Lightning) - non-destructive
agent-security test l402 --url https://l402-endpoint.com
# Test x402 payment endpoint (Coinbase/USDC) - non-destructive
agent-security test x402 --url https://x402-endpoint.com
# Test x402 with specific paid endpoint path
agent-security test x402 --url https://apibase.pro --paid-path /api/v1/tools/geo.geocode/call
# Test false positive rate (over-refusal)
agent-security test over-refusal --url http://localhost:8080/mcp
# Test supply chain provenance and attestation
agent-security test provenance --url http://localhost:8080/mcp
# Test jailbreak resistance
agent-security test jailbreak --url http://localhost:8080/mcp
# Test capability profile boundaries
agent-security test capability-profile --url https://agent.example.com
# Test harmful output safeguards
agent-security test harmful-output --url https://agent.example.com
# Test CBRN content prevention
agent-security test cbrn --url https://agent.example.com
# Test incident response readiness
agent-security test incident-response --url https://agent.example.com
# Statistical confidence intervals (NIST AI 800-2 aligned)
agent-security test mcp --url http://localhost:8080/mcp --trials 10
# Rate-limit for production endpoints (milliseconds between tests)
agent-security test a2a --url https://agent.example.com --delay 1000
# Try without a server (bundled mock MCP server)
python -m testing.mock_mcp_server # Terminal 1: starts on port 8402
agent-security test mcp --transport http --url http://localhost:8402/mcp # Terminal 2
MCP Server Mode
Use the harness as an MCP tool that any AI agent can call:
# stdio (for Cursor, Claude Desktop)
python -m mcp_server# HTTP
python -m mcp_server --transport http --port 8400
Tools: scan_mcp_server (quick scan), full_security_audit (332 tests), aiuc1_readiness, get_test_catalog, validate_attestation.
Harness Modules (24 modules, 332 tests)
| Command | Tests | What It Tests |
|---|
test mcp | 13 | MCP wire-protocol (JSON-RPC 2.0): tool poisoning, capability escalation, protocol downgrade, resource traversal, sampling hijack, context displacement |
test a2a | 12 | A2A protocol: Agent Card spoofing, task injection, push notification redirect, skill injection, context isolation |
test l402 | 14 | L402 payments: macaroon tampering, preimage replay, caveat escalation, invoice validation |
test x402 | 25 | x402 payments: recipient manipulation, session theft, facilitator trust, cross-chain confusion, spending limits, health checks. Includes Agent Autonomy Risk Score (0-100) |
test enterprise | 31 | Tier 1 enterprise: SAP, Salesforce, Workday, Oracle, ServiceNow, Microsoft, Google, Amazon, OpenClaw |
test extended-enterprise | 27 | Tier 2 enterprise: IBM Maximo, Snowflake, Databricks, Pega, UiPath, Atlassian, Zendesk, IFS, Infor, HubSpot, Appian |
test framework | 11 | Framework adapters: LangChain, CrewAI, AutoGen, OpenAI Agents SDK, Bedrock |
test identity | 18 | NIST NCCoE Agent Identity: identification, authentication, authorization, auditing, data flow, standards compliance |
test gtg1002 | 17 | GTG-1002 APT simulation: 6 campaign phases + hallucination detection |
test advanced | 10 | Advanced patterns: polymorphic injection, stateful escalation, multi-domain chains, jailbreak persistence |
test over-refusal | 25 | False positive rate: legitimate requests across all protocols that should NOT be blocked. Measures FPR with Wilson CI |
test provenance | 15 | Supply chain: fake provenance, spoofed attestation, marketplace integrity, CVE-2026-25253 attack patterns |
test jailbreak | 25 | Jailbreak resistance: DAN variants, token smuggling, authority impersonation, context manipulation, persistence |
test return-channel | 8 | Return channel poisoning: output injection, ANSI escape, context overflow, encoded smuggling, structured data poisoning |
test capability-profile | 10 | Executor capability boundary validation, profile escalation prevention |
test harmful-output | 10 | Toxicity, bias, scope violations, deception (AIUC-1 C003/C004) |
test cbrn | 8 | Chemical/biological/radiological/nuclear content safeguards (AIUC-1 F002) |
test incident-response | 8 | Alert triggering, kill switch, log completeness, recovery (AIUC-1 E001-E003) |
test aiuc1 | 12 | AIUC-1 compliance: all 24 certification requirements mapped |
test cloud | 25 | Cloud agent platforms: AWS Bedrock, Azure AI, GCP Vertex, Anthropic, OpenAI |
test cve-2026 | 8 | CVE-2026-25253 reproduction: supply chain tool poisoning at scale |
CI/CD Integration (v3.8+)
# GitHub Action - drop into any workflow
- uses: msaleme/red-team-blue-team-agent-fabric@v3.8
with:
target_url: http://localhost:8080/mcp
# Free quick scan (5 tests, A-F grade)
python scripts/free_scan.py --url http://server:port/mcp --format markdown# AIUC-1 certification readiness report
python scripts/aiuc1_prep.py --url http://server:port --simulate
# Monthly security report across multiple targets
python scripts/monthly_security_report.py
Output Format
All harnesses produce JSON reports with:
- Pass/fail per test with test ID and OWASP ASI mapping
- Full request/response transcripts for audit
- Elapsed time per test
- Wilson score confidence intervals (with
--trials N)
- x402 harness adds: CSG mapping, financial impact estimation, Agent Autonomy Risk Score
When to Use Each Harness
- Building an MCP server? Run
test mcp before deploying
- Exposing an A2A agent? Run
test a2a to check Agent Card and task security
- Adding agent payments? Run
test l402 (Lightning) or test x402 (USDC) before going live
- Deploying on enterprise platforms? Run
test enterprise with your platform name
- Red-teaming an agent system? Run
test gtg1002 for full APT campaign simulation
- Need compliance evidence? Use
--trials 10 for NIST AI 800-2 aligned statistical reports
- Preparing for AIUC-1 certification? Run all harnesses for B001/C010/D004 evidence
- Checking false positive rate? Run
test over-refusal to verify security controls don't break legitimate use
- Validating supply chain integrity? Run
test provenance (especially relevant after CVE-2026-25253)
- Testing jailbreak resistance? Run
test jailbreak for DAN variants and encoding evasion
- Checking agent capability boundaries? Run
test capability-profile to verify escalation prevention
- Validating safety controls? Run
test harmful-output and test cbrn for content safeguards
- Testing incident response? Run
test incident-response for kill switch and recovery validation
Research
This harness is part of a published research program on autonomous AI agent governance:
Source & Provenance