PHP5.2.0中allow_url_include的應用和解釋

日期:2006-11-07  作者:喜騰小二  來源:PHPChina


    【PHPChina訊】PHP常常因為它可能允許URLS被匯入和執行陳述式被人們指責。事實上,這件事情並不是很讓人感到驚奇,因為這是導緻稱為Remote URL Include vulnerabilities的php應用程式漏洞的最重要的原因之一。

    因為這個原因,許多安全研究人員建議在php.ini配置中禁用指嚮allow_url_fopen。不幸的是,許多推薦這種方法的人,並沒有意識到,這樣會破壞很多的應用並且並不能保證100%的解決remote URL includes以及他帶來的不安全性。

    通常,使用者要求在他們使用其他的檔案係統函式的時候,php允許禁止URL包含和請求宣告支援。

    因為這個原因,計劃在PHP6中提供allow_url_include。在這些討論之後,這些特性在php5.2.0 中被backported。現在大多數的安全研究人員已經改變了他們的建議,隻建議人們禁止allow_url_include。

    不幸的是,allow_url_fopen和allow_url_include並不是導緻問題的原因。一方麵來說在應用中包含本機檔案仍然是一件足夠危險的事情,因為攻擊者經常透過sessiondata, fileupload, logfiles,...等方法獲取php程式碼………

    另一方麵allow_url_fopen和allow_url_include隻是保護了against URL handles標記為URL.這影響了http(s) and ftp(s)但是並沒有影響php或date(new in php5.2.0) urls.這些url形式,都可以非常簡單的進行php程式碼注入。

Example 1: Use php://input to read the POST data
// Insecure Include
  // The following Include statement will
   // include and execute everything POSTed
   // to the server

   include "php://input";
?>
Example 2: Use data: to Include arbitrary code
 // Insecure Include
   // The following Include statement will
   // include and execute the base64 encoded
   // payload. Here this is just phpinfo()

   include "data:;base64,PD9waHAgcGhwaW5mbygpOz8+";
?>

    把這些放到我們的運算裡麵將會非常明顯的發現既不是url_allow_fopen也不是url_allor_include 被保障。這些隻是因為篩選器很少對矢量進行篩選。能夠100%解決這個URL include vulnerabilities的方法是我們的Suhosin延伸.

    原文地址:http://blog.php-security.org/archives/45-PHP-5.2.0-and-allow_url_include.html

<<<返回技術中心

技術文章

站內新聞

我要啦免费统计