任意文件上传getshell漏洞在
C:\phpStudy\WWW\apps\public\Lib\Action\AttachAction.class.php中的ajaxUpload函数

可以看到第192行
$options['allow_exts'] = t(jiemi($_REQUEST['exts']));
获取了变量exts,然后经过jiemi函数的处理,jiemi函数在
C:\phpStudy\WWW\src\vendor\zhiyicx\thinksns-old-code\src\OpenSociax\functions.inc.php中

又调用了tsauthcode函数,该函数也在该文件中,截图该函数最后一行

可以看到return $keyc.str_replace('=', '', base64_encode($result));
如果我们的输入的参数为空,那么返回的也是空值
回到
$options['allow_exts'] = t(jiemi($_REQUEST['exts']));
中,如果我们输入的exts变量值为空,那么$options[‘allow_exts’]也就是空值
程序接着往下走

在第201行,调用了upload函数,在
C:\phpStudy\WWW\src\vendor\zhiyicx\thinksns-old-code\src\addons\model\AttachModel.class.php中

因为我们的$options[‘allow_exts’]如果是空值,那么这里的$input_options[‘allow_exts’]也就是空值了。

其中第202行,会合并$default_options数组和$input_options数组,$default_options[‘allow_exts’]不为空,而$input_options[‘allow_exts’]为空,经过array_merge函数的处理,会造成变量覆盖的漏洞,最终$options[‘allow_exts’]也就被覆盖为空了。

程序走到第209行,跟进localUpload函数,在
C:\phpStudy\WWW\src\vendor\zhiyicx\thinksns-old-code\src\addons\model\AttachModel.class.php中

可以看到会实例化一个UploadFile类,如果$options[‘allow_exts’]为空,那么根据类UploadFile的定义,public $allowExts = array();,$allowExts将会是空值
在第300行,$upload->upload()调用upload函数进行文件上传,upload函数在
C:\phpStudy\WWW\src\vendor\zhiyicx\thinksns-old-code\src\addons\library\UploadFile.class.php中

会获取上传文件的后缀$file['extension'] = $this->getExt($file['name']);
然后检查上传文件是否合法
if (!$this->check($file)) {
跟进check函数,在
C:\phpStudy\WWW\src\vendor\zhiyicx\thinksns-old-code\src\addons\library\UploadFile.class.php中

可以看到第432行,检查了文件类型是否合法,在C:\phpStudy\WWW\src\vendor\zhiyicx\thinksns-old-code\src\addons\library\UploadFile.class.php中,

可以看到可以看到判断上传文件后缀是否为php、php3、exe等等,可以用.PHP来进行大写绕过。同时因为我们构造的this->allowExts为空,所以可以绕过
if (!empty($this->allowExts)) {
的判断,直接return true;
返回true之后,就是文件的正常保存了,可以任意上传文件来getshell
直接看证明:
构造一个表单进行文件上传

然后burp进行抓包,改包
因为有防csrf 的,所以要改一下referer为http://localhost/index.php
改文件后缀名为大写的PHP


可以直接看到保存的路径为2017/6/21/16,文件名为594a319c46ce9bd2634f.PHP

成功getshell
暂无评论