搜索
首页php教程php手册phpcms图片上传漏洞解析

phpcms图片上传漏洞解析

Jun 06, 2016 pm 08:08 PM
phpcms上传图片漏洞程序解析说明

?针对下法程序说明: Fileext函数是对文件后缀名的提

?针对下法程序说明:

Fileext函数是对文件后缀名的提取。
根据此函数我们如果上传文件名为ddd.Php.jpg%20%20%20%20%20%20%20Php
经过此函数提取到的后缀还是jpg,因此正在is_image()函数中后缀检测被绕过了。我们回到public function crop_upload() 函数中if(is_image($_GET['file'])== false || strpos($_GET['file'],’.php’)!==false) exit();
在经过了is_image的判断之后又来了个.php的判断,在此程序员使用的是strpos函数
这个函数是对大小写敏感的函数我们使用.Php就可以直接绕过了。
过上边的两层的过滤我们的ddd.Php.jpg%20%20%20%20%20%20%20Php后缀依然有效。
最后$basename变量的值就为ddd.Php.jpg%20%20%20%20%20%20%20Php 然后使用file_put_contents函数写入到了指定目录。
看见ddd.Php.jpg%20%20%20%20%20%20%20Php这个后缀,大家应该明白了,它用在apache搭建的服务器上可以被解析。

漏洞文件:phpcms\modules\attachment\attachments.php

public function crop_upload() {
		if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
  			$pic = $GLOBALS["HTTP_RAW_POST_DATA"];
  			if (isset($_GET['width']) && !empty($_GET['width'])) {
  				$width = intval($_GET['width']);
  			}
  			if (isset($_GET['height']) && !empty($_GET['height'])) {
  				$height = intval($_GET['height']);
  			}
  			if (isset($_GET['file']) && !empty($_GET['file'])) {
  				$_GET['file'] = str_replace(';','',$_GET['file']);//过滤了分号
  				if(is_image($_GET['file'])== false || strpos($_GET['file'],'.php')!==false) exit();//is_image()检测是个关键
  				if (strpos($_GET['file'], pc_base::load_config('system', 'upload_url'))!==false) {
  					$file = $_GET['file'];
  					$basename = basename($file);//获取带有后缀的文件名
  					if (strpos($basename, 'thumb_')!==false) {
  						$file_arr = explode('_', $basename);
  						$basename = array_pop($file_arr);
  					}
  					$new_file = 'thumb_'.$width.'_'.$height.'_'.$basename;
  				} else {
  					pc_base::load_sys_class('attachment','',0);
  					$module = trim($_GET['module']);
  					$catid = intval($_GET['catid']);
  					$siteid = $this->get_siteid();
  					$attachment = new attachment($module, $catid, $siteid);
  					$uploadedfile['filename'] = basename($_GET['file']);
  					$uploadedfile['fileext'] = fileext($_GET['file']);
  					if (in_array($uploadedfile['fileext'], array('jpg', 'gif', 'jpeg', 'png', 'bmp'))) {
  						$uploadedfile['isimage'] = 1;
  					}
  					$file_path = $this->upload_path.date('Y/md/');
  					pc_base::load_sys_func('dir');
  					dir_create($file_path);
  					$new_file = date('Ymdhis').rand(100, 999).'.'.$uploadedfile['fileext'];
  					$uploadedfile['filepath'] = date('Y/md/').$new_file;
  					$aid = $attachment->add($uploadedfile);
  				}
  				$filepath = date('Y/md/');
  				file_put_contents($this->upload_path.$filepath.$new_file, $pic);//文件名可控、$pic可控
  			} else {
  				return false;
  			}
  			echo pc_base::load_config('system', 'upload_url').$filepath.$new_file;
  			exit;
  		}
  	}

后缀检测:phpcms\modules\attachment\functions\global.func.php

function is_image($file) {
  	$ext_arr = array('jpg','gif','png','bmp','jpeg','tiff');
  	$ext = fileext($file);关键地方
  	return in_array($ext,$ext_arr) ? $ext_arr :false;
  }

?关键函数:

function fileext($filename) {
  	return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));
  }

此漏洞官方已修复.信息来源wooyun.

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用