本文内容

  • 文件头content-type字段校验(image/gif等)绕过

0x01 服务端一般检测的内容

  • 上传的文件名(扩展名、黑白名单)
  • MIME/TYPE (浏览器根据文件扩展名自动生成)
    部分burpsuite截取的部分展示

0x02 MIME了解

  • MIME (Multipurpose Internet Mail Extensions) 是描述消息内容类型的因特网标准。

  • MIME 消息能包含文本、图像、音频、视频以及其他应用程序专用的数据。

  • 浏览器会自动根据所上传的文件的扩展名,对应到相应的MIME类型上

  • 常见的白名单MIME/TYPE

0x03 实例分析

  • 环境:windows+phpstudy+burpsuite
  • 由于本地127.0.0.1burpsuite截不到包故采用本地网络地址

测试代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<?php
$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
if (($_FILES['upload_file']['type'] == 'image/jpeg') || ($_FILES['upload_file']['type'] == 'image/png') || ($_FILES['upload_file']['type'] == 'image/gif')) {
$temp_file = $_FILES['upload_file']['tmp_name'];
$img_path = 'uploads/' . $_FILES['upload_file']['name'];
if (move_uploaded_file($temp_file, $img_path)) {
$is_upload = true;
$msg= "<br/>成功上传至:<b> ".$img_path."</b>";
} else {
$msg = '上传出错!';
}
} else {
$msg = '文件类型不正确,请重新上传!';
}

}
?>

<div id="upload_panel">
<ol>

<li>
<h3>上传区</h3>
<form enctype="multipart/form-data" method="post" onsubmit="return checkFile()">
<p>请选择要上传的图片:<p>
<input class="input_file" type="file" name="upload_file"/>
<input class="button" type="submit" name="submit" value="上传"/>
</form>
<div id="msg">
<?php
if($msg != null){
echo "提示:".$msg;
}
?>
</div>
<div id="img">
<?php
if($is_upload){
echo '<img src="'.$img_path.'" width="250px" />';
}
?>
</div>
</li>
</ol>
</div>
  • 尝试上传一个含phpinfo的文件(phpinfo.php)

  • 使用burpsuite截断修改content-type,重新提交报文

  • 将burpsuite截断关闭,访问上传的文件