Communitygithub.com

審計 MCP 伺服器以偵測工具毒化

使用 Invariant Labs 的 mcp-scan 對 MCP 伺服器進行靜態與動態分析,以偵測工具毒化、工具影子攻擊、拉地毯詐騙、SSRF 及未經認證的暴露。

審計 MCP 伺服器以偵測工具毒化 是什麼?

這個技能教導 AI 代理如何對使用模型上下文協定 (MCP) 的伺服器進行安全審計。MCP 伺服器會揭露工具及其自然語言描述,這些描述會載入到 LLM 的上下文中,形成一個攻擊面:惡意伺服器可以在工具描述中嵌入隱藏指令(工具毒化攻擊,OWASP MCP03:2025),讓模型在不知情下執行檔案外洩或叫用其他工具等動作。此技能使用 Invariant Labs 的 mcp-scan 進行靜態掃描來偵測毒化、影子攻擊、拉地毯詐騙(透過工具哈希比對)及惡意組合流程,並透過自訂腳本手動測試 SSRF 及認證缺失。支援的平台包括 Claude Desktop、Cursor、VS Code、Windsurf 及任何自訂 MCP 代理堆疊。工作流程包含掃描 MCP 設定檔、檢查原始工具描述、固定工具哈希、以 MCP SDK 列舉工具、對自己擁有的目標測試 SSRF、確認遠端伺服器的認證與網路暴露,以及選擇性部署 mcp-scan 代理以進行即時防護。最終會產出對應 MITRE ATLAS AML.T0010 及 OWASP MCP03:2025 的發現報告。

相容平台✓Claude Code~Codex CLI✓Cursor✓Windsurf
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/auditing-mcp-servers-for-tool-poisoning

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

審計 MCP 伺服器以偵測工具毒化 是做什麼的?

僅限授權使用注意事項: 審計 MCP 伺服器可能會連接並探測實際的工具端點。僅掃描您擁有或獲得授權評估的伺服器。請將掃描到的工具描述視為不受信任的輸入——不要將未經審計的 MCP 伺服器載入到具有特權的代理中。未經許可探測第三方 MCP 端點的 SSRF 或認證弱點可能違法。

概述

模型上下文協定 (MCP) 讓 AI 代理能發現並呼叫由 MCP 伺服器廣告的外部工具。每個工具會揭露一個名稱和自然語言的描述,代理的 LLM 在決定呼叫該工具之前會讀取此描述。2025 年初,Invariant Labs 揭露此描述欄位是一個攻擊面:惡意伺服器可以在工具描述中嵌入隱藏指令(工具毒化攻擊,OWASP MCP03:2025),而一個能力足夠的模型會默默遵循這些指令——外洩檔案、洩露秘密或重新導向工具呼叫——同時向使用者回傳看似正常的回應。由於工具描述會被載入到代理的上下文中,工具毒化本質上是透過供應鏈傳遞的間接提示注入 (MITRE ATLAS AML.T0010 ML 供應鏈危害)。

除了毒化之外,MCP 伺服器還引入了經典的基礎設施風險:工具影子攻擊(惡意伺服器覆蓋可信工具的行為)、拉地毯詐騙(工具描述在使用者批准後改變)、惡意組合流程(允許資料外洩的工具組合)、工具中取得 URL 的 SSRF,以及綁定到網路介面的 MCP 伺服器的未經認證暴露。此技能使用 Invariant Labs 的 mcp-scan 進行靜態與執行時期分析,加上手動檢查 SSRF 和認證,並透過工具固定來捕捉拉地毯詐騙,對 MCP 伺服器進行端到端審計。

使用時機

  • 在將新的 MCP 伺服器加入代理堆疊之前(Claude Desktop、Cursor、VS Code、Windsurf、自訂代理)。
  • 在對內部開發的 MCP 伺服器進行安全審查時。
  • 在驗證已核准的工具是否未在不知不覺中改變時(拉地毯詐騙偵測)。
  • 作為 CI/CD 閘門,在每次變更時掃描 MCP 設定和 SKILL/工具定義。
  • 在事件回應期間,代理採取了與受毒化工具一致的非預期動作時。

