README
🚀 AgentAudit
AgentAudit 是一款专为 AI 包生态系统打造的安全扫描工具,具备 MCP 服务器和 CLI 两种使用方式。它能对 MCP 服务器、AI 技能和包进行漏洞、提示注入和供应链攻击检测,采用正则静态分析和深度大语言模型审计技术。
🚀 快速开始
选项 A:CLI(推荐)
# 全局安装(或使用 npx agentaudit)
npm install -g agentaudit
# 发现 AI 编辑器中配置的 MCP 服务器
agentaudit
# 快速扫描 — 克隆仓库,使用正则模式检查代码(约 2 秒)
agentaudit scan https://github.com/owner/repo
# 深度审计 — 克隆仓库,将代码发送到 LLM 进行 3 遍分析(约 30 秒)
agentaudit audit https://github.com/owner/repo
# 注册表查找 — 检查包是否之前已被审计(无需克隆)
agentaudit lookup fastmcp
示例输出:
AgentAudit v3.9.8
用于 AI 包的安全扫描器
正在发现 AI 编辑器中的 MCP 服务器...
• 扫描 Cursor ~/.cursor/mcp.json 找到 3 个服务器
├── 工具 supabase-mcp ✔ 正常
│ 安全 风险 0 https://agentaudit.dev/skills/supabase-mcp
├── 工具 browser-tools-mcp ✔ 正常
│ ⚠ 未审计 运行:agentaudit audit https://github.com/nichochar/browser-tools-mcp
└── 工具 filesystem ✔ 正常
│ 安全 风险 0 https://agentaudit.dev/skills/filesystem
正在寻找通用包扫描工具?试试 `pip audit` 或 `npm audit`。
选项 B:在 AI 编辑器中使用 MCP 服务器
将 AgentAudit 添加为 MCP 服务器,这样你的 AI 代理就可以使用其自身的大语言模型来发现、扫描和审计包,无需额外的 API 密钥。
Claude Desktop — ~/.claude/mcp.json
{
"mcpServers": {
"agentaudit": {
"command": "npx",
"args": ["-y", "agentaudit", "--stdio"]
}
}
}
Cursor — .cursor/mcp.json(项目级)或 ~/.cursor/mcp.json(全局)
{
"mcpServers": {
"agentaudit": {
"command": "npx",
"args": ["-y", "agentaudit", "--stdio"]
}
}
}
Windsurf — ~/.codeium/windsurf/mcp_config.json
{
"mcpServers": {
"agentaudit": {
"command": "npx",
"args": ["-y", "agentaudit", "--stdio"]
}
}
}
VS Code — .vscode/mcp.json
{
"servers": {
"agentaudit": {
"command": "npx",
"args": ["-y", "agentaudit", "--stdio"]
}
}
}
Continue.dev — ~/.continue/config.json
在现有配置的 mcpServers 部分添加:
{
"mcpServers": [
{
"name": "agentaudit",
"command": "npx",
"args": ["-y", "agentaudit", "--stdio"]
}
]
}
Zed — ~/.config/zed/settings.json
{
"context_servers": {
"agentaudit": {
"command": {
"path": "npx",
"args": ["-y", "agentaudit", "--stdio"]
}
}
}
}
然后向你的代理询问:“检查我已安装的 MCP 服务器,并审计任何未审计的服务器。”
✨ 主要特性
- 支持 CLI 工具和 MCP 服务器两种模式。
- 可对 MCP 服务器、AI 技能和包进行漏洞、提示注入和供应链攻击检测。
- 采用正则静态分析和深度大语言模型审计技术。
- 与 AgentAudit 信任注册表集成,可进行本地扫描。
📦 安装指南
全局安装
npm install -g agentaudit
不安装直接使用
npx agentaudit
💻 使用示例
基础用法
# 发现 AI 编辑器中配置的 MCP 服务器
agentaudit
# 快速扫描
agentaudit scan https://github.com/owner/repo
# 深度审计
agentaudit audit https://github.com/owner/repo
# 注册表查找
agentaudit lookup fastmcp
高级用法
# 发现并自动扫描所有服务器
agentaudit discover --quick
# 发现并交互式选择服务器进行深度审计
agentaudit discover --deep
# 通过扫描命令运行深度审计
agentaudit scan https://github.com/owner/repo --deep
📚 详细文档
📋 命令参考
| 命令 | 描述 | 示例 |
|---------|-------------|---------|
| agentaudit | 发现 MCP 服务器(默认,与 discover 相同) | agentaudit |
| agentaudit discover | 在 Cursor、Claude、VS Code、Windsurf 中查找 MCP 服务器 | agentaudit discover |
| agentaudit discover --quick | 发现并自动扫描所有服务器 | agentaudit discover --quick |
| agentaudit discover --deep | 发现并交互式选择服务器进行深度审计 | agentaudit discover --deep |
| agentaudit scan <url> | 基于正则的快速静态扫描(约 2 秒) | agentaudit scan https://github.com/owner/repo |
| agentaudit scan <url> --deep | 深度审计(与 audit 相同) | agentaudit scan https://github.com/owner/repo --deep |
| agentaudit audit <url> | 基于大语言模型的深度 3 遍审计(约 30 秒) | agentaudit audit https://github.com/owner/repo |
| agentaudit lookup <name> | 在信任注册表中查找包 | agentaudit lookup fastmcp |
| agentaudit setup | 注册代理并配置 API 密钥 | agentaudit setup |
全局标志
| 标志 | 描述 |
|------|-------------|
| --json | 将机器可读的 JSON 输出到标准输出 |
| --quiet / -q | 抑制横幅和装饰性输出(仅显示发现结果) |
| --no-color | 禁用 ANSI 颜色(也遵循 NO_COLOR 环境变量) |
| --help / -h | 显示帮助文本 |
| -v / --version | 显示版本 |
退出代码
| 代码 | 含义 |
|------|---------|
| 0 | 无发现,或查找成功 |
| 1 | 发现问题 |
| 2 | 错误(克隆失败、网络错误、参数无效) |
⚖️ 快速扫描与深度审计对比
| | 快速扫描 (scan) | 深度审计 (audit) |
|---|---------------------|---------------------|
| 速度 | 约 2 秒 | 约 30 秒 |
| 方法 | 正则模式匹配 | 基于大语言模型的 3 遍分析 |
| 是否需要 API 密钥 | 否 | 是(ANTHROPIC_API_KEY 或 OPENAI_API_KEY) |
| 误报率 | 较高(正则限制) | 非常低(上下文感知) |
| 检测内容 | 常见模式(注入、密钥、eval) | 复杂攻击链、AI 特定威胁、混淆 |
| 适用场景 | 快速筛选、CI 管道 | 关键包、预生产审查 |
🔌 MCP 服务器
作为 MCP 服务器运行时,AgentAudit 向你的 AI 代理提供以下工具:
| 工具 | 描述 |
|------|-------------|
| audit_package | 对存储库进行基于大语言模型的深度审计 |
| check_registry | 在信任注册表中查找包 |
| submit_report | 将审计结果上传到注册表 |
| discover_servers | 在本地编辑器配置中查找 MCP 服务器 |
工作流程
用户要求代理安装包
│
▼
代理调用 check_registry(package_name)
│
┌────┴────┐
│ │
找到 未找到
│ │
▼ ▼
返回 代理调用 audit_package(repo_url)
分数 │
▼
大语言模型分析代码(3 遍)
│
▼
代理调用 submit_report(findings)
│
▼
返回结果 + 风险分数
🎯 检测内容
| 类别 | 检测项 | | ---- | ---- | | 核心安全 | 命令注入、凭证窃取、数据泄露、SQL 注入、路径遍历、不安全反序列化 | | AI 特定 | 提示注入、越狱、代理伪装、能力提升、上下文污染、隐藏指令 | | MCP 特定 | 工具中毒、描述注入、资源遍历、未固定的 npx、广泛权限 | | 持久化与混淆 | 定时任务修改、Shell RC 注入、Git Hook 滥用、零宽字符、Base64 执行、ANSI 转义 |
🧠 3 遍审计工作原理
深度审计 (agentaudit audit) 使用结构化的 3 阶段大语言模型分析,不是单次提示,而是严格的多遍处理过程:
| 阶段 | 名称 | 操作 |
|-------|------|-------------|
| 1 | 🔍 理解 | 读取所有文件并构建 包配置文件:用途、类别、预期行为、信任边界。此时不进行扫描,目标是在查找不应有的内容之前,先了解包 应该 做什么。 |
| 2 | 🎯 检测 | 根据 50 多种检测模式 在 8 个类别(AI 特定、MCP、持久化、混淆、跨文件关联)中收集证据。只记录事实,暂不进行严重程度判断。 |
| 3 | ⚖️ 分类 | 每个发现都要经过 强制自检(5 个问题)、可利用性评估 和 置信度筛选。高/关键发现必须通过 魔鬼代言人 挑战,并包含完整的 推理链。 |
为什么需要 3 遍? 单次分析是误报的首要原因。通过将理解、检测和分类分开:
- 阶段 1 防止将核心功能标记为可疑(例如,数据库工具中的 SQL 执行)。
- 阶段 2 确保在没有严重程度偏见的情况下收集证据。
- 阶段 3 在结果报告之前捕获误报。
这种架构在我们的 11 个包测试集中实现了 0% 的误报率,而 v2 版本的误报率为 42%。
🔄 CI/CD 集成
AgentAudit 设计用于 CI 管道,具有适当的退出代码和 JSON 输出:
# GitHub Actions 示例
- name: 扫描 MCP 服务器
run: |
npx agentaudit scan https://github.com/org/mcp-server --json --quiet > results.json
# 退出代码 1 = 发现问题 → 构建失败
# Shell 脚本
agentaudit scan https://github.com/owner/repo --json --quiet 2>/dev/null
if [ $? -eq 1 ]; then
echo "发现安全问题!"
exit 1
fi
JSON 输出示例
# 扫描并输出 JSON
agentaudit scan https://github.com/owner/repo --json
{
"slug": "repo",
"url": "https://github.com/owner/repo",
"findings": [
{
"severity": "high",
"title": "命令注入风险",
"file": "src/handler.js",
"line": 42,
"snippet": "exec(`git ${userInput}`)"
}
],
"fileCount": 15,
"duration": "1.8s"
}
# 注册表查找并输出 JSON
agentaudit lookup fastmcp --json
即将推出:
--fail-on <severity>标志,用于设置非零退出的最低严重程度阈值(例如,--fail-on high忽略低/中等发现)。
⚙️ 配置
凭证
AgentAudit 将凭证存储在 ~/.config/agentaudit/credentials.json(或 $XDG_CONFIG_HOME/agentaudit/credentials.json)中。
可以运行 agentaudit setup 进行交互式配置,也可以通过环境变量设置:
export AGENTAUDIT_API_KEY=asf_your_key_here
环境变量
| 变量 | 描述 |
|----------|-------------|
| AGENTAUDIT_API_KEY | 访问注册表的 API 密钥 |
| ANTHROPIC_API_KEY | 用于深度审计的 Anthropic API 密钥(Claude) |
| OPENAI_API_KEY | 用于深度审计的 OpenAI API 密钥(GPT-4o) |
| NO_COLOR | 禁用 ANSI 颜色(no-color.org) |
🔧 技术细节
- 3 遍审计架构:通过将理解、检测和分类阶段分开,有效降低误报率。
- 正则静态分析:快速扫描使用正则模式匹配,能够快速检测常见的安全问题。
- 深度大语言模型审计:深度审计使用大语言模型进行 3 遍分析,能够检测复杂的攻击链和 AI 特定威胁。
❓ FAQ
如何设置 AgentAudit?
npm install -g agentaudit
agentaudit setup
或者不安装直接使用:npx agentaudit
是否需要 API 密钥?
- 快速扫描 (
scan):无需 API 密钥,使用正则进行本地扫描。 - 深度审计 (
audit):需要 LLM API 密钥(见下文)。 - 注册表查找 (
lookup):读取无需密钥,上传报告需要密钥。 - MCP 服务器:无需额外密钥,使用主机编辑器的大语言模型。
设置深度审计的 LLM 密钥
audit 命令支持 Anthropic(Claude) 和 OpenAI(GPT-4o)。设置以下环境变量之一:
# Linux / macOS
export ANTHROPIC_API_KEY=sk-ant-... # 推荐
export OPENAI_API_KEY=sk-... # 替代方案
# Windows (PowerShell)
$env:ANTHROPIC_API_KEY = "sk-ant-..."
$env:OPENAI_API_KEY = "sk-..."
# Windows (CMD)
set ANTHROPIC_API_KEY=sk-ant-...
set OPENAI_API_KEY=sk-...
优先级:如果同时设置了两个密钥,将使用 Anthropic。审计期间会显示活动的提供商。
故障排除:如果看到 API error: Incorrect API key,请检查密钥是否有效且有余额。使用 --debug 查看完整的 API 响应。
哪些数据会被外部发送?
- 注册表查找:包名称/标识符会发送到
agentaudit.dev以检查现有审计。 - 报告上传:审计结果会上传到公共注册表(需要 API 密钥)。
- 深度审计:源代码会发送到 Anthropic 或 OpenAI 进行大语言模型分析。
- 快速扫描:所有操作都在本地进行,没有数据离开你的机器。
能否离线使用?
快速扫描 (agentaudit scan) 在克隆后可以完全离线工作。注册表查找和深度审计需要网络访问。
能否不使用 CLI 而将其用作 MCP 服务器?
可以!当编辑器调用 npx agentaudit 时,它会启动 MCP 服务器。CLI 和 MCP 服务器是同一个包,其行为由调用方式决定。
discover 如何知道我使用的编辑器?
它会检查 Claude Desktop、Cursor、VS Code 和 Windsurf 的标准配置文件位置。它还会检查当前工作目录中的项目级 .cursor/mcp.json 和 .vscode/mcp.json。
🔗 相关链接
| | 项目 | 描述 | |---|---------|-------------| | 🌐 | agentaudit.dev | 信任注册表 — 浏览包、发现结果、排行榜 | | 🛡️ | agentaudit-skill | 代理技能 — 为 Claude Code、Cursor、Windsurf 提供预安装安全网关 | | ⚡ | agentaudit-github-action | GitHub 动作 — CI/CD 安全扫描 | | 📚 | agentaudit-mcp | 本仓库 — CLI + MCP 服务器源代码 | | 🐛 | 报告问题 | 报告错误和提出功能请求 |
📄 许可证
AGPL-3.0 — 开源使用免费。商业集成可获取商业许可证。
微信扫一扫