Hello, DEF CON. We have only 20 minutes, so let's get started. My today's talk is Electronizing macOS Privacy, a new weapon in your red teaming armory. My name is Wojciech Reguła and I'm a head of mobile security at Securing, where I'm mostly focused on macOS and iOS application security. In my free time I run a blog WojciechReguła.blog, which is of course about Apple security, and some of you may also know me from iOS security suite that I'm a creator of. It's a free and open source Swift library that helps developers make sure that their applications are run on secure iPhones, and recently I'm also engaged in macOS environment security assessments. So the plan for today's talk is that I am going to introduce you to TCC and privacy fundamentals on macOS. That will be a really quick introduction. And then we're gonna start talking about two problems. The first problem is with Electron applications, then the problem with TCC in general, and as a conclusion of those two problems I'm gonna show you my new tool that's Electronizer and it will be released shortly after after my talk. So watch my Twitter and LinkedIn. And at the end, because I'm releasing a new tool that helps red teaming exploitation, I will also say something about detections. Yeah, so let's start from the TCC and privacy fundamentals. Yesterday you could hear about SIP from JBO and two other friends from Microsoft. So let's start from the TCC and privacy fundamentals. Yesterday you could hear about SIP from JBO and two other friends from Microsoft. But let me quickly introduce you to system integrity protection for those who are not familiar. System integrity protection is a mechanism that is turned on on every macOS by default. And on macOS, even if you have root permissions, you are not a god. You cannot do everything you want with your machine. Because of the system integrity protection that will prevent you from modifying some crucial operating system parts. For example, even if you are root, you cannot debug Apple signed processes or process with hardened runtime. Or for example, you cannot modify some files, some directories that are part of macOS. And when the system protection is turned on, the TCC comes into play, the privacy framework that I'm about to talk about. And when the system protection is turned on, the TCC comes into play, the privacy framework that I'm about to talk about. So when you open, for example, a terminal or any other application, and you'll try to list address book or documents or desktop or get access to any other privacy sensitive resource on macOS, you will see a prompt. In this example on the slide, you can see that terminal would like to access your contacts. And Apple wanted to make sure that even if you are a root user, you cannot skip this prompt. And Apple wanted to make sure that even if you are a root user, you cannot skip this prompt. And Apple wanted to make sure that even if you are a root user, you cannot skip this prompt. It means that you just found a TCC bypass. So even if you are able to perform synthetic clicks, and your synthetic mouse clicks on the OK button, nothing will happen. Apple wanted to make sure that physical user clicks on the OK button and then the TCC permission is granted. You can find the TCC permissions and settings, and privacy at security tab. And as you can see, there are many, many different ways, and there are many, many different ways, that you can use TCC. many many resources that are now protected by the TCC and TCC is really granular so if you go for example to automation you can see that you see is that granular that even you can specify which application could control which other application and yeah every major Mac OS version introduces new TCC protections new resources that are considered as privacy sensitive so this is certain huge development from our hackers perspective that TCC stores the the permissions and SQLite free databases and there is one global TCC database in library application support come up with this directory and per each created Mac OS user there will be a separate database because for example one Mac can be used by for example two people and one has a broad two of them have for example Google Chrome and the first one wants to give from access to your camera but the second user doesn't so you know to solve this problem for each user there will be a separate database and of course those databases are protected by SIP so even if you are rude you can not modify directly those databases without the special permission especially the global one cannot be modified and as I said TCC databases are SQLite free so you can open SQLite tool and do a select and as you can see we have foreign columns the first one have the permission name the second one client has bundle identifier and sometimes in this column you can find a full path to the applications that have permissions granted our value of course and CSREC and CSREC stands for code signing requirement and you might ask why are there question marks and the question marks are there because the code signing requirements are binary blobs so you know you cannot read them with with just a simple select but we will decode them later all right now let's start talking about electron and the problems with electron as you probably know a lot of applications now are electron based so for example slack twitch visual studio code discord notion teams wordpress or github but there are many many more so you probably if you have Mac and you download desktop applications you probably will have at least one electron app installed installed and just to introduce you how electron technology works and it can be considered as a and embedded web browser with a website that runs in the context of that web browser so as any other website website needs to have an HTML file CSS files and javascript files that problem starts when the javascript files have a bridge to your system API and election apps needs that bridge because as they are applications they maybe sometimes want to move a file or save a file or write write something to a plist or to a user default or something so yeah they actually need that OS API bridge and as you may also notice in the past there are a lot of vulnerabilities at that let's to remote code execution and usually it was about executing a simple XSS right prostate scripting vulnerability but we are not talking about web security on this talk we are talking about Mac OS security so let me introduce you to another problem with electronic applications and the problem is that on Mac OS popular election applications require also granting them TC permissions for example install Microsoft themes and they will instantly ask you for your camera access for your microphone actors or screen-sharing access those oh you know US are about the CC provisions and in badkin 2019 I made a blog post abusing election up to buy bus markers security controls where I showed that election applications may be abused and Eway malicious application may take over the ATCC permissions that have been already granted by users. So I showed in the blog post that if you have a simple vulnerable electron application, which as you can see on the screenshot has access to my camera, because that's me, and save something to the macOS keychain, so it's a simple electron application with this bridge to system APIs because we have camera access and keychain access. I proved that if you do echo with whatever you want and override the base HTML file, it will of course break the signature of the whole application because you modified one of its files. But what happens if you run this broken signature application? Nothing happens. As you can see, the code has been injected, but you can see my arm, which means that the camera is still on. And you can see that the keychain entry is still reachable from that application. And why is that? The problem here lies with macOS, which verified only the signature of the main executable. And as we are not modifying the main executable because we modified HTML file, everything is fine. And with that trick, you could, for example, execute any JavaScript code within the electron apps context. You could load a dynamic library or you can spawn a calculator, right? But it's the past. macOS Ventura fixed this technique. So now if you open terminal, unprivileged terminal, you go to applications and you'll try to, for example, modify any file, within the electron apps directory, you will see that the operation was not permitted and there will be a notification that terminal was prevented from modifying apps on your Mac. And that's good. That's Apple's fix for the general problem of modifying app resources. Now when you open an application for the first time, its directory is being locked, so only the application signed with the same developer ID is able to modify itself. That's reasonable because, for example, applications need somehow to update themselves. So that's reasonable. So I wanted to develop something new to get code execution within electron applications. But now let's talk about TCC permissions inheritance. So TCC permissions inheritance is really, really complicated and led to many vulnerabilities in the past. And please make a notice that this slide may not be always accurate because Apple is still changing the implementation of TCC inheritance. So yeah, that may change. And general speaking, which not always may be true, but general speaking, when an application has private TCC entitlements, the children that are spawned by these applications will not have their TCC permissions inherited. But when you download an application from the Internet and you grant for the downloaded application TCC permission, it asks for your permission, the TCC permissions will be granted to its children. Fortunately for us, for us hackers of course, electron apps are the second case, right? So those are downloaded from the Internet or from the App Store and you grant the TCC permissions, so every children spawned by electron application will have its permissions inherited. So if there was only a technique that doesn't break the macOS Ventura app protection mechanism, we could get the takeover of the TCC permissions. And that's when I introduced my new tool called Electronizer. And Electronizer abuses the fact that electron apps are, as I said at the beginning, native browsers with embedded websites. And every browser has developer tools, right? You click Control-I and you can execute JavaScript within the context of the web page. The same thing is with Electron. You can spawn them with inspect flag and under the hood the Electron applications will open a web socket to which you can connect and execute JavaScript code within the context of those electron apps. And as I said, all the children spawned by those applications will inherit our TCC permissions. And Electronizer connects to this, spawns those applications with inspect flag, connects via web socket, and spawns, you know, our malicious payloads. So let's take a look on Visual Studio Code, which usually has access to your desktop document download because it's a, you know, code editor. So it needs to have such access. Let's see the demo. So we open Electronizer with inject parameter. We want to inject to Visual Studio Code with predefined script bind shell. So Visual Studio Code under the hood will spawn a bash shell. And we can access the web, the shell via NC. But let's first verify that we cannot indeed access the desktop files. As you can see, the operation has not been permitted. But now let's use the shell that we've just spawned. It's in the context of the Visual Studio Code. Visual Studio Code spawned that shell, so that's the children of Visual Studio Code. That's a child for Visual Studio Code. Now let's use TCC Checker Swift, which is a cool retining tool created by Cedric Owens, which enumerates directories to which we have already access to without raising any TCC prompts. So it's still. And now let's cut the secret TXT. And it succeeded, which means that we have been able to successfully take over Visual Studio Code's permissions. Now let's do the same thing but with Microsoft Teams. But now we are not going to get access to files, but to your camera. So we use the predefined script takeSelfie. And as you can see, tmp.selfie.jpg has been created. And let's now open the file. That's me, which again means that we have taken over Microsoft Teams camera access. But what if the Electron application disabled inspect flag? You may ask. Why those vulnerabilities I presented are zero days and are not zero days at the very same time? Because there is no such option for now to fix them. Even if you disable inspect flag, and let's take Slack for example. If you open NPX tool and read up application Slack, you will see that the flag enable no CLI inspect arguments are disabled. So it means that Slack application will not respect the inspect flag. There is another problem, but with the TCC. Do you remember the question marks I told you about? If you use the following code, you can decode those codesigning requirements to human readable version. And the human readable version defines the codesigning requirement as of course said. And as you can see, this codesigning requirement defines only the information about the certificate that was used to sign Slack, right? There is no information about the Slack version. So you can use a typical downgrade attack to abuse the TCC. So let's inject Electronizer to an older version of Slack. So we have one Slack. The newest version already installed, but we as a Red Teamers, we're going to deliver an old version of the Slack. And from the Mac OS perspective, that will be the same Slack. So, Electronizer inject volumes because it's mounted Slack. And predefined script. Screenshot. Give it a while. And as you can see in TMP screenshot, we'll have our screenshot. Yeah. So as you can see, the screenshot has been opened. Yeah. So regarding the detections, as now on Mac OS, we have endpoint security framework. The easiest way to detect such a technique is to filter for ES event type notify exec because in the context parameter, you will have all the flags passed to applications that are in spawn. So if you detect there is an inspect flag used to spawn an election application, you may expect that something bad happened. So summing everything up, I showed you that the TCC permissions inheritance is possible to children spawned by Electron applications. And even if we have a Mac OS Ventura or any other modern Mac OS version that already has the app protection mechanism, we can still abuse Electron applications to take over their permissions. And even if you find an Electron application with TCC permissions granted and you want to abuse them, but the inspect flag is disabled, you can still, as a red teamer, download under the hood an older version of the version application with the inspect flag respectable and still take over the TCC permissions. So that's it for now. Thank you very much.