Pass21【数组绕过+“/.”绕过】
$is_upload = false;
$msg = null;
if(!empty($_FILES['upload_file'])){
//检查MIME
$allow_type = array('image/jpeg','image/png','image/gif');
if(!in_array($_FILES['upload_file']['type'],$allow_type)){
$msg = "禁止上传该类型文件!";
}else{
//检查文件名
$file = empty($_POST['save_name']) ? $_FILES['upload_file']['name'] : $_POST['save_name'];
if (!is_array($file)) {
$file = explode('.', strtolower($file));
}
$ext = end($file);
$allow_suffix = array('jpg','png','gif');
if (!in_array($ext, $allow_suffix)) {
$msg = "禁止上传该后缀文件!";
}else{
$file_name = reset($file) . '.' . $file[count($file) - 1];
$temp_file = $_FILES['upload_file']['tmp_name'];
$img_path = UPLOAD_PATH . '/' .$file_name;
if (move_uploaded_file($temp_file, $img_path)) {
$msg = "文件上传成功!";
$is_upload = true;
} else {
$msg = "文件上传失败!";
}
}
}
}else{
$msg = "请选择要上传的文件!";
}
如果按正常思维,这里是没有洞的,但是:
if (!is_array($file)) {
$file = explode('.', strtolower($file));
}
让我们想到如果上传一个数组。
数组的长度之谜
当我们上传一个数组,只上传array[0]和array[2]时,此时array[1]值为空,且数组count为2.
此时
$file[count($file) - 1] != end($file)
具体测试如下:
如下图,我们的$file[count($file) - 1]
就为空,$file_name = reset($file) . '.' . $file[count($file) - 1];
的值就是base.php. ,其中结尾的.会被windows自动忽略。
当然我们也可以利用Pass19学习的/.绕过,使save_name[0]=base.php/,拼接完成后base.php/.最后的/.会被move_uploaded_file过滤
注意:bp里------------9921那一行和后面Content-Disposition那一行中间不能有空行,否则bp会不识别空行之后的内容!
参考这一篇[1]
References
[1]
参考这一篇: https://blog.csdn.net/u014029795/article/details/102917199