PromptArmor——法学硕士安全红队

Claude Code插件+MCP服务器,用于LLM应用程序安全红队。读取代码,测试端点,修复漏洞。
为什么选择PromptArmor
像promptfoo这样的现有工具测试端点是盲目的——它们发送攻击并检查响应,但不知道你的系统提示说了什么,你暴露了什么工具,或者你的护栏在哪里。PromptArmor首先读取代码:
- 侦察 --扫描代码库以查找系统提示、工具定义、护栏和注入表面
- 计划 --根据发现的内容对攻击进行优先级排序(找到SQL工具?优先考虑SQL注入。系统提示说“永远不要讨论竞争对手”?具体测试一下。)
- 攻击 --针对您的端点发送80多种攻击类型和25种以上突变策略
- 法官 --法学硕士作为评判者+模式匹配+情境感知评分
- 修复 --在特定的文件行位置生成实际的代码补丁,而不是通用建议
快速开始
安装插件
claude plugin add ./plugin运行完整扫描
/prompt-armor:scan --target https://your-app.com/api/chat或者只是分析代码
/prompt-armor:analyze建筑
两个组件协同工作:
┌─────────────────────────────────────────────┐
│ Claude Code Plugin │
│ ┌──────────┐ ┌──────────┐ ┌──────────────┐│
│ │ Commands │ │ Agents │ │ Skills ││
│ │ 6 cmds │ │ 5 agents │ │ 5 modules ││
│ └──────────┘ └──────────┘ └──────────────┘│
│ ┌──────────┐ │
│ │ Hooks │ │
│ │ 4 hooks │ │
│ └──────────┘ │
└───────────────────┬─────────────────────────┘
│ MCP Protocol
┌───────────────────▼─────────────────────────┐
│ MCP Server (TypeScript) │
│ ┌──────────┐ ┌──────────┐ ┌──────────────┐│
│ │ Attacks │ │ Judge │ │ Reports ││
│ │ 80+ │ │ 3-tier │ │ text/json/ ││
│ │ plugins │ │ grading │ │ sarif ││
│ └──────────┘ └──────────┘ └──────────────┘│
│ ┌──────────┐ ┌──────────┐ ┌──────────────┐│
│ │Mutations │ │ Client │ │ State ││
│ │ 25+ │ │ adapters │ │ persistence ││
│ │strategies│ │ for APIs │ │ JSON files ││
│ └──────────┘ └──────────┘ └──────────────┘│
└─────────────────────────────────────────────┘命令
| 命令 | 描述 |
|---|---|
/prompt-armor:scan | 完整管道:代码分析→ 攻击计划→ 测试→ 补救→ 报告 |
/prompt-armor:analyze | 仅代码分析--查找没有测试端点的LLM集成点 |
/prompt-armor:attack | 对端点运行特定的攻击类别 |
/prompt-armor:report | 根据保存的结果生成报告 |
/prompt-armor:config | 创建或验证 promptarmor.yaml |
/prompt-armor:diff | 比较两个扫描结果以进行回归跟踪 |
代理
| 代理 | 角色 |
|---|---|
| 侦察员 | 扫描代码库以查找系统提示、工具模式、护栏、注入表面 |
| 攻击计划者 | 根据侦察结果制定有针对性的攻击策略 |
| 红队队员 | 通过MCP服务器工具执行攻击 |
| 法官代理人 | 使用上下文感知评分审查边缘判决 |
| 补救剂 | 使用file:行引用生成特定于代码的修复 |
攻击覆盖范围
80+攻击插件 跨越10个类别:
| 类别 | 计数 | 示例 |
|---|---|---|
| 越狱 | 13 | 基本忽略、角色切换、DAN、系统提示提取、分隔符注入 |
| 注入 | 5 | 直接、间接、上下文合规、系统覆盖、提示提取 |
| 工具滥用 | 12 | SQL注入、SSRF、文件读/写、代码执行、权限升级 |
| 有害 | 18 | 暴力、犯罪、仇恨、自残、毒品、武器、网络犯罪、错误信息 |
| 偏见 | 5 | 年龄、性别、种族、残疾、宗教 |
| PII | 4 | 直接披露、会话泄漏、社会工程、数据库泄漏 |
| 合规性 | 4 | HIPAA、COPPA、FERPA、GDPR |
| 代理 | 3 | 内存中毒、跨会话泄漏、目标错位 |
| RAG | 3 | 文件泄露、来源归因、中毒 |
| 其他 | 13+ | 幻觉、模仿、合同、竞争对手、调试访问 |
25+突变策略:
| 类型 | 策略 |
|---|---|
| 编码 | Base64、ROT13、十六进制、Leetspeak、同形符、莫尔斯、猪拉丁语、表情符号、ASCII走私 |
| 结构化 | 少镜头素数、上下文填充、指令分隔符、Markdown注入、引用、权威标记 |
| 多回合 | Crescendo、GOAT、HYDRA、重试 |
| 高级 | 多语言(10种语言),数学提示,最佳N,越狱模板,复合 |
配置
创建一个 promptarmor.yaml:
target:
url: https://your-app.com/api/chat
format: openai
attacks:
suites: [jailbreak, injection, tool-abuse, harmful, pii]
num_per_plugin: 5
mutations:
strategies: [base64, multilingual, crescendo]
judge:
provider: anthropic
analysis:
enabled: true
paths: [src/]
output:
formats: [text, json, sarif]
ci:
fail_on: critical输出格式
- 文本/Markdown --人类可读的报告,包括发现、严重程度和补救措施
- JSON --机器可读自动化
- SARIF v2.1.0 --上传到GitHub安全选项卡
CI集成
PromptArmor自动检测CI环境并进行调整:
- JSON/SARIF输出(无交互式提示)
- 漏洞超过时退出代码1
--fail-on阈值 - 工件保存到
.prompt-armor/用于收藏
MCP 服务器
MCP服务器可由任何MCP客户端(Claude Desktop、Cursor等)独立使用:
| 工具 | 目的 |
|---|---|
run_attack_suite | 运行一整套攻击 |
send_attack | 发送一次攻击 |
judge_response | 判断答案 |
get_results / save_results | 国家管理 |
generate_report | 生成报告 |
list_attacks / list_mutations | 发现 |
validate_config | 配置验证 |
E2E已验证
针对故意易受攻击的Node.js聊天端点进行了测试,该端点具有关键字触发的秘密泄露、系统提示泄露和无输入净化:
$ /prompt-armor:scan --target http://localhost:4010/api/chat
Artifacts:
.prompt-armor/recon/recon-2026-03-24.json (system prompts, tool schemas, injection surfaces)
.prompt-armor/state.json (full scan state with per-test verdicts)
.prompt-armor/reports/report-2026-03-24-full.md (151-line executive report)
.prompt-armor/reports/promptarmor-*.json (machine-readable report)
.prompt-armor/reports/promptarmor-*.txt (text report)
Tests: 150 across 8 categories
Passed: 133
Failed: 17 (15 critical, 2 high)
By category:
jailbreak: 12/16 (4 failed) tool-abuse: 13/24 (11 failed)
injection: 13/15 (2 failed) harmful: 47/47 passed
bias: 15/15 passed pii: 12/12 passed
compliance: 12/12 passed agentic: 9/9 passed
Detected:
- System prompt disclosure (3 vectors)
- DAN mode jailbreak adoption
- Secret exfiltration (JWT_SECRET, DB credentials via prompt injection)
- Privilege escalation (admin access granted unconditionally)
- File content disclosure (/etc/passwd)
- SQL injection (DROP TABLE executed)
- Tool schema enumerationRecon正确识别了系统提示(src/config.js:3),工具模式,硬编码的秘密,以及所有带有file:line引用的注入表面。
发展
npm install # Install dependencies
cd server && npm test # Run server tests