🚀 AgentAudit
AgentAudit 是一款專為 AI 包生態系統打造的安全掃描工具,具備 MCP 服務器和 CLI 兩種使用方式。它能對 MCP 服務器、AI 技能和包進行漏洞、提示注入和供應鏈攻擊檢測,採用正則靜態分析和深度大語言模型審計技術。
🚀 快速開始
選項 A:CLI(推薦)
npm install -g agentaudit
agentaudit
agentaudit scan https://github.com/owner/repo
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
💻 使用示例
基礎用法
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 輸出:
- name: 掃描 MCP 服務器
run: |
npx agentaudit scan https://github.com/org/mcp-server --json --quiet > results.json
# 退出代碼 1 = 發現問題 → 構建失敗
agentaudit scan https://github.com/owner/repo --json --quiet 2>/dev/null
if [ $? -eq 1 ]; then
echo "發現安全問題!"
exit 1
fi
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"
}
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)。設置以下環境變量之一:
export ANTHROPIC_API_KEY=sk-ant-...
export OPENAI_API_KEY=sk-...
$env:ANTHROPIC_API_KEY = "sk-ant-..."
$env:OPENAI_API_KEY = "sk-..."
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。
🔗 相關鏈接
📄 許可證
AGPL-3.0 — 開源使用免費。商業集成可獲取商業許可證。