更多信息:
RARLAB WinRAR 目录遍历远程代码执行漏洞。此漏洞允许远程攻击者在受影响的 RARLAB WinRAR 安装上执行任意代码。漏洞利用需要用户交互,即目标必须访问恶意页面或打开恶意文件。
具体缺陷存在于存档文件中文件路径的处理。精心构造的文件路径可导致进程遍历到意外的目录。攻击者可利用此漏洞在当前用户上下文中执行代码。之前编号为 ZDI-CAN-27198。
发布时间 2025-06-21 00:09:03 更新时间 2025-06-23 20:16:22 来源 Zero Day Initiative
漏洞类别:目录遍历 | 执行代码
这是 CVE-2025-6218 WinRAR 路径遍历漏洞的一个非常简洁的概念验证。(还包括:我用于漏洞测试的 RAR 格式工具集)
概念验证中不包含路径遍历到 RCE 的完整利用链,但在 Windows 上从任意文件写入到 RCE 是轻而易举的。
创建概念验证:
$ python3 cve-2025-6218.py
如果你解压此存档,test.txt 将会被解压到当前目录的上一级目录。
该问题源于 WinRAR 可执行文件(版本 7.11 及之前)在清理空格与扫描路径遍历之间存在特定冲突:
一个经过简化和清理的版本:
void file_name_check(char *a1){
cur_filename = a1;
j = 0;
cur_pos = 0;
if ( *(a1 + 4) > 0 )
{
offset = 0;
while ( 1 )
{
if ( (cur_pos + 1) == cur_filename[2] )
goto BREAK;
str = cur_filename;
if ( cur_filename[3] > 7 )
str = *cur_filename;
if ( str[offset + 1] == '\\' || str[offset + 1] == '/' )
{
BREAK:
if ( cur_pos >= 0 )
break;
}
LOOP_START:
++cur_pos;
++offset;
if ( cur_pos >= *(cur_filename + 4) )
goto LABEL_47;
}
while ( 1 )
{
if ( str[offset] != '.' )
{
if ( str[offset] != ' ' )
goto LOOP_START;
}
if ( !cur_pos )
{
if ( str[offset] == ' ' )
{
str[offset] = '_';
goto LOOP_START;
}
}
if ( str[offset] == '.' )
{
if ( !cur_pos )
goto LOOP_START;
if ( str[offset - 1] == '\\' || str[offset - 1] == '/' )
goto LOOP_START;
if ( cur_pos == 2 )
{
if ( is_safe_character(cur_filename) )
goto LOOP_START;
}
else if ( cur_pos < 1 )
{
goto DELETE;
}
if ( str[offset - 1] == '.' )
{
if ( cur_pos == 1 )
goto LOOP_START;
if ( str[offset - 2] == '\\' || str[offset - 2] == '/' || cur_pos == 3 && is_safe_character(cur_filename) )
goto LOOP_START;
}
}
DELETE:
delete_char(cur_filename, cur_pos, 1u);
--offset;
if ( --cur_pos < 0 )
goto LOOP_START;
}
}
//...
}
在 7.12 之后:
void __fastcall file_name_check(char **a1){
cur_filename = a1;
j = 0;
if ( *(a1 + 4) > 0 )
{
offset = 0;
fname_index = 1;
do
{
if ( fname_index == cur_filename[2] )
goto HANDLE_DIR_NEXT;
str = cur_filename;
if ( str[offset + 1] == '\\' || str[offset + 1] == '/' )
{
HANDLE_DIR_NEXT:
if ( offset >= 0 )
{
if ( str[offset] == '.' )
goto FILENAME_BEGINS;
if ( str[offset] == ' ' )
{
FILENAME_BEGINS:
if ( str[offset] != '.' )
goto CONT;
if ( offset )
{
if ( str[offset - 1] != '\\'
&& str[offset - 1] != '/'
&& (offset != 2 || !is_safe_character(cur_filename)) )
{
if ( str[offset - 1] != '.' )
goto CONT;
if ( offset != 1 )
{
if ( str[offset - 2] != '\\'
&& str[offset - 2] != '/'
&& (offset != 3 || !is_safe_character(cur_filename)) )
{
CONT:
str[offset] = '_';
}
}
}
}
}
}
}
++j;
++offset;
++fname_index;
}
while ( j < *(cur_filename + 4) );
}
//...
}