
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)) {
-
- $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);
- }
因此我们可已直接通过上传含有恶意代码的图片来利用该漏洞,按照老规矩,VulnSpy 已经准备好了在线的实验环境,大家可以移步到下面链接进行测试:
在线测试地址:https://www.vulnspy.com/cn-jquery-file-upload-below-v9.x-rce/
漏洞修复
将 /server/php/UploadHandler.php 中的默认图片处理库修改为GD库: