Lucene search

K
seebugFengSSV:89630
HistoryOct 10, 2015 - 12:00 a.m.

PHP多版本(5.2,5.4.38~5.6.6)任意文件上传漏洞

2015-10-1000:00:00
feng
www.seebug.org
416

0.008 Low

EPSS

Percentile

79.3%

PHP任意文件上传漏洞(CVE-2015-2348)。通常情况下,php的开发者会对文件名后缀、文件类型(Content-Type)、Mime type、文件大小等进行检查来限制恶意php脚本的上传,但是攻击者可以利用该漏洞绕过这些限制,直接上传恶意的文件。

漏洞详情

该漏洞存在于php的move_uploaded_file()函数中,这个函数一般在上传文件时被使用,用途是将上传的文件移动到新位置。

move_uploaded_file ( string $filename , string $destination )

这次的漏洞就出现在$destination这个参数中,这个参数代表的是上传文件移动的最终目的地址。如果$destination变量是从用户$_GET或$_POST中获得的并且我们可控,那么我们可以利用空字符\x00来截断后面的拓展名,从而造成任意文件上传。

漏洞利用演示

我们利用DVWA的high难度来演示,首先我们把move_uploaded_file()函数的第二个参数改成我们可控的$_POST[‘xxname’]。

<?php
if (isset($_POST['Upload'])) {
$target_path = DVWA_WEB_PAGE_TO_ROOT."hackable/uploads/";
$target_path = $target_path . basename($_FILES['uploaded']['name']);
$uploaded_name = $_FILES['uploaded']['name'];
$uploaded_ext = substr($uploaded_name, strrpos($uploaded_name, '.') + 1);
$uploaded_size = $_FILES['uploaded']['size'];
if (($uploaded_ext == "jpg" || $uploaded_ext == "JPG" || $uploaded_ext == "jpeg" || $uploaded_ext == "JPEG") && ($uploaded_size < 100000)){
if(!move_uploaded_file($_FILES['uploaded']['tmp_name'], $_POST['xxname'])) {
$html .= '<pre>';
$html .= 'Your image was not uploaded.';
$html .= '</pre>';
      } else {
$html .= '<pre>';
$html .= $target_path . ' succesfully uploaded!';
$html .= '</pre>';
}
}
else{
$html .= '<pre>';
$html .= 'Your image was not uploaded.';
$html .= '</pre>';
}
}
?>

![](https://images.seebug.org/contribute/e24a34b4-e688-4c49-89c6-ae6b485f06db-2015-09-22 22_44_10.png)

然后上传文件,这里把POST的xxname参数利用空字符进行截断。

如下图所示:

![](https://images.seebug.org/contribute/51338806-f32b-4c00-af46-9d3f5c665c04-2015-09-22 22_44_54.png)

我们可以看到,文件名被成功截断,php脚本上传成功。

![](https://images.seebug.org/contribute/24e9d061-8957-4af3-a95c-d0369b995490-2015-09-22 22_45_44.png)

受影响的php版本

5.4.38~5.6.6,同时由于php 5.2版本本身就受到00截断漏洞的影响,所以也在受影响的行列之中。

参考链接:

http://bobao.360.cn/news/detail/1383.html