### 简要描述:
U-Mail邮件系统某处上传缺陷,导致可以暴力获取webshell
### 详细说明:
漏洞文件:C:\umail\WorldClient\html\client\mail\module\o_attach.php
代码:
```
if ( ACTION == "attach-upload" )
{
if ( $_FILES )
{
$file_name = $_FILES['Filedata']['name'];
$file_type = $_FILES['Filedata']['type'];
$file_size = $_FILES['Filedata']['size'];
$file_source = $_FILES['Filedata']['tmp_name'];
$file_suffix = getfilenamesuffix( $file_name );
$path_target = getusercachepath( );
do
{
$file_id = makerandomname( );
$file_target = $path_target.$file_id.".".$file_suffix;
} while ( file_exists( $file_target ) );
if ( !move_uploaded_file( $file_source, $file_target ) )
{
dump_json( array(
"status" => 0,
"message" => el( "写入文件出错,请与管理员联系!", "" )
) );
}
$_SESSION[SESSION_ID]['attach_cache'][] = array(
"id" => $file_id,
"name" => $file_name,
"type" => "1",
"path" => $file_target,
"size" => $file_size
);
dump_json( array(
"status" => "1",
"filename" => $file_name,
"filesize" => $file_size,
"file_id" => $file_id
) );
}
else
{
dump_json( array(
"status" => "0",
"message" => el( "无法找到需要上传的文件!", "" )
) );
}
}
```
此处为发送邮件时的上传附件函数,允许上传任意文件,在通过黑白盒测试对比分析后得知$path_target = getusercachepath( )函数执行的结果为C:\umail\WorldClient\html\client\cache\{用户的user_id},其中$file_id即为上传文件保存的随机文件名,$file_suffix即为上传附件的文件类型。
在执行上传文件时候先将文件保存为临时文件,而此临时文件是存在web目录里,默认配置是可执行的(此处演示的是官网下载的最新版,windows server 2003搭建,且都为默认配置)
漏洞产生的在哪里?
首先通过对代码的分析,没找到用户可以查看$user_id的函数,而$user_id还是有规律可循的,按用户的数量从1一直递增;临时文件存放的路径是在web目录里,默认是有脚本执行权限的;临时文件名在上传成功后,审查元素可以看到。
因而,可以暴力猜解$user_id的值,来获得我们的webshell。
漏洞演示:
首先要有一个普通的用户,此处为了说明存储文件的伪随机性,在后台添加1000个用户,如图
[<img src="https://images.seebug.org/upload/201405/12224232cd5b8ecfc18b8a87e9517702af2fa87d.jpg" alt="5f9965a4-255e-4120-a178-b18213a51424.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/12224232cd5b8ecfc18b8a87e9517702af2fa87d.jpg)
挑选test00877@fuck.com帐号密码password877登录后,写信,如图
[<img src="https://images.seebug.org/upload/201405/122243043b9b03d1cf97cb5967ac113f5bde8b6e.jpg" alt="7b7e1d2a-b0fd-4694-ae4b-d281717963ac.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/122243043b9b03d1cf97cb5967ac113f5bde8b6e.jpg)
选择添加附件,上传php文件,返回结果获得的文件名(php文件上传过程中的临时文件名)为13998959208,保留此页面不关闭,然后打开burpsuite构造如下请求
[<img src="https://images.seebug.org/upload/201405/122243413b2e6f33fca5f13d6e65e3f39546d0c1.jpg" alt="0cf0d69a-144d-4df2-816b-089dca5b359e.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/122243413b2e6f33fca5f13d6e65e3f39546d0c1.jpg)
载入intruder,设置payloads为numbers,依次递增。
[<img src="https://images.seebug.org/upload/201405/12224443a1f03e67b4ef5e6afae5d38950a6ca96.jpg" alt="f9d4bc3f-653a-44b6-9e89-6ce83b5afedb.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/12224443a1f03e67b4ef5e6afae5d38950a6ca96.jpg)
好吧,1000个用户,跑了不到5秒。结果如下
[<img src="https://images.seebug.org/upload/201405/12224513da684b1014d5a4338f93b432c23463f7.jpg" alt="bc3af965-86a5-401e-8522-37aba9d3d5f9.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/12224513da684b1014d5a4338f93b432c23463f7.jpg)
服务器状况为
[<img src="https://images.seebug.org/upload/201405/12224544a0fb240dea93aee5b73cea280fd10e37.jpg" alt="7828b351-b850-400b-9c7c-5ca0c9e2f712.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201405/12224544a0fb240dea93aee5b73cea280fd10e37.jpg)
### 漏洞证明:
如上详细描述
暂无评论