先決條件

  • Python 3.10+ 和 uv(用於 uvx),或 pip。
  • 您要掃描的 MCP 設定檔(例如 ~/.cursor/mcp.json、~/.vscode/mcp.json、Claude Desktop 設定)。
  • 安裝工具:
# uv 提供 uvx(mcp-scan 的推薦執行器)
curl -LsSf https://astral.sh/uv/install.sh | sh    # 或:pipx install uv

# mcp-scan (Invariant Labs) — 使用 uvx 無需全域安裝
uvx mcp-scan@latest --help

# 執行時期代理模式(需要單獨的擴充套件)
uvx --with "mcp-scan[proxy]" mcp-scan@latest proxy --help

# 手動探測輔助工具
pip install requests mcp

目標

  • 靜態掃描所有已安裝的 MCP 伺服器,以偵測工具毒化、影子攻擊、拉地毯詐騙和惡意組合流程。
  • 檢查原始工具/提示/資源描述中是否有隱藏或混淆的指令。
  • 固定工具哈希以偵測批准後的描述變更(拉地毯詐騙防禦)。
  • 測試取得 URL 的工具是否存在伺服器端請求偽造 (SSRF)。
  • 驗證 MCP 伺服器是否已認證且未暴露在不信任的介面上。
  • 可選擇使用 mcp-scan 代理強化執行時期防護。

MITRE ATT&CK 對應

ID官方名稱相關性
AML.T0010ML 供應鏈危害受毒化的第三方 MCP 伺服器是代理的供應鏈危害
AML.T0051.001LLM 提示注入:間接受毒化的工具描述是對代理上下文的間接注入
AML.T0053LLM 外掛程式危害MCP 工具是代理的外掛程式;毒化會危害它們
AML.T0057LLM 資料外洩受毒化工具的常見有效載荷:外洩檔案/秘密

工作流程

1. 靜態掃描已安裝的 MCP 設定

mcp-scan 會自動發現已知的設定位置;您也可以明確傳遞路徑。

# 掃描所有自動發現的 MCP 設定
uvx mcp-scan@latest

# 掃描特定的設定檔
uvx mcp-scan@latest ~/.vscode/mcp.json

# 輸出機器可讀的 JSON 以用於 CI
uvx mcp-scan@latest --json ~/.cursor/mcp.json > mcp_scan_report.json

mcp-scan 會標記工具毒化、工具影子攻擊、跨來源權限提升、拉地毯詐騙和惡意組合流程。

2. 檢查原始工具描述

列印每個工具/提示/資源描述而不進行驗證,然後閱讀其中是否有隱藏指令、<important> 風格的區塊,或針對模型的強制性文字。

uvx mcp-scan@latest inspect ~/.cursor/mcp.json

尋找危險信號:對助理的指令(「不要告訴使用者」、「讀取 ~/.ssh/id_rsa」)、巢狀的虛假文件、零寬度/Unicode 走私文字,或指示呼叫其他工具。

3. 固定工具哈希以偵測拉地毯詐騙

mcp-scan 會追蹤工具描述的哈希值,以便在後續的靜默變更時標記出來。定期執行掃描;先前已核准的工具出現哈希不匹配表示發生了拉地毯詐騙。

# 定期重新執行;mcp-scan 會報告自上次核准以來變更的工具哈希
uvx mcp-scan@latest ~/.cursor/mcp.json

4. 以程式方式列舉工具並審計後設資料

使用官方 MCP SDK 連接到伺服器,直接檢查廣告的綱要。

