查看: 15591|回复: 5

phpcms v9 前台无限制GETSHELL

[复制链接]
  • TA的每日心情

    2024-5-1 16:11
  • 签到天数: 1563 天

    [LV.Master]伴坛终老

    发表于 2014-1-26 18:08:50 | 显示全部楼层 |阅读模式
    0x01:介绍

    PHPCMS V9(后面简称V9)采用PHP5+MYSQL做为技术基础进行开发。V9采用OOP(面向对象)方式进行基础运行框架搭建。模块化开发方式做为功能开发形式。框架易于功能扩展,代码维护,优秀的二次开发能力,可满足所有网站的应用需求。 5年开发经验的优秀团队,在掌握了丰富的WEB开发经验和CMS产品开发经验的同时,勇于创新追求完美的设计理念,为全球多达10万网站提供助力,并被更多的政府机构、教育机构、事业单位、商业企业、个人站长所认可。

    0x02:漏洞分析

    在中 v9\phpcms\modules\member\index.php381行处
    [AppleScript] 纯文本查看 复制代码
    public function account_manage_avatar() {
     
    $memberinfo = $this->memberinfo;
     
    //初始化phpsso
     
    $phpsso_api_url = $this->_init_phpsso();
     
    $ps_auth_key = pc_base::load_config('system', 'phpsso_auth_key');
     
    $auth_data = $this->client->auth_data(array('uid'=>$this->memberinfo['phpssouid'], 'ps_auth_key'=>$ps_auth_key), '', $ps_auth_key);
     
    $upurl = base64_encode($phpsso_api_url.'/index.php?m=phpsso&c=index&a=uploadavatar&auth_data='.$auth_data);
     
    //获取头像数组
     
    $avatar = $this->client->ps_getavatar($this->memberinfo['phpssouid']);
     
     
     
    include template('member', 'account_manage_avatar');
     
    }

    这里是一个上传头像的功能模块,我们继续跟踪上传地址为

    v9/phpsso_server/index.php?m=phpsso&c=index&a=uploadavatar

    读取v9\phpsso_server\phpcms\modules\phpsso\index.php文件

    其中uploadavatar为我们处理上传头像函数

    具体函数如下

    public function uploadavatar() {
    [AppleScript] 纯文本查看 复制代码
    //根据用户id创建文件夹
     
    if(isset($this->data['uid']) && isset($this->data['avatardata'])) {
     
    $this->uid = $this->data['uid'];
     
    $this->avatardata = $this->data['avatardata'];
     
    } else {
     
    exit('0');
     
    }
     
     
     
    $dir1 = ceil($this->uid / 10000);
     
    $dir2 = ceil($this->uid % 10000 / 1000);
     
     
     
    //创建图片存储文件夹
     
    $avatarfile = pc_base::load_config('system', 'upload_path').'avatar/';
     
    $dir = $avatarfile.$dir1.'/'.$dir2.'/'.$this->uid.'/';
     
    if(!file_exists($dir)) {
     
    mkdir($dir, 0777, true);
     
    }
     
     
     
    //存储flashpost图片
     
    $filename = $dir.$this->uid.'.zip';
     
    file_put_contents($filename, $this->avatardata);
     
    echo $filename;exit();
     
    //解压缩文件
     
    pc_base::load_app_class('pclzip', 'phpsso', 0);
     
    $archive = new PclZip($filename);
     
    if ($archive->extract(PCLZIP_OPT_PATH, $dir) == 0) {
     
    die("Error : ".$archive->errorInfo(true));
     
    }
     
     
     
    //判断文件安全,删除压缩包和非jpg图片
     
    $avatararr = array('180x180.jpg', '30x30.jpg', '45x45.jpg', '90x90.jpg');
     
    if($handle = opendir($dir)) {
     
       while(false !== ($file = readdir($handle))) {
     
    if($file !== '.' && $file !== '..') {
     
    if(!in_array($file, $avatararr)) {
     
    @unlink($dir.$file);
     
    } else {
     
    $info = @getimagesize($dir.$file);
     
    if(!$info || $info[2] !=2) {
     
    @unlink($dir.$file);
     
    }
     
    }
     
    }
     
       }
     
       closedir($handle);    
     
    }
     
    $this->db->update(array('avatar'=>1), array('uid'=>$this->uid));
     
    exit('1');
     
    }
     
     
    其中关键代码
     
    pc_base::load_app_class('pclzip', 'phpsso', 0);
     
    $archive = new PclZip($filename);
     
    if ($archive->extract(PCLZIP_OPT_PATH, $dir) == 0) {
     
    die("Error : ".$archive->errorInfo(true));
     
    }

    这里为解压缩文件

    接下来为判断是否为图片类型
    [AppleScript] 纯文本查看 复制代码
    //判断文件安全,删除压缩包和非jpg图片
     
    $avatararr = array('180x180.jpg', '30x30.jpg', '45x45.jpg', '90x90.jpg');
     
    if($handle = opendir($dir)) {
     
       while(false !== ($file = readdir($handle))) {
     
    if($file !== '.' && $file !== '..') {
     
    if(!in_array($file, $avatararr)) {
     
    @unlink($dir.$file);
     
    } else {
     
    $info = @getimagesize($dir.$file);
     
    if(!$info || $info[2] !=2) {
     
    @unlink($dir.$file);
     
    }
     
    }
     
    }
     
       }
     
       closedir($handle);    
     
    }

    为180x180.jpg', '30x30.jpg', '45x45.jpg', '90x90.jpg ,如果不为这几种,则就删除,但是他考虑到的仅仅是当前目录下的,没做循环遍历,导致我们可以新建一个目录,然后里面放入我们的PHP木马,然后压缩成zip,然后再上传,然后即可达到任意上传文件,直接前台无限制getshell

    0x03:漏洞利用

    新建一个如图文件

    新建一个22目录,目录里面放入我们的test.php文件,test.php里面放入我们的一句话,然后压缩成zip文件
    20140126180714.jpg
    然后上传一个正常头像,获取一个路径,如正常头像地址为http://127.0.0.1/v9/phpsso_serve ... tar/1/1/3/90x90.jpg

    然后我们再次上传,通过burpsuit抓包,将其中post的内容用paste from file替换掉
    20140126180805.jpg
    然后发送

    最好获取shell路径为 在之前的正常路径下面加上我们的解压路径,如http://127.0.0.1/v9/phpsso_serve ... r/1/1/3/22/test.php
    20140126180849.jpg

    回复

    使用道具 举报

    该用户从未签到

    发表于 2014-1-26 23:24:54 | 显示全部楼层
    沙发
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-1-9 18:10
  • 签到天数: 2 天

    [LV.1]初来乍到

    发表于 2014-1-27 00:38:51 | 显示全部楼层
    {:soso_e140:}直接秒了~
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    郁闷
    2016-7-31 10:41
  • 签到天数: 43 天

    [LV.5]常住居民I

    发表于 2014-1-27 11:24:37 | 显示全部楼层
    这个真的很好,原理讲的很清楚
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2017-8-21 09:22
  • 签到天数: 181 天

    [LV.7]常住居民III

    发表于 2014-1-27 11:46:59 | 显示全部楼层
    再次的秒杀啊
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    发表于 2014-9-4 23:46:38 | 显示全部楼层
    怎么发现啊
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    指导单位

    江苏省公安厅

    江苏省通信管理局

    浙江省台州刑侦支队

    DEFCON GROUP 86025

    旗下站点

    邮箱系统

    应急响应中心

    红盟安全

    联系我们

    官方QQ群:112851260

    官方邮箱:security#ihonker.org(#改成@)

    官方核心成员

    Archiver|手机版|小黑屋| ( 苏ICP备2021031567号 )

    GMT+8, 2024-5-9 00:13 , Processed in 0.047572 second(s), 16 queries , Gzip On, MemCache On.

    Powered by ihonker.com

    Copyright © 2015-现在.

  • 返回顶部