<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>tcc on 🥔</title>
    <link>https://www.angelystor.com/tags/tcc/</link>
    <description>Recent content in tcc on 🥔</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 02 Oct 2023 11:22:20 +0800</lastBuildDate><atom:link href="https://www.angelystor.com/tags/tcc/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>CVE-2023-40299 TCC Bypass with Kong Insomnia in MacOS</title>
      <link>https://www.angelystor.com/posts/cve-2023-40299/</link>
      <pubDate>Mon, 02 Oct 2023 11:22:20 +0800</pubDate>
      
      <guid>https://www.angelystor.com/posts/cve-2023-40299/</guid>
      <description>Introduction TCC (Transparency, Consent and Control) is a mechanism in MacOS that helps restrict access to protected folders on a system. This helps a user make informed consent whenever an application seeks to access files in a folder (eg Desktop). A more indepth discussion about TCE can be found here.
From an attacker&amp;rsquo;s perspective, he would want to find out as much information that belongs to the victim when he manages to get a RAT (Remote Access Trojan) on the system.</description>
      <content:encoded><![CDATA[<h1 id="introduction">Introduction</h1>
<p>TCC (Transparency, Consent and Control) is a mechanism in MacOS that helps restrict access to protected folders on a system. This helps a user make informed consent whenever an application seeks to access files in a folder (eg Desktop). A more indepth discussion about TCE can be found <a href="https://www.angelystor.com/posts/macos_tcc/">here</a>.</p>
<p>From an attacker&rsquo;s perspective, he would want to find out as much information that belongs to the victim when he manages to get a RAT (Remote Access Trojan) on the system. TCC blocks this as it prevents important folders such as the user&rsquo;s Desktop, Documents and Downloads folders from being accessed by any process without permission. This blocking works even if the RAT is running as a root process. In order for an attacker to access those folders, he would either need to &ldquo;reveal&rdquo; himself to the user by sending such a prompt such as the one below:</p>
<p><img loading="lazy" src="/posts/cve-2023-40299/tcc-prompt.png" type="" alt=""  /></p>
<p>This could alert the user that something is up. Thus, if the attacker can borrow preexisting TCC permissions from another application, or pretend to be another application while requesting such permissions, the user might be more amenable to granting it and also not raising any alarms.</p>
<h1 id="hardened-runtime">Hardened Runtime</h1>
<p>To enhance the security of MacOS, the <a href="https://developer.apple.com/documentation/security/hardened_runtime?language=objc">Hardened Runtime</a> security feature was introduced in Mojave (MacOS 10.14). Enabling Hardened Runtime is necessary in order to get an application notarised. Notarisation is a key requirement for an application to be executed smoothly by users without unnecessary prompts and it gives users confidence that the app has been checked by Apple for malicious components.</p>
<p>However, due to the restrictiveness of Hardened Runtime, Apple allows developers to uncheck certain settings (or in other words, set different entitlements) that may make sense for their applications.</p>
<p>The 2 entitlements that are interesting to us in this case (and this CVE), are <code>com.apple.security.cs.allow-dyld-environment-variables</code> and <code>com.apple.security.cs.disable-library-validation</code>.</p>
<h2 id="comapplesecuritycsallow-dyld-environment-variables">com.apple.security.cs.allow-dyld-environment-variables</h2>
<p>This entitlement, if enabled, allows the DYLD environment variables to affect the libraries loaded by the application, in other words, dylib injection.</p>
<h2 id="comapplesecuritycsdisable-library-validation">com.apple.security.cs.disable-library-validation</h2>
<p>This entitlement, if enabled, allows any dylib to be loaded and executed by the application. In normal cases, only dylibs that are signed with the same certificate as the application can be loaded.</p>
<p>These 2 entitlements, if enabled at the same time, allow a third party to inject their own dylib into the process space of the victim application.</p>
<h1 id="putting-it-together">Putting it together</h1>
<p>In my <a href="https://www.angelystor.com/posts/macos_tcc/">previous post on TCE</a>, certain DYLD environment variables can allow arbitrary dylibs to be executed together with an application.</p>
<p>A way that we can execute our dylib together with an application is a command such as this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>DYLD_INSERT_LIBRARIES<span style="color:#f92672">=</span>libDylibTest.dylib  WeakDylibApp.app/Contents/MacOS/WeakDylibApp
</span></span></code></pre></div><p>This runs the WeakDylibApp while also loading our dylibtest.</p>
<h1 id="cve-2023-40299">CVE-2023-40299</h1>
<p>With all the preamble out of the way, it&rsquo;s time to discuss this CVE.</p>
<p><a href="https://insomnia.rest/">Kong Insomnia 2023.4.0</a> was distributed with the previously discussed entitlements enabled.</p>
<p><img loading="lazy" src="/posts/cve-2023-40299/insomnia-entitlements.png" type="" alt=""  /></p>
<p>This allows an attacker to load whatever dylib he wants in the same process as Insomnia, and also inheriting whatever TCC permissions that Insomnia has. As a trusted developer app, a user would generally have no issues in granting it if the application requests for it.</p>
<p>The video below describes the attack. An arbitrary dylib that enumerates the user&rsquo;s Documents folders is loaded together with Insomnia, this fires up a TCC prompt if no such permission was granted before, the user would generally be inclined to allow the operation since it is issued by Insomnia, an application that he installed.</p>

<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
  <iframe src="https://www.youtube.com/embed/NciinjUQYQw" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" allowfullscreen title="YouTube Video"></iframe>
</div>

<p>This was reported to Kong and fixed <a href="https://github.com/Kong/insomnia/pull/6217">here</a>.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