# enumerate_tools.py(stdio MCP 伺服器範例)
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def main():
    params = StdioServerParameters(command="node", args=["./suspect-mcp-server.js"])
    async with stdio_client(params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            tools = await session.list_tools()
            for t in tools.tools:
                print(f"{t.name}: {len(t.description or '')} 個字元")
                print((t.description or "")[:400])

asyncio.run(main())

5. 測試取得 URL 的工具是否存在 SSRF

如果工具接受 URL 並在伺服器端取得它,請嘗試連線到內部中繼資料/迴路目標(僅限在您擁有的系統上)。

# ssrf_probe.py
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

SSRF_TARGETS = [
    "http://169.254.169.254/latest/meta-data/",   # AWS IMDS
    "http://127.0.0.1:22/", "http://localhost:6379/", "file:///etc/passwd",
]

async def main():
    params = StdioServerParameters(command="node", args=["./suspect-mcp-server.js"])
    async with stdio_client(params) as (r, w):
        async with ClientSession(r, w) as s:
            await s.initialize()
            for url in SSRF_TARGETS:
                res = await s.call_tool("fetch_url", {"url": url})
                body = str(res.content)[:200]
                print(f"[SSRF?] {url} -> {body}")

asyncio.run(main())

6. 驗證認證與網路暴露

檢查遠端 MCP 伺服器(HTTP/SSE 傳輸)是否需要認證,且是否未綁定到不信任網路上的 0.0.0.0。

# 確認 SSE/HTTP MCP 端點是否在無憑證下回應
curl -s -i http://mcp-host:8000/sse | head -n 20

# 檢查本機執行中 MCP 伺服器的監聽介面
ss -tlnp | grep -E ':(8000|3000|6277)'

返回工具列表或接受 tools/call 而無需認證的 MCP 端點即為未經認證的暴露——應使用令牌/OAuth 進行修復,並綁定到 localhost 或經過認證的閘道。

7. 強化執行時期防護(可選)

為了持續保護,將代理的 MCP 流量路由通過 mcp-scan 代理,它會即時檢查工具呼叫、資料流限制、PII 和間接注入。

uvx --with "mcp-scan[proxy]" mcp-scan@latest proxy

8. 報告發現

針對每個發現記錄伺服器、工具、證據(受毒化的描述 / SSRF 回應 / 未經認證的列表)、嚴重性以及 ATLAS 對應。建議移除或沙箱化受毒化的伺服器、加入認證、固定已核准的工具,並啟用代理。

工具與資源

工具用途來源
mcp-scan靜態 + 執行時期 MCP 安全掃描器https://github.com/invariantlabs-ai/mcp-scan
MCP Python SDK程式化工具列舉/呼叫https://github.com/modelcontextprotocol/python-sdk
OWASP MCP Top 10MCP 風險參考 (MCP03 工具毒化)https://owasp.org/www-project-mcp-top-10/
Invariant Labs 部落格工具毒化揭露https://invariantlabs.ai/blog/introducing-mcp-scan
MITRE ATLASAI 威脅技術分類法https://atlas.mitre.org/

MCP 威脅參考

威脅描述偵測方式
工具毒化工具描述中的隱藏指令mcp-scan 掃描 / 檢查
工具影子攻擊惡意伺服器覆蓋可信工具mcp-scan 跨來源檢查
拉地毯詐騙描述在批准後變更mcp-scan 工具固定(哈希)
惡意組合流程允許外洩的工具組合mcp-scan 惡意組合流程分析
SSRF取得 URL 的工具連線到內部目標針對擁有的伺服器執行 ssrf_probe
未經認證暴露無認證的 MCP 端點curl/ss 介面與認證檢查

驗證標準

  • 所有已安裝的 MCP 設定已使用 mcp-scan 靜態掃描
  • 原始工具/提示/資源描述已檢查是否有隱藏指令
  • 工具哈希已固定且拉地毯詐騙偵測已啟用
  • 已透過 MCP SDK 以程式方式列舉工具
  • 已對擁有的目標測試取得 URL 的工具是否存在 SSRF
  • 已驗證遠端伺服器的認證與網路暴露
  • 已評估或在適當處部署執行時期代理防護
  • 發現已對應到 MITRE ATLAS AML.T0010 和 OWASP MCP03:2025
  • 已為每個發現指派嚴重性並記錄修復方式
  • 已排程重新掃描以捕捉未來的拉地毯詐騙

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

相關技能