upload -labs | Pass-02

upload -labs | Pass-02
Pass-02:MIME类型验证绕过


关卡提示: 本pass在服务端对数据包的MIME类型进行检测!
核心思路: 服务端检查了 HTTP 请求头中的 Content-Type 字段,判断其是否在允许的范围内(如 image/jpeg, image/png, image/gif)。

1.准备 shell.php 文件。

2.使用 Burp Suite 抓取上传数据包。

3.在 Burp Suite 中,将 Content-Type: application/octet-stream 修改为合法的类型,例如 Content-Type: image/jpeg。

image

改为iamge/png

上传成功
总结: 和前端验证一样,请求头中的 Content-Type 也是完全由客户端控制的,不能作为验证文件类型的依据。




题目源码:


$is_upload = false;
$msg = null;
if (isset($_POST['submit'])) {
    if (file_exists(UPLOAD_PATH)) {
        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 = UPLOAD_PATH . '/' . $_FILES['upload_file']['name']            
            if (move_uploaded_file($temp_file, $img_path)) {
                $is_upload = true;
            } else {
                $msg = '上传出错!';
            }
        } else {
            $msg = '文件类型不正确,请重新上传!';
        }
    } else {
        $msg = UPLOAD_PATH.'文件夹不存在,请手工创建!';
    }
}

posted @ 2026-08-03 20:49  Dragon_Roar  阅读(7)  评论(0)    收藏  举报