jQuery-File-Upload <= 9.x 远程命令执行漏洞 (ImageMagick/Ghostscript)

阅读量264250

发布时间 : 2018-10-24 14:29:56

jQuery-File-Upload 是 Github 上继 jQuery 之后最受关注的 jQuery 项目,该项目最近被披露出一个存在了长达三年之久的任意文件上传漏洞,该漏洞在随后发布的 v9.22.2 版本中被修复,但是在 VulnSpy 团队对代码的复查中发现了另外一个严重的命令执行漏洞,该漏洞允许攻击者通过上传恶意的图片文件来执行任意系统命令。

漏洞细节

在 jQuery-File-Upload 的 PHP 上传处理文件 /server/php/UploadHandler.php 中优先使用了 Imagick 来校验上传的图片:

protected function get_image_size($file_path) {
    if ($this->options['image_library']) {
        if (extension_loaded('imagick')) {
            $image = new Imagick();
            try {
                if (@$image->pingImage($file_path)) {
                    $dimensions = array($image->getImageWidth(), $image->getImageHeight());
                    $image->destroy();
                    return $dimensions;
                }
                return false;
            } catch (Exception $e) {
                error_log($e->getMessage());
            }
        }
        if ($this->options['image_library'] === 2) {
            $cmd = $this->options['identify_bin'];
            $cmd .= ' -ping '.escapeshellarg($file_path);
            exec($cmd, $output, $error);
            if (!$error && !empty($output)) {
                // image.jpg JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 465KB 0.000u 0:00.000
                $infos = preg_split('/s+/', substr($output[0], strlen($file_path)));
                $dimensions = preg_split('/x/', $infos[2]);
                return $dimensions;
            }
            return false;
        }
    }
    if (!function_exists('getimagesize')) {
        error_log('Function not found: getimagesize');
        return false;
    }
    return @getimagesize($file_path);
}

我们都知道 ImageMagick 在近几年来出现了多个严重的安全漏洞:

因此我们可已直接通过上传含有恶意代码的图片来利用该漏洞,按照老规矩,VulnSpy 已经准备好了在线的实验环境,大家可以移步到下面链接进行测试:

在线测试地址:https://www.vulnspy.com/cn-jquery-file-upload-below-v9.x-rce/

 

如何修复

/server/php/UploadHandler.php 中的默认图片处理库修改为GD库:

// Set to 0 to use the GD library to scale and orient images,
// set to 1 to use imagick (if installed, falls back to GD),
// set to 2 to use the ImageMagick convert binary directly:
'image_library' => 0

本文转载自:jQuery-File-Upload <= 9.x 远程命令执行漏洞 (ImageMagick/Ghostscript)

 

参考

本文转载自: vulnspy.com

如若转载,请注明出处: https://blog.vulnspy.com/2018/10/23/jQuery-File-Upload-9-x-Remote-Code-Execution-With-ImageMagick-Ghostscript-CN/

安全客 - 有思想的安全新媒体

分享到:微信
+10赞
收藏
VULNSPY
分享到:微信

发表评论

内容需知
  • 投稿须知
  • 转载须知
  • 官网QQ群8:819797106
  • 官网QQ群3:830462644(已满)
  • 官网QQ群2:814450983(已满)
  • 官网QQ群1:702511263(已满)
合作单位
  • 安全客
  • 安全客
Copyright © 北京奇虎科技有限公司 360网络攻防实验室 安全客 All Rights Reserved 京ICP备08010314号-66