|
微博上传图片时只在前端进行验证, 服务器端没有进行安全过滤。
\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_ )
​修复方案:
\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;
}
|
|