finecms V5 会员头像任意文件上传漏洞 附修复代码

前台会员头像上传任意文件,finecms v5.2及之后的版本已修复此漏洞,大家可以对比一下代码确认

涉及文件:/finecms/dayrui/controllers/member/Account.php

public function upload() {

// 创建图片存储文件夹
$dir = SYS_UPLOAD_PATH.'/member/'.$this->uid.'/';
@dr_dir_delete($dir);
!is_dir($dir) && dr_mkdirs($dir);

if ($_POST['tx']) {
    $file = str_replace(' ', '+', $_POST['tx']);
    if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $file, $result)){
        $new_file = $dir.'0x0.'.$result[2];
        if (!@file_put_contents($new_file, base64_decode(str_replace($result[1], '', $file)))) {
            exit(dr_json(0, '目录权限不足或磁盘已满'));

接收txt的参数.然后匹配了正则.最后取出内容和文件后缀部分。再直接存盘.文件名都是统一的0x0
finecms V5 会员头像任意文件上传漏洞 附修复代码

仅仅是需要记住当前用户的id就可以搞定了

网络修复方案:

if (preg_match('/^(data:\s*image\/(png|jpg|jpeg);base64,)/', $file, $result)){

官方修复方案:升级到最新版,或手动替换代码

public function upload() {

    // 创建图片存储文件夹

    $dir = dr_upload_temp_path().'member/'.$this->uid.'/';

    @dr_dir_delete($dir);

    !is_dir($dir) && dr_mkdirs($dir);

    if ($_POST['tx']) {

        $file = str_replace(' ', '+', $_POST['tx']);

        if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $file, $result)){

            $new_file = $dir.'0x0.'.$result[2];

            if (!in_array(strtolower($result[2]), array('jpg', 'jpeg', 'png', 'gif'))) {

                exit(dr_json(0, '目录权限不足'));

            }

            if (!@file_put_contents($new_file, base64_decode(str_replace($result[1], '', $file)))) {

                exit(dr_json(0, '目录权限不足'));

            } else {

                list($width, $height, $type, $attr) = getimagesize($new_file);

                if (!$type) {

                    @unlink($new_file);

                    exit(function_exists('iconv') ? iconv('UTF-8', 'GBK', '图片字符串不规范') : 'error3');

                }

                $this->load->library('image_lib');

                $config['create_thumb'] = TRUE;

                $config['thumb_marker'] = '';

                $config['maintain_ratio'] = FALSE;

                $config['source_image'] = $new_file;

                foreach (array(30, 45, 90, 180) as $a) {

                    $config['width'] = $config['height'] = $a;

                    $config['new_image'] = $dir.$a.'x'.$a.'.'.$result[2];

                    $this->image_lib->initialize($config);

                    if (!$this->image_lib->resize()) {

                        exit(dr_json(0, '上传错误:'.$this->image_lib->display_errors()));

                        break;

                    }

                }

                // ok

                $my = SYS_UPLOAD_PATH.'/member/'.$this->uid.'/';

                @dr_dir_delete($my);

                !is_dir($my) && dr_mkdirs($my);

                $c = 0;

                if ($fp = @opendir($dir)) {

                    while (FALSE !== ($file = readdir($fp))) {

                        $ext = substr(strrchr($file, '.'), 1);

                        if (in_array(strtolower($ext), array('jpg', 'jpeg', 'png', 'gif'))) {

                            if (copy($dir.$file, $my.$file)) {

                                $c++;

                            }

                        }

                    }

                    closedir($fp);

                }

                if (!$c) {

                    exit(dr_json(0,  fc_lang('未找到目录中的图片')));

                }

            }

        } else {

            exit(dr_json(0, '图片字符串不规范'));

        }

    } else {

        exit(dr_json(0, '图片不存在'));

    }

转载于:https://blog.51cto.com/13785115/2128603

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值