mcp-shark/mcp-shark-security-lab
GitHub: mcp-shark/mcp-shark-security-lab
一套面向 MCP 协议和 AI Agent 安全的参考靶场语料库,提供有毒工具模式、静态扫描 harness、AAuth 固定环境和 YARA 规则,用于安全扫描器的检出能力验证与规则覆盖测试。
Stars: 1 | Forks: 0
# MCP Shark Security Lab
**参考 MCP 服务器、静态扫描工具集和 YARA 规则**,用于针对 OWASP 风格的 MCP 和 Agentic 风险模式进行安全工具测试。
[](https://github.com/mcp-shark/mcp-shark-security-lab/actions/workflows/ci.yml)
[](./LICENSE)
[](https://github.com/mcp-shark/mcp-shark)
[Issues](https://github.com/mcp-shark/mcp-shark-security-lab/issues) · [安全](./SECURITY.md) · [贡献](./CONTRIBUTING.md) · [MCPShark](https://github.com/mcp-shark/mcp-shark)
## 目录
- [这是什么](#what-this-is)
- [前置条件](#prerequisites)
- [快速开始](#quick-start)
- [使用 MCP Shark 测试 AAuth Explorer](#test-aauth-explorer-with-mcp-shark)
- [Cursor:一个组合的 MCP 服务器](#cursor-one-combined-mcp-server)
- [仓库布局](#repository-layout)
- [OWASP 风格覆盖范围](#owasp-style-coverage)
- [其他 MCP 客户端](#other-mcp-clients)
- [单独的服务器](#individual-servers)
- [MCPShark 静态扫描工具集](#mcpshark-static-scan-harness)
- [AAuth:应用内示例流量](#aauth-in-app-sample-traffic)
- [一体化测试床](#one-go-testbed)
- [AAuth 端到端参考](#aauth-end-to-end-reference)
- [YARA Smart Scan 和流量](#yara-smart-scan-and-traffic)
- [漏洞主题](#vulnerability-themes)
- [参考资料](#references)
- [法律声明](#legal)
## 这是什么
**MCP Shark Security Lab** 是一个开源的 **MIT** 测试语料库:一个包含数十种有毒工具/资源/提示词模式的组合 **stdio MCP 服务器**,一个用于静态分析的**多服务器 `mcp.json` 测试集**,用于 AAuth 格式请求头的 **localhost HTTP 固定环境**,与 OWASP Agentic Top 10 (ASI01–ASI10) 对齐的 **YARA** 规则,以及辅助脚本(Cursor 配置、测试床、流量生成器)。
你可以将其与**任何**支持 MCP 的扫描器、IDE 或流水线配合使用。它**首要且专为 [MCPShark](https://github.com/mcp-shark/mcp-shark) ([`@mcp-shark/mcp-shark`](https://www.npmjs.com/package/@mcp-shark/mcp-shark)) 打造**——CLI `scan`、仪表板、AAuth Explorer、代理/测试床流程和文档均假定采用此配对,以提供最短路径和最完整的引导式检查。MCPShark 是一款**独立的产品**,拥有其**自己的许可证**和可选功能(例如,**Smart Scan** 在启用时可能会使用**您的** API 密钥);在商业用途之前,请阅读[其许可证](https://github.com/mcp-shark/mcp-shark/blob/main/LICENSE)。
此软件包在 npm 上是 **`private`**(私有)的:请**从 GitHub 克隆**并运行 `npm install`——本仓库没有通过 npm 注册表安装的方式。
## 前置条件
- **Node.js** 18+ ([`engines`](./package.json))
- 本仓库的 **Git** 克隆
- **MCPShark**(可选但推荐):`npx @mcp-shark/mcp-shark` / `npx mcp-shark`
- 运行时依赖项:`@modelcontextprotocol/sdk`、`zod`(有关版本和传递许可证,请参见 `package-lock.json`)
## 快速开始
```
git clone https://github.com/mcp-shark/mcp-shark-security-lab.git
cd mcp-shark-security-lab
npm install
npm start # Combined server: 46 tools + 3 resources + 2 prompts (patterns for scanners; handlers return placeholders)
```
## 使用 MCP Shark 测试 AAuth Explorer
**MCP Shark** 是您通过 `npx @mcp-shark/mcp-shark`(npm scope 为 `@mcp-shark`)运行的 [MCPShark](https://github.com/mcp-shark/mcp-shark) 应用程序。使用它可以在 **AAuth Explorer**、**Traffic** 和 **Local Analysis** 中探索 **AAuth 安全态势**(签名流量、`401` 质询、Bearer、共存)。
### 选项 A —— 仅合成数据(不需要来自本仓库的服务器)
```
npx @mcp-shark/mcp-shark
```
在界面中:**AAuth Explorer** 或 **Local Analysis → AAuth Posture** → **Generate sample data**。合成数据包使用 `user-agent: mcp-shark-self-test/1.0`。
您应该会看到:图节点(Agent / Mission / Resource / Signing / Access),流量行上的态势标签,以及从节点 → 数据包 → Traffic 检查器的向下钻取。**仅限观察**——不进行签名验证。
### 选项 B —— 本仓库的 HTTP 固定环境(端口 9701–9703)
从**仓库根目录**(包含 `package.json` 的目录)运行:
```
git clone https://github.com/mcp-shark/mcp-shark-security-lab.git
cd mcp-shark-security-lab
npm install
npm run aauth:all
```
如果您已经打开了仓库,请跳过 `git clone` / `cd`。在**第二个**终端中运行 MCPShark。单个固定环境运行:`npm run aauth:signed`、`aauth:challenge`、`aauth:bearer`、`npm run aauth:bearer:coexist`。
### 选项 C —— 脚本化自测(`POST /api/aauth/self-test`)
在 MCPShark 的 API 正在监听的情况下(默认仪表板 API 通常在 **9852** 端口——如需要请调整):
```
npm install
npm run aauth:traffic -- --rounds 3 --shark http://127.0.0.1:9852
```
`--shark` 是 `POST …/api/aauth/self-test` 的基础 URL;它**不会**启动 HTTP 固定环境。
**Cursor + MCPShark 代理一步到位:**[一体化测试床](#one-go-testbed)。**CLI、`curl`、Cursor JSON:**[AAuth 端到端参考](#aauth-end-to-end-reference)。
## Cursor:一个组合的 MCP 服务器
注册**一个**进程:`servers/all-vulnerabilities-server.js`(**46** 个工具 + 资源 + 提示词)。
| 方法 | 命令 / 文件 |
|----------|----------------|
| **A — 项目 `.cursor/mcp.json`(推荐)** | `npm run cursor:mcp:install`(指向此克隆的绝对路径)。覆盖:`npm run cursor:mcp:install -- --force` |
| **B — 打印用于 `~/.cursor/mcp.json` 的 JSON** | `npm run cursor:mcp` |
| **C — 工作区相对路径**(仅当本仓库是 Cursor 工作区根目录时) | [`fixtures/cursor-combined-workspace-relative.json`](./fixtures/cursor-combined-workspace-relative.json) |
**配合 MCPShark 使用:**在服务器出现后运行 `npx mcp-shark scan --ide Cursor`。对于多服务器静态规则(流、重复项、声明式包):运行 `npm run harness:copy-mcp-json`,然后从本仓库根目录运行 `npx mcp-shark scan --ide Project`。其他扫描器可以复用相同的 JSON 结构。
## 仓库布局
| 路径 | 作用 |
|------|------|
| [`servers/all-vulnerabilities-server.js`](./servers/all-vulnerabilities-server.js) | 组合的脆弱 stdio 服务器 |
| [`servers/*.js`](./servers/) | 分类服务器 + AAuth HTTP 固定环境 + CLI 测试集存根 |
| [`fixtures/mcp-shark-cli.harness.json`](./fixtures/mcp-shark-cli.harness.json) | 多服务器静态扫描工具集(嵌入的 `tools`) |
| [`mcp.json`](./mcp.json) | 仓库根目录下的测试集副本;**`npm run harness:copy-mcp-json` 会将其覆盖** |
| [`fixtures/cursor-aauth-mcp.json`](./fixtures/cursor-aauth-mcp.json) | HTTP 固定环境的可选 Cursor 条目 |
| [`scripts/`](./scripts/) | Cursor MCP 配置,AAuth 运行器/流量,测试床 |
| [`yara-rules/*.yar`](./yara-rules/) | ASI01–ASI10 YARA 规则 |
| [`.mcp-shark/rules/harness-yaml-rule.yaml`](./.mcp-shark/rules/harness-yaml-rule.yaml) | 用于 `mcp-shark scan` 的示例 YAML 规则 |
### `npm` 脚本(参考)
| 脚本 | 用途 |
|--------|---------|
| `start` | 组合的 `all-vulnerabilities` stdio 服务器 |
| `cursor:mcp` / `cursor:mcp:install` | 组合服务器的 Cursor MCP JSON |
| `vulnerable-token`, `poisoned-tool`, `command-injection`, `prompt-injection`, `oversharing`, `privilege-abuse` | 按类别的服务器 |
| `clean` | 非脆弱基线 |
| `harness:copy-mcp-json` | 将工具集复制到 `./mcp.json` |
| `cli-harness-stub`, `cli-harness-config-vault`, `cli-harness-team-notify` | 用于流检查的实时 stdio 存根 |
| `aauth:signed`, `aauth:challenge`, `aauth:bearer`, `aauth:bearer:coexist`, `aauth:all` | AAuth HTTP 固定环境 |
| `aauth:traffic` | 调用 MCPShark 的 `POST /api/aauth/self-test` |
| `testbed:up`, `testbed:install`, `testbed:start`, `testbed:status`, `testbed:uninstall` | 代理 + Cursor 装配(见测试床部分) |
## OWASP 风格覆盖范围
### 组合服务器(46 个工具 + 3 个资源 + 2 个提示词)
处理程序用于**扫描器和培训**:它们返回**占位符文本**,而**不会**执行元数据中描述的有害操作。尽管如此,在 LLM 驱动的设置中,仍需将该进程视为**不受信任的**。
| 类别 | 主题 | 工具数 |
|----------|--------|------:|
| MCP01 + ASI06 | Tokens, secrets, PII | 6 |
| MCP03 + ASI01 | Tool poisoning, hijacking | 4 |
| MCP05 + ASI03 | Command injection, misuse | 5 |
| MCP06 + ASI02 | Prompt injection | 5 |
| MCP10 | Oversharing | 3 |
| ASI04 | Privilege / identity | 2 |
| ASI05 | Guardrails | 3 |
| ASI08 | DoS / exhaustion | 2 |
| ASI09 | Supply chain | 2 |
| ASI10 | Misplaced trust | 2 |
| Scanner / YARA-style | JWT, LDAP/SSH, keys, SQL, shells, payments, paths, cards | 12 |
| — | **Resources** (非工具) | 3 |
| — | **Prompts** (非工具) | 2 |
| | **工具总数** | **46** |
### YARA 规则 (ASI01–ASI10)
| 文件 | 关注点 |
|------|--------|
| `asi01-behavior-hijacking.yar` | Agent / 角色接管 |
| `asi02-prompt-injection.yar` | ChatML, Llama, Claude 风格注入 |
| `asi03-tool-misuse.yar` | Shell, SQL, 路径遍历 |
| `asi04-privilege-abuse.yar` | 提权, 冒充 |
| `asi05-inadequate-guardrails.yar` | 沙箱 / 边界 |
| `asi06-info-disclosure.yar` | PII, 密钥 |
| `asi07-data-poisoning.yar` | RAG / 训练 |
| `asi08-dos-resource-exhaustion.yar` | DoS 模式 |
| `asi09-supply-chain.yar` | 不受信任的来源 |
| `asi10-misplaced-trust.yar` | 自动执行, 审计缺口 |
## 其他 MCP 客户端
在**您的**克隆中使用指向 `servers/all-vulnerabilities-server.js` 的**绝对**路径:
```
{
"mcpServers": {
"security-test": {
"command": "node",
"args": ["/Users/you/src/mcp-shark-security-lab/servers/all-vulnerabilities-server.js"]
}
}
}
```
## 单独的服务器
```
npm run vulnerable-token # MCP01 + ASI06
npm run poisoned-tool # MCP03 + ASI01 + ASI02
npm run command-injection # MCP05 + ASI03
npm run prompt-injection # MCP06 + ASI02
npm run oversharing # MCP10 + ASI06
npm run privilege-abuse # ASI04 + ASI05 + ASI08–10
npm run clean # Baseline without patterns
```
## MCPShark 静态扫描工具集
MCPShark 的静态分析器读取 **IDE MCP 配置**和嵌入的 **`tools`** 元数据(在此模式下它不会调用实时的 `tools/list`)。
1. **将工具集安装为项目 `mcp.json`**
npm run harness:copy-mcp-json
或者:`cp fixtures/mcp-shark-cli.harness.json mcp.json`(**会覆盖** `./mcp.json`)。如果您的主机当前工作目录不同,请调整 `command` / `args`。
2. **从同一目录扫描**(当前工作目录 = 仓库根目录,以便解析 `./mcp.json`)
npx mcp-shark scan --ide Project
选项:`--format json|sarif|html`、`--output report.html`、`--strict`、--walkthrough`、`--refresh-rules`。
3. **工具集测试的内容**(示例):不安全的 `http://` / `ws://` URL;包含 `$(…)` 或 `|` 的 `args`;`--debug`;没有 jail 标志的 `npx` 文件系统 MCP;`env` 中的 `GITHUB_TOKEN`;重复的工具名称;跨服务器流配对(`harness-config-vault` + `harness-team-notify`);针对 `HARNESS_YAML_TOOL` 的 YAML 规则;声明式的 secret/ANSI/path 短语;`bash -c` / `$(whoami)` 风格的文本。
某些规则需要跨服务器的**全局**工具列表;即使扫描器的实现仍在完善中,其意图也已记录在工具集中。
4. **实时 stdio 存根(可选)**用于流标签:在两个终端中分别运行 `npm run cli-harness-config-vault` 和 `npm run cli-harness-team-notify`,并在客户端中注册两者。静态扫描仍依赖于 JSON 中嵌入的 `tools`。
5. **TUI / HTML:**在复制工具集后,运行 `npx @mcp-shark/mcp-shark tui`(流面板 **3**)或 `npx @mcp-shark/mcp-shark scan --format html --output report.html`。
## AAuth:应用内示例流量
**Generate sample data** 路径与上面的[使用 MCP Shark 测试 AAuth Explorer](#test-aauth-explorer-with-mcp-shark) **选项 A**(仅限界面,标记的合成流量)相同。该部分提供了最快的演练流程。
## 一体化测试床
用于通过您的技术栈传输**真实的 HTTP** AAuth 格式请求头(可选;会涉及 **`~/.mcp-shark/mcps.json`** 和 **`~/.cursor/mcp.json`**):
```
npm run testbed:up
```
它的作用:
1. **备份:**将现有的 `~/.mcp-shark/mcps.json` 和 `~/.cursor/mcp.json` 复制为 `*.testbed-backup`,**前提是**该备份路径不存在。如果您需要全新的备份链,请在重新安装之前重新运行 **`testbed:uninstall`**。
2. **MCPShark 上游:**将 **`dummy-all-vulnerabilities`** stdio 服务器合并到 `mcps.json` 中并进行净化处理(无代理循环;不将 401 质询固定环境作为上游)。
3. **Cursor:**添加 **`mcp-shark`** → `http://127.0.0.1:9851/mcp`(覆盖:`npm run testbed:up -- --shark-port=…`),**合并** `mcpServers`。写入的文件仅包含顶层的 **`mcpServers`** 对象——不要指望其他的顶层键能被保留。
4. **进程:**启动三个 **localhost** HTTP 固定环境服务器(Ctrl+C 会停止它们)。它们**不是** MCPShark 的上游(质询会破坏代理探测)。
接着:在另一个终端中运行 `npx @mcp-shark/mcp-shark`,重新加载 Cursor,通过代理执行工具。
| 命令 | 用途 |
|---------|---------|
| `npm run testbed:install` | 仅写入配置(添加 `-- --dry-run` 以预览) |
| `npm run testbed:start` | 仅启动 HTTP 固定环境 |
| `npm run testbed:status` | 显示上游 + 备份状态 |
| `npm run testbed:uninstall` | 恢复最新的 `*.testbed-backup` |
## AAuth 端到端参考
MCPShark 的 AAuth 可见性是**仅限观察的**(无签名验证或强制执行)。固定环境:
| 固定环境 | 端口 | 发出内容 | 展示内容 |
|---------|-----:|--------|----------|
| `aauth-signed-http-server.js` | 9701 | `Signature`, `Signature-Input`, `Signature-Key`, `AAuth-Agent`, `AAuth-Mission` | **已签名** 态势, 身份, 任务 |
| `aauth-challenge-http-server.js` | 9702 | `401` + `AAuth-Requirement` | **AAuth 感知**, 需求规则 |
| `bearer-token-http-server.js` | 9703 | `Authorization: Bearer …`(+ 带有 `--coexist` 的 `Signature-Input`) | **Bearer**; 共存规则 |
**启动界面:**`npx @mcp-shark/mcp-shark` · **服务器:**`npm run aauth:all`(或单独的 `aauth:*` 脚本)。**脚本化数据包:**`npm run aauth:traffic -- …`(见上方选项 C)。**界面参考:**[AAuth Explorer 模拟](https://mcp-shark.github.io/aauth-explorer/) vs 来自捕获数据包的实时图。
**CLI 检查:**
```
npx mcp-shark list
# Expect AAuth Visibility section (例如利用 shark-harness-aauth-agent)。
npx mcp-shark scan --ide Project
# Static (server/tool scope):例如 aauth-agent-identity-observed、aauth-jwks-discovery-url。
# Packet-scoped rules 需要捕获的 HTTP 流量——使用 Generate sample data / fixtures / proxy。
```
**HTTP API(默认仪表板端口通常为 9001——如果不同请使用您的实际端口):**
```
curl -sS "http://localhost:9001/api/aauth/posture" | jq
curl -sS "http://localhost:9001/api/aauth/missions" | jq
```
预期包含以下字段:`verified: false`,非零的签名计数,`packet_count > 0` 的任务。
**Cursor(可选):**将 [`fixtures/cursor-aauth-mcp.json`](./fixtures/cursor-aauth-mcp.json) 合并到 `~/.cursor/mcp.json` 中,以便这三个 HTTP MCP 能够显示(通常流量会通过 MCPShark 代理)。
## YARA Smart Scan 和流量
- **`yara-rules/`** — 标准 YARA 规则;可在**任何**引擎中使用。在 MCPShark 中:**Security → Community Rules → Add source** → 选择此文件夹。
- **组合服务器** — 添加到 MCP 客户端配置,然后在 MCPShark 捕获时驱动流量。
- **Smart Scan** — MCPShark 中的可选功能;启用时可能会使用**您的** API token 调用**远程**模型——请参阅 MCPShark 文档。
## 漏洞主题
| 领域 | 语料库中的示例 |
|------|---------------------|
| MCP01 + ASI06 | 硬编码密钥, Bearer 文本, URI 中的凭据, PII, 医疗保健参考 |
| MCP03 + ASI01 | 隐藏指令, 角色劫持, ChatML / 脚本注入 |
| MCP05 + ASI03 | Shell, 路径遍历, `eval`, SQL |
| MCP06 + ASI02 | 指令覆盖, 越狱, 系统提示词提取 |
| ASI04 + ASI05 | 提权, 冒充, 沙箱逃逸, 弱防护 |
| ASI08 + ASI09 + ASI10 | DoS, 供应链, 盲目信任 / 无审计 |
## 参考资料
- [OWASP Top 10 for Agentic Applications](https://genai.owasp.org/)
- [OWASP Top 10 for LLM Applications](https://owasp.org/www-project-top-10-for-large-language-model-applications/)
- [Model Context Protocol](https://modelcontextprotocol.io/)
- [MCPShark](https://github.com/mcp-shark/mcp-shark)
**运维说明:**HTTP 固定环境绑定到 **localhost**(默认为 9701–9703)。**测试床**会编辑您**主目录**下的文件——如果不确定,请使用 `testbed:status`、`testbed:uninstall` 和 `--dry-run`。
## 法律声明
在 [MIT License](./LICENSE) 下开源。本仓库不授予使用 **MCP Shark**、**MCPShark** 或 **Cursor** 名称或徽标的权利,也不授予超出其各自许可证范围的第三方软件包的任何权利。
**GitHub About:**仓库的 **description**、**website** 和 **topic** 标签(GitHub 主页标题下的元数据)是为了便于发现而维护的。它们未存储在 git 中;当定位发生变化时,请使用 [CONTRIBUTING — GitHub About](./CONTRIBUTING.md#github-about) 中的命令更新它们。标签:AAuth, AI安全, Chat Copilot, CISA项目, DLL 劫持, DNS解析, Homebrew安装, IP 地址批量处理, MCP, MITM代理, MIT许可, SOC Prime, YARA, 云资产可视化, 人工智能安全, 合规性, 大语言模型, 安全测试, 安全靶场, 开发工具, 开源项目, 恶意样本, 插件系统, 攻击性安全, 智能体安全, 测试集, 端到端测试, 网络安全, 错误基检测, 隐私保护, 静态代码分析