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协议读入文件:
再用POST传参的方式写入:
也可以使用data伪协议进行绕过:
$file 参数要求文件包含,这里用正则表达式过滤了flag.php,但是提示了存在useless.php,通过filter伪协议读取。
读取源码:
定义了一个类Flag,以及类中存在一个魔术方法__tostring(),分析该魔术方法可得,如果该文件设置了 $file 属性,则进行文件包含,并输出文件的内容。
查看index.php,其中对类进行反序列化之后直接输出,调用了魔术方法,所以直接构造反序列化字符串,定义变量内容为flag.php即可。
Last updated