CVE-2021-36440(未授权任意文件上传)
该漏洞出自产品showdoc
影响版本
根据github提交记录分析影响版本为
未授权:2.9.4-2.9.5
授权后的任意文件上传:2.9.6-2.10.3
漏洞分析
该漏洞出来自
/server/Application/Api/Controller/AdminUpdateController.class.php中
关注到download方法
该方法中处有三个可控参数,分别是
$new_version:由用户直接传参(new_version)
$title_url:由用户直接传参(file_url)
$version_num:去掉$new_version中的v

继续往下分析
在52行处file_get_contents可以下载远程服务器上的恶意文件,此时$file_url的参数为:
http://192.168.1.106:81/showdoc-666.zip下载到远程文件内容后将其写入$zip_file中

然后压缩包会被解压到$temp_dir也就是/tmp/showdoc_update/中

然后会判断压缩包内文件是否符合要求,如果符合要求就会将压缩包内的文件写入
/var/www/html/Public/Uploads/upadte/

此处判断的条件是如下三个文件是否存在
1 | $zip_file_subpath.'composer.json' |
而$zip_file_subpath的生成规则则是/tmp/showdoc_update/showdoc-$version_num/
而此处的$version_num是可控的

于是我们的压缩包内容只要满足如下层级即可满足条件,此处的1.php是我们的木马

上传恶意压缩包,web根目录生成木马

成功访问

全版本更新分析
该功能在2.9.4版本发布,到2.9.6之前都是未授权文件上传
从2.9.6开始,作者增加了权限验证,但是文件上传仍然还是存在的,只不过由未授权变成了需要管理员权限

直到2.10.4,作者才彻底修复了这一版本的漏洞
作者搭建了自己的更新服务器,从而导致file_url不在可控了
