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

栏目: jQuery · 发布时间: 7年前

内容简介:在 jQuery-File-Upload 的 PHP 上传处理文件

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

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)

参考


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Black Box Society

The Black Box Society

Frank Pasquale / Harvard University Press / 2015-1-5 / USD 35.00

Every day, corporations are connecting the dots about our personal behavior—silently scrutinizing clues left behind by our work habits and Internet use. The data compiled and portraits created are inc......一起来看看 《The Black Box Society》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具