[SWPUCTF 2022 新生赛]file_master wp

发布时间 2023-06-26 10:40:26作者: MRFS

前置知识点:

这个题目的有一点之前是没有看见过的,就是对图片的宽和高进行了一些限制,限制都小于20才能上传成功

看了别人的wp说是可以直接定义

#define height 1
#define width 1

就是上面的 只要把后面的数字改成小于20的就可以了 (20是题目要求的,image hight and width must less than 20)

具体的看实际环境来看

先读取index.php

<!--?php
    session_start();
    if(isset($_GET['filename'])){
        echo file_get_contents($_GET['filename']);
    }
    else if(isset($_FILES['file']['name'])){
        $whtie_list = array("image/jpeg");
        $filetype = $_FILES["file"]["type"];
        if(in_array($filetype,$whtie_list)){
            $img_info = @getimagesize($_FILES["file"]["tmp_name"]);
            if($img_info){
                if($img_info[0]<=20 && $img_info[1]<=20){
                    if(!is_dir("upload/".session_id())){
                        mkdir("upload/".session_id());
                    }
                    $save_path = "upload/".session_id()."/".$_FILES["file"]["name"];
                    move_uploaded_file($_FILES["file"]["tmp_name"],$save_path);
                    $content = file_get_contents($save_path);
                    if(preg_match("/php/i",$content)){
                        sleep(5);
                        @unlink($save_path);
                        die("hacker!!!");
                    }else{
                        echo "upload success!! upload/your_sessionid/your_filename";
                    }
                }else{
                    die("image hight and width must less than 20");
                }
            }else{
                die("invalid file head");
            }
        }else{
            die("invalid file type!image/jpeg only!!");
        }
    }else{
        echo '<img src="data:jpg;base64,'.base64_encode(file_get_contents("welcome.jpg")).'"-->

具体的就是把php进行了一个过滤,然后对 MIME进行了一个检查 还有就是对上传的图片大小进行了一个限制

前两个之前都遇见过,后面一个就是利用前面的,进行一个定义

最后需要注意一下路径即可

image