这个是发送页面send.php
<form method="POST" name='sadf' action="upload_img.php"  enctype="multipart/form-data">
<p align="center"><input type="file" name="upload_img"/><input type="submit" value="submit"/></p>
</form>
<?phpprint_r($_FILES);if($_FILES['upload_img']['name']){
require_once("plugin/image.class.php");
$image=new image(); $image->check_file($_FILES['upload_img']);
$img_url=$image->upload_file($_FILES['upload_img']);


echo "<input id='dd' type='hidden' value='$img_url'/><p align='center'><img src='images/user/$img_url' width='350px'  /></p>";
}
?>这个是图片上传类image.class.php
<?php
/**
 * 上传类
 */
class image
{

/**
 * 验证图片
 * 
 * @param $file 获取的文件对象($_FILES)
 */
public static function check_file($file)
{
$allow_file_ext_list = array(1=>'image/jpeg' , 2=>'image/gif' , 3=>'image/pjpeg');
$allow_file_max_size = 1024*1024;
//验证上传图片类型
if (array_search($file['type'] , $allow_file_ext_list) == false)
{
exit;
}

if ($allow_file_max_size < $file['size'])
{
show_alert('上传图片大小超过1M,系统只允许上传1M的图片');
}
}

/**
 * 上传文件
 *
 * @param $file 获取的文件对象($_FILES)
 * @param $filePath 可选参数,即是否存在分级目录下
 */
public static function upload_file($file , $file_path = '')
{
$destination_path = ($file_path == '') ? ("images/user/") : ($file_path);

if(!file_exists($destination_path))
{
mkdir($destination_path , 0777);
} $file_name = get_datetime('YmdHis') . '_' . get_cookie('sysuserid') . substr( basename($file['name']) , strpos(basename($file['name']),'.') ); if (move_uploaded_file($file['tmp_name'], $destination_path . $file_name)) {
return $file_name;
}
return '';
}

//删除图片

public static function del_file($filepath){

if(unlink($filepath)){

return true;
}else{

return false;
}
}

}function get_datetime($string_format='Y-m-d H:i:s'){
   global $timestamp;
return gmdate($string_format,time()+3600*8);
}
function get_cookie($name){ global $_COOKIE,$cookieprename;
if (isset($_COOKIE[$cookieprename.$name])) {
return urldecode($_COOKIE[$cookieprename.$name]);
}
return false;
}?>麻烦大家耐心看下帮我分析下

解决方案 »

  1.   

    定下 说明我的怀疑 这个文件夹是放上传文件的文件夹
    $image->check_file($_FILES['upload_img']); 这段判断上传的是不是图片 只能上传gif和jpg/jpeg图片
    我怀疑他可以上传别的类型文件
      

  2.   

    说白了!上传文件光靠$_FILES['upload_img']['type']是无法判断文件类型的!
    他直接把后缀改了,你获取到的$_FILES['upload_img']['type']就改变了!如果你确实需要获取文件的类型的话
    参考http://user.qzone.qq.com/9399428/blog/1290052850
    转载的文章!再退一部分!你精确判断到文件类型之后一样不能排除病毒的植入,当你下载到病毒文件,执行的时候会出现内存溢出,然后执行病毒部分!
      

  3.   

    没看到代码,不知道这个check_file如果发现不是图片,是否会停止后面的upload操作。
      

  4.   

    $file['type'] 是来自客户端的,php不对其作检查,所以不适合用它来做判定参看手册:
    http://www.php.net/manual/en/features.file-upload.post-method.php
      

  5.   

    你可以使用 通过$ _FILES ['userfile'] ['类型'] 变量来排除任何文件不符合特定类型的标准,但只把这个当作首先检查的一个系列,因为此值完全由客户端的控制,而不是在PHP端检查。
    PHP端检查能给个类子么
      

  6.   

    刚才是不是我看漏了,有源码不知道这个$_FILES里的文件类型能不能被伪造。如果可以,就能过这个验证。
    建议还是通过判断实际上传文件的扩展名来过滤吧?至少,如果是PHP程序,被改成了.JPG,就算传上来,也无法执行,除非要有另一个程序来进行改名。
    而另一个程序的上传,则又会有其他方面的限制了。
      

  7.   

    这是个古老的漏洞了,直接GOOGLE下就知道,如果要判断文件类型,需要判断文件头,你那个是没有效果的,如果只是上传图片的话,GD库里有几个函数可以直接判断是否为图片,而不需要判断文件头
      

  8.   

    这个,你用扩展名来判断,如果是php他改成jpg服务器也是当图片来处理的
      

  9.   

    貌似程序没问题,是不是你的服务器是nginx的,可上传图片,执行图片中的脚本参考 http://www.80sec.com/nginx-securit.html
      

  10.   

    你可以用ultraedit打开图片文件(比一般的图片大很多)看下,是不是有php代码在里面。