1.打开环境,审计代码。
<?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");
}
?>
2.主要有两个可绕过的点,preg_match和_wake up的绕过
(1)_wake up的绕过
.在 PHP5 < 5.6.25, PHP7 < 7.0.10 的版本存在wakeup的漏洞。当反序列化中object的个数和之前的个数不等时,wakeup就会被绕过。
参考文章:WEB攻防-通用漏洞&PHP反序列化魔术方法&漏洞绕过&公私有属性
(2)preg_match绕过
参考文章:关于PHP函数preg_match绕过、move_uploaded_file绕过方式以及include包含例题