WinRAR 目录穿越漏洞(CVE-2018-2025[0-3])

0x00 漏洞描述

Check Point 团队爆出了一个关于 WinRAR 存在 19 年的漏洞,用它来可以获得受害者计算机的控制。攻击者只需利用此漏洞构造恶意的压缩文件,当受害者使用 WinRAR 解压该恶意文件时便会触发漏洞。

该漏洞是由于 WinRAR 所使用的一个陈旧的动态链接库 UNACEV2.dll 所造成的,动态链接库的作用是处理 ACE 格式文件。而 WinRAR 解压ACE文件时,由于没有对文件名进行充分过滤,导致存在目录穿越漏洞,允许解压过程将恶意文件写入任意目录,甚至 写入开机启动项,导致代码执行。

由于 UNACEV2.dll 动态链接库还被市面上一些支持 .ace 格式文件 的解压缩软件所使用,因此除 WinRAR 之外的众多压缩工具、文件管理工具,可能也会存在相同的代码执行风险。

WinRAR 代码执行相关的 CVE 编号如下:

CVE-2018-20250, CVE-2018-20251, CVE-2018-20252, CVE-2018-20253

漏洞名称 CVE编号 描述
ACE文件验证逻辑绕过漏洞 CVE-2018-20250 In WinRAR versions prior to and including 5.61, There is path traversal vulnerability when crafting the filename field of the ACE format (in UNACEV2.dll). When the filename field is manipulated with specific patterns, the destination (extraction) folder is ignored, thus treating the filename as an absolute path. 在WinRAR 5.61之前的版本中,创建ACE格式文件的filename时存在路径穿越漏洞(在UNACEV2.dll中)。当使用特定的模式操作filename时,解压时将忽略目标(提取)文件路径,而将文件名视为绝对路径进行提取。
ACE文件名逻辑验证绕过漏洞 CVE-2018-20251 In WinRAR versions prior to and including 5.61, there is path traversal vulnerability when crafting the filename field of the ACE format. The UNACE module (UNACEV2.dll) creates files and folders as written in the filename field even when WinRAR validator noticed the traversal attempt and requestd to abort the extraction process. the operation is cancelled only after the folders and files were created but prior to them being written, therefore allowing the attacker to create empty files and folders everywhere in the file system. 在WinRAR 5.61之前的版本中,创建ACE格式文件的filename时存在路径穿越漏洞。UNACEV2.dll按照filename中写入的内容创建文件和文件夹,即使WinRAR校验器注意到目录穿越尝试并请求中止提取过程,只有在创建了文件夹和文件之后(写入内容之前)操作才会被取消,因此允许攻击者在文件系统的任何地方创建空文件和空文件夹。
ACE/RAR文件越界写入漏洞 CVE-2018-20252 In WinRAR versions prior to and including 5.60, there is an out-of-bounds write vulnerability during parsing of crafted ACE and RAR archive formats. Successful exploitation could lead to arbitrary code execution in the context of the current user. 在WinRAR 5.60之前的版本中,对ACE和RAR格式文件进行解析时,存在越界写入漏洞,成功利用可能导致在当前用户的上下文中执行任意代码。
LHA/LZH文件越界写入漏洞 CVE-2018-20253 In WinRAR versions prior to and including 5.60, There is an out-of-bounds write vulnerability during parsing of a crafted LHA / LZH archive formats. Successful exploitation could lead to arbitrary code execution in the context of the current user. 在WinRAR 5.60之前的版本中,对LHA和LZH格式文件时进行解析时,存在越界写入漏洞,成功利用可能导致在当前用户的上下文中执行任意代码。

参考链接:http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=WinRAR

0x01 影响范围

  1. 发布时间早于 5.70 Beta 1 版本的所有 WinRAR 软件;
  2. 使用 UNACEV2.dll 动态链接库的解压、文件管理类工具软件,如:

Bandizip < = 6.2.0.0
好压(2345 压缩) < = 5.9.8.10907
360压缩 < = 4.0.0.1170

0x02 漏洞利用

方式一:使用开源 EXP 生成压缩格式为 ace 的恶意 rar 文件。

方式二:手动创建恶意ace文件(具体见 https://www.cnblogs.com/fox-yu/p/10495236.html)

  1. 使用 WinACE 创建一个 ace 文件;
  2. 使用 acefile 查看该文件头部信息;
  3. 使用 WinHex 修改文件解压缩路径;
  4. 同时修改 hdr_size 以及 hdr_crc 以及路径长度;
  5. 再用 acefile 校验修改后的结果;
  6. 解压实现攻击。

利用测试(方式一):

利用开源的 exp 生成恶意 ace 压缩文件 test-exp.rar(其中包含3个文件,如图所示),右键解压到当前文件目录后,发现在本地生成了两个正常的 txt 文件,而在开始菜单的启动项中生成了一个hi.exe的可执行文件,目录穿越成功。

文件解压时写入的实际路径如下:

漏洞利用条件:

由于产生漏洞的DLL文件:UNACEV2.DLL,不能识别相对路径,只能识别绝对路径。因此攻击者在利用漏洞时需要硬编码写入一个相对于当前目录的一个绝对路径,比如:C:..\..\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\test.exe,并且攻击不能跨盘符

因此攻击能否成功,需要取决于受害者进行解压文件触发漏洞时是否在系统盘,且在不知道计算机主机名的情况下,只能在主浏览器的默认下载路径下(C:\Users\Administrator\Downloads)或者桌面进行解压,或者多猜几个启动项路径。

0x03 检测方案

  1. 读取压缩文件的十六进制内容,根据头部特征判断是否为 ACE 格式文件;
  2. 读取压缩文件的十六进制内容,识别其默认解压路径(filename)是否为绝对路径(以 ASCII 字符形式存在,中文会出现乱码);
  3. 读取压缩文件的十六进制内容,识别其默认解压路径(filename)是否包含有敏感路径;
  4. 读取压缩文件的十六进制内容,识别其中是否包含有可执行文件。

ACE 文件特征头部

在 WinHex 中以十六进制查看 ACE 文件头部。

正常ace文件test1.ace

正常ace文件test2.ace

上文构造的恶意ace文件test-exp.rar

1
2
3
// ACE 文件特征头部
HEX:31000000902A2A4143452A2A14140200
ASCII:1 **ACE**

ACE 文件中存在的目的路径及文件名

上文构造的恶意ace文件test-exp.rar

1
2
3
4
5
6
7
// filename字段值
HEX:433A5C433A433A2E2E2F417070446174615C526F616D696E675C4D6963726F736F66745C57696E646F77735C5374617274204D656E755C50726F6772616D735C537461727475705C68692E657865
ASCII:
C:\C:C:../AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\hi.exe

// filename头部起始标志位
HEX:0A005445XX00

检测方式:是否为绝对路径 + 是否为开机自启动路径 + 是否包含可执行文件后缀名。

一些 Windows 版本的自启动路径如下:

Win2003 开机启动项路径:C:\Documents and Settings\Administrator\「开始」菜单\程序\启动

Win2008 开机启动项路径:C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Win2012 开机启动项路径:C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Win7 开机启动项路径:C:\Users\用户\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Win8.1 开机启动项路径:C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

Win10 开机启动项路径:C:\Users\用户\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

除 Win 2003 中文版外共有的启动路径特征:\Microsoft\Windows\Start Menu\Programs\Startup

参考文章:
漏洞的详细分析:https://xz.aliyun.com/t/4221
攻击利用方式:https://www.freebuf.com/column/201214.html