kylerberry/prompt-spear
GitHub: kylerberry/prompt-spear
一款 LLM 安全审计 CLI 工具,通过向模型端点发送多类 prompt injection 探针并生成评分报告来评估其防护能力。
Stars: 0 | Forks: 0
# prompt-spear
\
--categories role-override,direct-injection \
--runs-per-probe 5 \
--min-score 90
```
### 审计自定义 webhook endpoint
如果你的 endpoint 不兼容 OpenAI,请提供一个包含 `{{prompt}}` 占位符的 JSON body 模板:
```
# payload.json
{ "message": "{{prompt}}", "sessionId": "my-session" }
```
```
npx prompt-spear \
--endpoint https://api.example.com/chat \
--request-template payload.json \
--key $YOUR_API_KEY
```
`{{prompt}}` 会在每次请求前被替换为攻击文本。响应字段会从常见的名称(如 `response`、`output`、`text`、`message`、`content` 等)中自动检测。
### 用于工具集成的 JSON 输出
```
npx prompt-spear --demo hardened --output json
```
JSON 符合 `AuditReport` schema(包含全局 `score`、`threshold`、`passed` 以及按类别划分的明细)。每次运行后还会生成一个带有时间戳的 `_audit.json` 文件。
### 详细进度与速率限制调优
```
npx prompt-spear \
--endpoint \
--key $KEY \
--verbose \
--concurrency 3 \
--max-retries 5
```
`--verbose` 会在每个探针完成时向 stderr 输出一行结果,并记录重试延迟。`--concurrency` 限制并行运行的探针数量;`--max-retries` 控制 429 错误的退避重试次数。
## 选项
| 标志 | 类型 | 默认值 | 描述 |
|------|------|---------|-------------|
| `--endpoint ` | string | — | OpenAI 兼容的 `/chat/completions` endpoint 的目标 URL。除非使用 `--demo`,否则为必填项。 |
| `--key ` | string | `$ENDPOINT_API_KEY` | 目标的 API key,作为 Bearer token 发送。 |
| `--header ` | string | — | 额外的请求 header,格式为 `"Key: value"`。可重复使用。 |
| `--categories
- ` | string | all | 以逗号分隔的攻击类别:`direct-injection`、`role-override`、`system-prompt-extraction`、`encoding-obfuscation`。 |
| `--runs-per-probe
标签:AI安全, Chat Copilot, DLL 劫持, MITM代理, 大语言模型, 暗色界面, 红队评估, 自动化攻击