{"id":33118,"date":"2021-07-13T14:05:56","date_gmt":"2021-07-13T18:05:56","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=33118"},"modified":"2021-07-13T14:06:10","modified_gmt":"2021-07-13T18:06:10","slug":"bypassing-tcc-by-changing-the-environment","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/07\/13\/bypassing-tcc-by-changing-the-environment\/","title":{"rendered":"Bypassing TCC By Changing the Environment"},"content":{"rendered":"<p><a href=\"https:\/\/objective-see.com\/blog\/blog_0x4C.html\">Matt Shockley<\/a> (<a href=\"https:\/\/twitter.com\/mattshockl\/status\/1287888229887291394\">tweet<\/a>, <a href=\"https:\/\/medium.com\/@mattshockl\/cve-2020-9934-bypassing-the-os-x-transparency-consent-and-control-tcc-framework-for-4e14806f1de8\">Medium<\/a>):<\/p>\n<blockquote cite=\"https:\/\/objective-see.com\/blog\/blog_0x4C.html\">\n<p>TCC stores these user-level entitlements in a SQLite3 database on disk at <tt>$HOME\/Library\/Application Support\/com.apple.TCC\/TCC.db<\/tt>. Apple uses a dedicated daemon, <code>tccd<\/code>, for each logged-in user (and one system level daemon) to handle TCC requests. These daemons sit idle until they receive an access request from the OS for an application attempting to access protected data<\/p>\n<p>[&#8230;]<\/p>\n<p>Obviously being able to write directly to the database completely defeats the purpose of TCC, so Apple protects this database itself with TCC and System Integrity Protection (SIP). Even a program running as root cannot modify this database unless it has the <code>com.apple.private.tcc.manager<\/code> and <code>com.apple.rootless.storage.TCC<\/code> entitlements. However, the database is still technically owned and readable\/writeable by the currently running user, so as long as we can find a program with those entitlements, we can control the database.<\/p>\n<p>[&#8230;]<\/p>\n<p>Essentially, when the TCC daemon attempts to open the database, the program tries to directly open (or create if not already existing) the SQLite3 database at <tt>$HOME\/Library\/Application Support\/com.apple.TCC\/TCC.db<\/tt>. While this seems inconspicuous at first, it becomes more interesting when you realize that you can control the location that the TCC daemon reads and writes to if you can control what the <code>$HOME<\/code> environment variable contains. [&#8230;] Thus, I could set the <code>$HOME<\/code> environment variable in <code>launchctl<\/code> to point to a directory I control, restart the TCC daemon, and then directly modify the TCC database to give myself every TCC entitlement available without ever prompting the end user.<\/p><\/blockquote>\n\n<p>So SIP is still protecting the normal path, but the system relies on <code>tccd<\/code>, which has been redirected to a different path. Apple fixed this 4.5 months later, in July 2020.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/patrickwardle\/status\/1284939400980205568\">Patrick Wardle<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/patrickwardle\/status\/1284939400980205568\">\n<p>TCC continues to be a massive pain in the butt for legitimate software\/app developers.<\/p>\n<p>...but for hackers? Yah, not so much at all &#x1F62D;&#x1F62D;&#x1F62D;&#x1F62D;&#x1F62D;<\/p>\n<p>For example (as a legitimate soft dev), how can my updater tell if my app was already granted certain TCC privileges (so I don&rsquo;t have to re-prompt the user)?<\/p>\n<p>And why do I have to manually restart TCCd to avoid a myriad of (broken) caching issues?<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/06\/04\/tcc-bypass-in-xcsset-malware\/\">TCC Bypass in XCSSET Malware<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/07\/03\/mount_apfs-tcc-bypass-and-privilege-escalation\/\">mount_apfs TCC Bypass and Privilege Escalation<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2018\/09\/25\/bypassing-mojave-security-protections\/\">Bypassing Mojave Security Protections<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/09\/21\/dropbox-modifies-tcc-db-to-give-itself-accessibility-access\/\">Dropbox Modifies TCC.db to Give Itself Accessibility Access<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Matt Shockley (tweet, Medium): TCC stores these user-level entitlements in a SQLite3 database on disk at $HOME\/Library\/Application Support\/com.apple.TCC\/TCC.db. Apple uses a dedicated daemon, tccd, for each logged-in user (and one system level daemon) to handle TCC requests. These daemons sit idle until they receive an access request from the OS for an application attempting to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2021-07-13T18:05:59Z","apple_news_api_id":"0c555ebf-ce72-477e-ad49-b434817c0ecf","apple_news_api_modified_at":"2021-07-13T18:06:13Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/ADFVev85yR36tSbQ0gXwOzw","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[131,2095,500,30,1666,355,48,1235,1960],"class_list":["post-33118","post","type-post","status-publish","format-standard","hentry","category-technology","tag-bug","tag-exploit","tag-launchd","tag-mac","tag-macos-10-15","tag-privacy","tag-security","tag-system-integrity-protection","tag-transparency-consent-and-control-tcc"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=33118"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33118\/revisions"}],"predecessor-version":[{"id":33120,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/33118\/revisions\/33120"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=33118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=33118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=33118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}