十年匠心定制 · 商业建站与技术教学双线并行 咨询热线:400-886-1026 service@lmnt.cn
ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

AI-Infra-Guard MCP 扫描全指南:Agent 驱动的 MCP Server 安全审计、多轮红队对抗与插件化漏洞检测

AI-Infra-Guard MCP 扫描全指南:Agent 驱动的 MCP Server 安全审计、多轮红队对抗与插件化漏洞检测 AI-Infra-Guard MCP 扫描全指南Agent 驱动的 MCP Server 安全审计、多轮红队对抗与插件化漏洞检测【免费下载链接】AI-Infra-GuardA full-stack AI Red Teaming platform securing AI ecosystems via Agent Scan, Skills Scan, MCP scan, AI Infra scan and LLM jailbreak evaluation.项目地址: https://gitcode.com/GitHub_Trending/ai/AI-Infra-Guard本篇技术指南围绕 AI-Infra-Guard 的 MCP 扫描MCP Scan能力展开系统讲解其基于 AI Agent 驱动的 MCP Server 安全检测方案从九大类 MCP 特有安全风险识别、三种扫描输入方式源码压缩包、代码仓库、远程 SSE/Streamable HTTP 服务、多轮自动化红队攻击Crescendo / TAP 双策略到插件化的漏洞检测提示词体系。读完本文你将掌握如何在 AIG 平台 Web 界面完成一次完整的 MCP Server 安全扫描理解底层mcp-scan模块的检测原理与 SARIF 输出并能通过RedTeamOrchestrator独立运行多轮对抗测试。为什么 MCP Server 需要专门的安全扫描MCPModel Context Protocol作为 AI Agent 与外部工具、数据源的通用连接器其安全性直接决定整个 Agent 生态的信任边界。与传统 Web 服务不同MCP Server 的攻击面包含提示词注入、工具投毒、上下文劫持等 Agent 特有风险——这些无法用常规 Web 漏洞扫描器覆盖。A.I.GAI-Infra-Guard使用基于 AI Agent 驱动的 MCP Server 安全检测方案同时支持 MCP Server源代码安全审计与远程 MCP Server URL 安全扫描两种模式。检测能力完全由 Agent 驱动检测准确性与耗时取决于所选大模型 API 的能力因此对模型配置有明确要求。九大类 MCP Server 安全风险A.I.G 持续更新维护以下常见 MCP Server 安全风险检测项风险名称风险说明工具投毒攻击恶意 MCP Server 通过工具描述注入隐藏指令操纵 AI Agent 执行未授权操作例如窃取数据、执行恶意行为。地毯式骗局恶意 MCP Server 在初期表现正常但在用户批准或运行若干次后改变行为执行恶意指令导致难以察觉的恶意行为。工具覆盖攻击恶意 MCP Server 通过隐藏指令重新定义其他可信 MCP Server 工具的行为例如修改邮件接收者、执行额外操作。恶意代码/命令执行MCP Server 若支持直接执行代码或命令且缺乏沙箱隔离可能被攻击者利用在服务器或用户本地执行恶意操作。数据窃取恶意 MCP Server 诱导 AI Agent 读取并传输敏感数据例如 API 密钥、SSH 密钥或直接将用户授权输入的数据发送至外部服务器。未授权访问/鉴权不当MCP Server 缺乏有效授权认证或存在缺陷导致攻击者可绕过验证访问受限资源或用户数据。间接提示词注入MCP Server 将包含恶意指令的外部数据例如网页、文档输出给 AI Agent可能影响 AI Agent 的决策和行为。包名混淆与抢注攻击恶意 MCP Server 使用与可信服务相似的名称、工具名或描述诱导 AI Agent 错误调用或第三方抢注官方 AI 工具名称植入后门。明文存储密钥MCP Server 在代码或配置文件中硬编码或明文存储敏感密钥易导致泄露风险。上述风险在底层扫描器中对应更细粒度的规则体系。在 mcp-scan 的 SARIF 格式化器 中实现了MCP 特有的 10 类风险分类MCP01–MCP10 3 个补充分类与本表的风险图谱一一对应规则 ID名称说明MCP01令牌管理与密钥暴露凭据窃取与密钥泄露MCP02权限提升与范围蔓延工具权限定义过宽MCP03工具投毒攻击合法工具被注入恶意逻辑MCP04软件供应链攻击依赖库篡改、恶意第三方服务器MCP05命令注入与执行不可信输入构造系统命令MCP06提示注入攻击上下文注入恶意指令劫持模型MCP07认证与授权不足身份校验缺失导致越权MCP08审计与遥测缺失缺乏不可篡改的调用日志MCP09影子 MCP 服务器未经授权部署的 MCP 实例MCP10上下文注入与过度分享敏感上下文跨会话泄露Name Confusion名称混淆攻击相似名称诱导错误调用Rug Pull Attack拉地毯攻击获取信任后突然变更行为Tool Shadowing Attack工具阴影攻击重定义同名工具覆盖合法行为前置条件添加用于检测的模型 APIMCP 扫描能力由 AI Agent 驱动因此在首次使用前必须配置大模型 API。在 AIG Web 界面的模型配置区域添加 LLM API Key 与模型名称平台推荐使用以下大模型 API 以获得稳定、准确的检测效果Hy3GLM-5.3DeepSeek-V4Kimi-K3Qwen3-Coder-480B-A35B-Instruct从源码看mcp-scan 的 LLM 封装 与 LLM 管理器 支持为不同任务配置专用模型思考、编码、快速响应等。对应环境变量模板见 mcp-scan/env.example核心项包括# OpenRouter API Key必需 OPENROUTER_API_KEYyour-api-key-here # 默认模型 DEFAULT_MODELdeepseek/deepseek-v3.2-exp # API 基础 URL DEFAULT_BASE_URLhttps://openrouter.ai/api/v1 # Thinking 模型用于深度推理 THINKING_MODELgoogle/gemini-2.5-pro THINKING_BASE_URLhttps://openrouter.ai/api/v1 # Coding 模型用于代码生成和分析 CODING_MODELanthropic/claude-sonnet-4.5 CODING_BASE_URLhttps://openrouter.ai/api/v1配置优先级从高到低为命令行参数 环境变量 代码默认值。未显式传入 API Key 时CLI 会依次回退到LLM_API_KEY、OPENAI_API_KEY、OPENROUTER_API_KEY环境变量见 mcp-scan/mcp_scan/main.py。方式一MCP Server 源代码压缩包扫描适用场景本地已有 MCP Server 源码包需要离线提交检测。选择MCP扫描添加附件上传源代码压缩包开始扫描。方式二MCP Server 代码仓库扫描适用场景MCP Server 托管在代码托管平台可直接拉取公开仓库。选择MCP扫描输入框输入代码仓库地址如https://github.com/xxx/mcp-server开始扫描。方式三远程 MCP 服务扫描适用场景目标 MCP Server 已部署运行需要直接探测其远程端点。选择MCP扫描输入框输入 MCP 服务地址支持SSE或Streamable HTTP协议如http://127.0.0.1:9000/sse开始扫描。这一场景对应扫描器的动态分析模式CLI 中通过--server_url参数指定远程地址参见 mcp-scan/README_zh.md可配合--header key:value多次传入自定义 HTTP 头用于鉴权、内网等场景例如python main.py \ --server_url http://localhost:8000/sse \ --prompt 测试工具投毒漏洞查看扫描状态和结果扫描任务提交后Web 前端会实时展示扫描进度与结果。三阶段流水线信息收集 → 代码审计 → 漏洞整理的进度与中间结果实时刷新最终生成包含漏洞详情、风险等级和安全评分的完整报告底层流水线与 SARIF 输出从 mcp-scan/README_zh.md 可知扫描器支持两种模式单阶段模式CLI 默认静态预扫描正则扫描 14 类高危模式覆盖curl|bash、云元数据、凭据窃取等→ 代码审计 → 输出 SARIF 2.1.0 JSON。速度约为三阶段的 3 倍适合 CI/CD 集成。三阶段模式--aig-mode信息收集分析项目结构、识别技术栈、判断是否 Agent Skill→ 代码审计深度分析、识别安全问题若为 Skill 项目执行一致性审计→ 漏洞整理风险评级、生成报告。结构化 JSON 日志通过mcpLogger输出到 stdout由 Go 后端解析后推送到前端实时展示。Web 界面的执行链路为用户提交任务 → Go 后端分发给 Agent 进程 → Agent 自动以--aig-mode调用 mcp-scan对应 mcp-scan/main.py 这个薄层入口供 common/agent/mcp_task.go 调用→ 结构化日志回传前端。CLI 独立使用时默认输出SARIF 2.1.0JSON可被 GitHub Code Scanning、Azure DevOps、GitLab Security Dashboard、VS Code Problems 面板等 SARIF-aware 工具原生消费# 基础扫描默认单阶段模式 python main.py --repo ./myproject # 保存结果到文件 python main.py --repo ./myproject -o result.sarif.json # 使用特定模型 python main.py --repo ./myproject -m anthropic/claude-3.5-sonnet # 使用环境变量提供 API Key无需 --api_key export LLM_API_KEYsk-or-v1-xxxxx python main.py --repo ./myproject # 自定义提示词 debug 模式 python main.py --repo ./myproject --prompt 重点检查 SQL 注入漏洞 --debugSARIF 结果中rules静态声明完整的 MCP01–MCP10 3 个补充规则即使本次未发现也总是输出results每条漏洞映射到规则 ID包含levelerror/warning/note、locations文件行号、partialFingerprints去重哈希、fixes修复建议properties记录安全评分、主语言、所用 LLM 与扫描时间。多轮自动化红队攻击Multi-Turn Red Team除常规扫描外A.I.G 内置了面向 MCP Server 的多轮自动化红队攻击子模块通过Attacker / Target / Evaluator 三个 LLM 角色协作对 MCP Server 源码进行深度对抗测试。模块代码位于 mcp-scan/mcp_scan/redteam/运行前需在mcp-scan项目根目录下安装依赖uv sync或pip install -r requirements.txt。三角色协作架构从 redteam 包 README 与 编排器实现 可以还原整体架构┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ Attacker Agent │ ──► │ Target Runner │ ──► │ Evaluator Agent │ │ 生成攻击 prompt │ │ 与 MCP 交互/模拟 │ │ 打分 1-10 与判定 │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ │ │ └────────────────────────┴────────────────────────┘ RedTeamOrchestratorAttacker Agent根据攻击目标与对话历史用 LLM 生成下一轮攻击消息输出 JSONthought/message/attack_technique/reflectionTarget Runner当前为源码分析模式——复用 mcp-scan 的代码读取能力收集仓库上下文由 LLM 模拟 MCP Server 对攻击的响应不实际启动 MCP 进程Evaluator Agent对每轮攻击消息 目标响应判定是否紧扣目标on_topic、打分 1–10score、是否已达成攻击目标is_successful。支持的攻击策略策略说明Crescendo渐进式多轮升级建立信任 → 试探边界 → 逐步升级 → 发起攻击TAPTree of Attacks with Pruning每轮生成多个攻击变体后经两阶段剪枝保留最优路径逐层深入从 strategy.py 的实现看Crescendo 划分为build_trust建立信任、probe_boundary试探边界、escalate逐步升级、launch_attack发起攻击四个阶段可配置每阶段最大轮数、总轮数默认max_rounds_per_phase3、max_total_rounds20与晋级最低分默认min_score_to_advance5.0。TAP 则对每个叶节点生成branch_factor个变体Evaluator 打分后执行两阶段剪枝先按on_topic过滤再按score保留 top-k仅对保留节点继续扩展。预定义攻击目标OWASP Agentic Top 10 对齐红队模块预定义了 6 个与 OWASP Agentic Top 10 对齐的攻击目标常量ATTACK_TARGETS定义于 mcp-scan/mcp_scan/redteam/init.py目标标识说明data_exfiltration数据窃取indirect_prompt_injection间接提示注入ssrf_via_agent经 Agent 的 SSRFrce_via_tool经工具的 RCEprivilege_escalation权限提升tool_poisoning工具投毒使用方式import asyncio from mcp_scan.redteam import RedTeamOrchestrator, generate_report async def main(): orch RedTeamOrchestrator( api_keyyour-api-key, base_urlhttps://openrouter.ai/api/v1, modeldeepseek/deepseek-v4-pro, repo_dirpath/to/your/mcp/server/repo, ) result await orch.run(data_exfiltration, strategy_namecrescendo, max_total_rounds8) print(generate_report(result)) asyncio.run(main())参数说明api_key必填也可省略后自动从环境变量OPENROUTER_API_KEY/API_KEY读取未设置时会抛出说明性错误见 orchestrator.pybase_url/model默认从utils.config的DEFAULT_MODEL、DEFAULT_BASE_URL读取strategy_namecrescendo或tap对应统一入口run()的分发逻辑策略参数Crescendo 可传max_rounds_per_phase、max_total_roundsTAP 可传branch_factor、top_k、max_depth。调用generate_report(result)会根据result[strategy]生成 Markdown 攻击报告包含各轮/各节点的攻击消息摘要、得分与是否成功等信息便于复现与审计。相关测试用例见 mcp-scan/pytests/test_redteam_llm_requests.py。MCP 插件体系MCP 扫描基于 AI Agent 对代码进行检测A.I.G 将 MCP 漏洞抽象为插件可在前端查看与维护插件模板的关键字段是prompt_template——用提示词告诉大模型漏洞类型与应如何扫描。以下是完整的鉴权绕过Authentication Bypass检测插件模板info: id: auth_bypass name: Authentication Bypass Detection description: Detect possible authentication bypass vulnerabilities in MCP code author: Zhuque Security Team categories: - code prompt_template: | As a professional cybersecurity analyst, you need to precisely detect authentication bypass vulnerabilities in MCP code. This detection requires extremely high accuracy - only report when you find concrete evidence of authentication bypass risks. ## Vulnerability Definition Authentication bypass refers to an attackers ability to gain unauthorized access by circumventing the systems authentication mechanisms without providing valid credentials. ## Detection Criteria (Must meet at least one concrete evidence) ### 1. Hardcoded Credential Vulnerabilities **Required Conditions:** - Discovery of plaintext stored real credentials (not test/example data) - Credentials have actual system access privileges - Ability to obtain valid authentication information directly through code - Existence of backdoors that bypass normal authentication processes **Code Patterns:** - Hardcoded API keys, passwords, tokens - Universal passwords or backdoor accounts - Special parameters or flags that bypass authentication ### 2. JWT Security Flaws **Required Conditions:** - Missing or bypassable JWT signature verification - Use of weak signature algorithms (e.g., none, HS256 with weak keys) - JWT key leakage or predictability - JWT replay attack vulnerabilities **Detection Points:** - verifyFalse or skipping signature verification - Using fixed or weak JWT keys - Missing timestamp verification (exp, iat) - Allowing algorithmnone JWT ### 3. OAuth Authentication Flaws **Required Conditions:** - Missing or loose redirect_uri validation - Missing state parameter leading to CSRF attacks - client_secret leakage or hardcoding - Authorization code reuse or no time limits ### 4. Session Management Vulnerabilities **Required Conditions:** - Session fixation attacks - Session hijacking risks (missing secure/httponly flags) - Missing session timeout mechanisms - Missing Cross-Site Request Forgery (CSRF) protection ### 5. Authentication Logic Bypass **Required Conditions:** - Conditional bypass in authentication check logic - Logic errors in permission judgment - Ability to skip steps in multi-step authentication process - Missing or misconfigured authentication middleware ## Technical Detection Methods ### Code Pattern Recognition **High-Risk Patterns:** - if user admin and password hardcoded_password - jwt.decode(token, verifyFalse) - session[authenticated] True # Setting without verification - app.route(/admin) # Missing authentication decorator ### Configuration File Analysis - Check security of authentication-related configurations - Verify if default credentials have been changed - Analyze completeness of access control lists ### API Endpoint Security - Identify sensitive interfaces lacking authentication protection - Check correct application of authentication middleware - Verify granularity and completeness of permission control ## Exclusion Conditions (Do not report the following) ### Normal Development Scenarios - Mock authentication in test code - Temporary credentials in development environment - Fixed test data in unit tests - Placeholder credentials in example code ### Security Practices - Correctly implemented OAuth2.0 flows - Secure JWT implementations (strong signatures, complete verification) - Comprehensive session management mechanisms - Appropriate RBAC permission control ### Configuration Management - Credentials managed through environment variables - Implementations using key management services - Correct configuration file permission settings ## Verification Requirements 1. **Vulnerability Exploitability**: Must be able to construct actual attack paths 2. **Impact Assessment**: Clearly define access privileges after bypassing authentication 3. **Technical Details**: Provide specific vulnerability principle analysis 4. **Remediation Suggestions**: Provide clear security hardening solutions ## Strict Judgment Standards - **Default Configuration**: If its framework default configuration with documentation, do not report - **Test Identifiers**: Do not report those containing test, demo, example, mock keywords - **Development Environment**: Do not report configurations clearly used for development debugging - **Correct Implementation**: Do not report authentication implementations that follow security best practices - **Permission Verification Project Level Assessment**: If no permission verification exists, assess whether the project information collection indicates an important project (i.e., capable of operating local host or database operations). If the project is not important, do not report ## Input Data Source code path: {{ .CodePath }} Directory structure: ------ {{ .DirectoryStructure }} ------ ## Output Requirements Only output when finding concrete authentication bypass vulnerabilities: - Specific file paths and line numbers - Complete vulnerability code snippets - Technical analysis: vulnerability principles and exploitation methods - Impact assessment: privileges obtainable after bypassing authentication - Attack paths: specific exploitation steps - Remediation suggestions: detailed security hardening solutions **Strict Requirement: Must provide complete vulnerability exploitation paths and impact analysis. Remain silent when no concrete evidence exists.**这个模板展示了插件体系的设计要点info元信息id、name、description、author、categories如code用于在前端展示与检索prompt_template提示词工程这是插件的灵魂通过漏洞定义 → 检测标准 → 技术方法 → 排除条件 → 验证要求 → 严格判定标准 → 输入数据 → 输出要求八段式结构把安全专家的检测方法论完整编码为 LLM 可执行的指令模板变量注入{{ .CodePath }}与{{ .DirectoryStructure }}由扫描器在运行时注入真实项目上下文源码路径与目录树使提示词与实际目标强绑定低误报设计模板明确要求仅在发现具体证据时输出并列出排除条件测试代码、示例凭据、框架默认配置、正确实现配合严格判定标准控制报告质量。提示词加载与注入逻辑可在 mcp-scan/mcp_scan/utils/prompt_manager.py 与 Agent 实现 中进一步查阅——Agent 在扫描前会注入项目目录树作为上下文并通过 Challenge 机制检测工具结果中的敏感模式、对工具结果做截断防止上下文溢出。实战建议模型选择决定检测质量MCP 扫描完全由 Agent 驱动优先使用平台推荐的大模型如 GLM-5.3、DeepSeek-V4、Qwen3-Coder-480B-A35B-Instruct或为思考/编码任务配置专用模型以平衡准确率与耗时。按场景选择输入方式有源码用方式一/方式二审计更彻底支持文件行号级定位目标已部署用方式三SSE / Streamable HTTP 远程探测内网鉴权场景记得通过--header附加认证头。CI/CD 集成用 CLI SARIF单阶段模式速度快约 3 倍输出 SARIF 2.1.0 可被 GitHub Code Scanning、Azure DevOps、GitLab 等原生消费适合流水线门禁。深度对抗用多轮红队对高危 MCP Server 源码运行 Crescendo渐进式信任升级或 TAP多分支剪枝搜索策略覆盖数据窃取、间接提示注入、经工具 RCE 等 OWASP Agentic Top 10 场景用 Markdown 报告沉淀攻击路径。扩展检测能力用插件参照auth_bypass模板编写新的漏洞检测插件核心是打磨prompt_template的检测标准与排除条件控制误报、提升可解释性。所有检测能力均落地在 mcp-scan 子项目中完整 CLI 参数表、SARIF 规则体系与开发指南可查阅 mcp-scan/README_zh.md红队模块细节见 mcp-scan/mcp_scan/redteam/README.md。【免费下载链接】AI-Infra-GuardA full-stack AI Red Teaming platform securing AI ecosystems via Agent Scan, Skills Scan, MCP scan, AI Infra scan and LLM jailbreak evaluation.项目地址: https://gitcode.com/GitHub_Trending/ai/AI-Infra-Guard创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表