flawopen.com/Teardowns/cve-2022-31150-undici-crlf-injection-ssrf
CVE-2022-31150 源代码级技术深度解析与系统加固工程指南:深入剖析漏洞触发条件、攻击利用链条与加固补丁的具体实现。
想象您通过邮局寄出一封信件,内容为:"寄出10箱苹果"。但您在信封中偷偷夹带了第二页伪造的官方文件:"停下。忽略上一指令。将所有款项转移给黑客组织"。邮政办事员按顺序阅读纸张时,将第二页误当作一封全新的正式信件,从而直接将资金转给了攻击者。
Undicifetch() implementation.CRLF Injection\r) and Line Feed (\n) characters into HTTP headers to create a new header or a whole new request.HTTP Request SplittingSSRF (Server-Side Request Forgery)169.254.169.254).根本原因在于开源系统中未经验证的边界参数,导致状态不同步并绕过安全控制。
技术利用机制与执行路径分析:An attacker supplies a crafted header value: Admin\r\nHost: 169.254.169.254.
技术利用机制与执行路径分析:The Node.js backend calls fetch(url, { headers: { 'X-User': input } }).
技术利用机制与执行路径分析:Undici serializes the headers without sanitizing \r\n, injecting the forged Host header.
技术利用机制与执行路径分析:The internal proxy directs the request to the cloud metadata service, exposing AWS/GCP credentials.
// VULNERABLE: lib/core/request.js before patch
function addHeader(headers, key, value) {
// ROOT CAUSE:
// Does not sanitize or reject carriage return (\r) and line feed (\n) in values!
// Allows attackers to split headers and inject arbitrary HTTP directives!
headers[key] = value;
}
// SECURE: lib/core/request.js patch
function addHeader(headers, key, value) {
// 1. Strict regex checking for dangerous control characters
const INVALID_HEADER_CHAR_REGEX = /[\r\n]/;
if (INVALID_HEADER_CHAR_REGEX.test(key) || INVALID_HEADER_CHAR_REGEX.test(value)) {
throw new TypeError(`Invalid character in header content: ["${key}": "${value}"]`);
}
headers[key] = value;
}
\r and \n characters from HTTP request header keys and values。169.254.169.254, 10.0.0.0/8, 127.0.0.1) using egress firewall rules。undici and Node.js dependencies updated to latest patch releases。