So, thanks everyone. I'm John. So today we are starting to share about how we steal the PRT cookie on macOS. And use the PRT cookie persistent in Android. That's a very funny fact is we realize Microsoft implementation on macOS for PRT cookie is more security implementation than on Windows. So I will starting first and I will hand over to the next speaker. I'm John. I'm the director of research at Sidecraft. And I have a blogger called HackerPenisJohn. And I'm a researcher so of course I speak at several conferences. But it's my first time in DEF CON. So let's jump in on today's topic. Because macOS has a lot of different type of service. Maybe 100, 200. And if you don't want our computer asking the password again and again, we need to ask our computer single sign-on to help us single sign-on to this service. You can log in all of them using the Android ID account or we call, consumer site we call Microsoft account. So you can use this account to do a single sign-on. But how it work? This is how it work when Windows generate SSL token for your browser. I will explain about Windows part and later on Cosmo will introduce about the macOS part. There's a two component, LSAS, which is handle the authentication process. And there's inside LSAS, there's a plugin called CloudAT. CloudAT will interact with the TPN, which is trust platform module. The TPN is designed for make sure the private key and secret key never leave on this device. And then there's a two element stored in the TPNs. PRT, primary refresh token, represent the user identity. And the session key is a device identity. So if you have a PRT, we can exchange everything we want. But by the design, the PRT will not directly single out the TPN. We need to calculate the PRT to the PRT cookie. The PRT cookie only has a 50 minutes lifetime. And we can use the PRT cookie to token exchange to the refresh token and access token. The max lifetime is 24 hours. And then we can use the access token to log in the cloud service. And here is how it go in detail process in the Windows system. There's a browser like Edge, Chrome, Firefox, they can have a pass announce to the browser code which is building binary inside of Windows. And the browser code will interact with Microsoft account token provider DLL and send a request to LSATS process. LSATS process will calculate the PRT cookie sent to the browser. And in this process, there's at least three way to abuse the process and get a PRT cookie. First, the raw tools and the second is request a refresh token and the token broker. They are leveraging a different stage and abuse until today they can still can get a PRT cookie from the Windows system. The PRT cookie will contain some information very important for us. Like a user identity and the link device information. Which means if you have a PRT cookie from a device, usually we can get the MFA claim and the device claim. Which means I'm from, I'm coming from, I'm user A, I'm coming from a trust device and I comply with some requirement. This can help us pass some condition as a policy check. So it's why stealing a PRT cookie is so valuable. Here is our today's objective. We will steal the PRT cookie from macOS because Windows have already researched it but macOS are not. But a PRT cookie only has a short term lifetime so we want a long term persistence. And comply some security requirement for the condition as a policy and as a critical resource. And now I will hand it over to Kazuma to introduce macOS part. Thanks John for the great overview. And welcome everyone to the wonderful world of Apple. Today in my session I'm going to talk about how do we steal the macOS PRT cookie. Before we dive in let me introduce myself first. My name is Kazuma, but feel free to just call me Kazuma. And I'm a university student from Taiwan and also I'm a CD player. For the past few years I've been leading a pretty active team called Beef Soup and we've managed to bring home quite a few trophies along the way. Recently I'm just transitioning from the intern to researcher at Cycler Technology. So I'm still learning a lot every day and I really appreciate the chance to be here and share research with all of you. So let's dive in with one question. Why do we research steal the macOS PRT cookies? Today many organizations rely on Intune as their end-to-end solution for both Windows and macOS. And with conditional access now extending to the macOS part, zero trust policy is no longer just a Windows story. But here's the thing. Most research and detection still focus on the Windows. And macOS on the other hand remains largely unsolved. And of course Dirk Jong and Olaf's research on macOS was a huge inspiration for us and gave us a solid starting point. From there we decided to dive deeper into how macOS handles the PRT cookies and more importantly where the weaknesses are. So if we want to steal the macOS PRT cookie, we must enroll our macOS device into Entral ID first. And according to the Microsoft documentation we can see that it needs us to download and use this company portal app. And the company portal app has two main parts. On the left you can see it's interrelated part for device management. But what we really care about here is on the right. This is where even like the macOS apps and even Safari go through. It's SSL extension for it. You need to do the single sign thing to the Entral ID. And it used to be called platform SSL but as we all know Microsoft loves to rename things so it's not a good name. And now let me put out some components that are related to the SSL part in the company portal. There are two main plugins and one is the SSL extension what we mentioned earlier and it used to be called platform SSL extension. And the other one start with the autofill which we are not going to cover today. Also we can see there is a framework under the SSL extension called the authentication broker macOS. And this is the library most of performing more for the color validation checks. And a framework on the macOS is kind of like DL on the Windows. Both provide libraries but a framework on the macOS contains more bundle resources. But it's pretty much the same concept though. Also at the same time we can see there is browser core under the resources folder. Which also appear earlier in the Windows SSL floor. And earlier in John's session we can see that the browser core is playing the key role handling SSL requests from- initiated by the Google Chrome. So as we saw that company portal also has this app is cross core. We immediately suspect it might serve a similar purpose for handling SSL requests on the macOS as well. So to help visualize the comparison I put together the macOS diagram from the Windows one. We can see that Apple provide app SSL agent to do the SSL part. Handle requests from different vendors. But this diagram is a little simplifier. Actually it has authentication framework to offer API and do the front end part. And the app SSL agent is just doing the back end part. But it's easier to understand that. And macOS doesn't have LSS. So the component responsible for computing the final PID cookie is the SSL extension under the company portal. And any request passed into the company portal will go through its ID authentication framework to do the color validation checks. And after we have the basic understanding of the macOS ecosystem, now we have let's summarize what we have found. Totally we found three methods to fill the macOS PID cookie. Next I will get through each of them and explain how they work. The first one is head browser pass method. The first one is pretty straight forward but Microsoft provide us this extension called Microsoft SSL Chrome extension. And we can just initiate an SSL request and directly retrieve the output there. So when we compromise a macOS device, we can just initiate a headless browser and install this extension and then we can initiate an SSL request and get the PID cookie right away. And from the logs we can also confirm that a browser core is handling the SSL request, playing the key role in the SSL flow like the Windows one. But this method does come with some limitations is that we need the victim to be logging into their desktop session. Because headless browser doesn't mean there's no GUI dependencies. It's more like a transparent browser running in the background. So we need it to log in their session. And also there's also another limitation is that this technique only works with official Chrome and Microsoft Edge. And we'll know why when we get to the third method. So to wrap up the first method, we found that this first method has specific dependencies, but of course we won't satisfy with just that. Next we'll move to the second one. The bypass browser core's parent process check. So after some reverse engineering of the browser core, we found that whenever the browser core needs to check its coder, it will first call running application with process identifier, this function, and get the parent process info. And then it will concatenate like it can get the PID from the info and concatenate coside HDV to execute this command and get bundle ID and team ID. Also when it has this two value, it will concatenate it and hash it and check against internal wireless. And here's the fun part is that until very last our research, we found that this running application function only work with direct process. So later in our POC, you will see that we package the whole script into a direct process. And here you might find some terms that I'm familiar with, which is team ID and the bundle ID. And let me explain them quickly. The team ID is the identifier included in the certificate issued by Apple to each developer. So only the developer owns the certificate can sign the app with their own team ID. But bundle ID on the other hand is just a string for identification. It has no real security value. So we can change it to whatever we want. In short, attacker can affect the bundle ID but team ID doesn't. Also we can found that there are some similar mechanism on the Windows 4. It's called security identifier or somebody call it SID. In this flow we can see that security identifier is more like a bundle ID is just for identification. So we can also change it to whatever we want. And this is interesting because that Microsoft never implement something like the team ID on their operating system. So they check this security identifier is a bit pointless. And also we found that this SSL flow involves a lot of components and that means a lot of coders. And more coders means more coder validation checks. So let me clear things up and focus on the most two important one. The first one is the coder of the browser core. And of course as the name suggests is the browser. And in this case it can be the Google Chrome or Microsoft Edge. And also it is the parent in the parent process check in our earlier talk. And this is what we have mentioned about here in the diagram. This is the part like the Google Chrome call into the browser core. So let me read off the attack strategy. First we create a parallel binary and second we have a fake call site and put it in the slash TMP directly. And we have it use the binary ID for Google Chrome and the team ID. Also we package the whole process into a process and that the browser core can retrieve the parent process info since the running application function. And here's the real problem is that browser core runs this call site HDB function just without the absolute pass. So we can use pass in the session to change the environment variable to slash TMP to let it run the fake one instead of the real one. And here's the screen shot of our POC. And this execution is clients and so running it, showing the video will be kind of funny. But we will release this tool at the end of our talk. And here's let me share some little funny story here. At first, when we try to do the second method, we first do the pass to browser core. And when we run it from the terminal, we found it running an error. Caller is not allowed to invoke. With an error call, it's minus 6,000. So we decided to use the LDB to dynamic debug it. And to our surprise, we just get the PID cookie right here. So that led us to dig into what happened behind the scenes. And from the logs, we can see that in the fail run, it can't retrieve the bundle ID and team ID. And the component responsible for this function is app SSL agent. So later, we started to analyze it and we found that the key point is that whenever app SSL agent need to retrieve the process, team ID and the bundle ID, it will check if it has CS value flake or the CS debug flake. So this explain everything because earlier when we patched the browser core, the CS value flake became false. And when we attach it with the LDB, the CS debug flake was true. Somebody will think that maybe LDB can be one of our method to get the PID cookie. But actually, we think about that too. But it need us to disable the system integrated protection and also we need to use touch ID or the password to pass the developer tools SS prompt. So if we want to use it with LDB, we must need some extra privilege escalation. So we want to try find some method just in the browser core to get the user privilege. And here come the second caller. It's called caller of the app SSL agent. And in this case, it's browser core. Also, it can be other vendors helper tool. And whenever you are the caller to call app SSL agent, you need this CS value flake or the CS debug flake to that app SSL agent to retrieve your team ID or bundle ID. And this is why we are talking right now. Is the browser core calling to the app SSL agent part here. So to wrap up the second method, this method can run without any dependency and also it can run in the user privilege. So that little LDB twist story make us dig into the ID authentication framework and we found that this browser core method is just the tip of the iceberg. Actually, we found that there are four paths for the SSL. And that lead us to the third method. Direct SSL invocation via the Apple's API. And this SSL method, the first one is browser native message. This is the same route of the browser core. And the second one is passkey credential operation. And this two method checks bundle ID and the team ID. So there's no problem with that. But the problem is there are two paths not check the team ID at all. Is the general SSL extension request. This is mainly used by the Microsoft apps like the PowerPoint, Outlook, Teams, Excel, something like that. And there are also cookie SSL acquisition is for the third party apps like the Firefox or the Opera. And like the cookie SSL one, it also, this bundle ID is content for three subsets. It's like edge bundle IDs, third party browser bundle IDs, non-native browser bundle IDs. Totally there are 39 bundle IDs. And if it only checks the bundle IDs, what we need to do here is only pick anything we like. And just like that, we can also get a PID cookie right here. And this tool will also like the second one releasing at the end of our talk. So to wrap up the third method, we can also see that it can run without any dependencies and also run in the user privilege. So here in my session, I'm successfully make the PID cookie thief into a reality. But here's some problem. PID cookies only survives for about 15 minute-ish. And how can we achieve persistence and keep the attack going? So, how can we achieve persistence? Before we started, allow me to first introduce myself. My name is Echo. I'm also a cloud security researcher at Sidecraft. I have presented in multiple security conferences, such as RootCon and FIRST, and most of my research focus on cloud security. So back to our subject, why do we need persistence? As Kazuma said, PRT cookie is only valid for a few minutes. However, the core reason of this question is that we don't have the TPM, the PRT, and the session key is stored in the hardware, which as an adversary, we cannot access it, even we have the administrative privilege. So how do we achieve persistence? A general solution is to abuse the device during scenarios. A attacker, by registering a new device, they can have their own PRT and session key, so they can generate their own PRT cookie continuously whenever they need it. However, by registering a new device, we cannot only achieve persistence, we could also bypass some conditional access policies. However, registering a device has a requirement that it requires an access token without device ID, which means we cannot use the stolen PRT cookie from a device to register another device. And as I just said, we also want to bypass conditional access policy. And the most common conditional access policy is to require multi-factor authentication. However, token issued through passwordless authentication also contain the MFA claim. And sometimes conditional access has a stricter policy, such as it requires passwordless authentication or phishing-resistant authentication, such as Windows Holo for Business or FIDO. So we also want to register our own Windows Holo for Business key or platform credential on macOS, which is basically the same thing for MSHOP, but just a different name on different OS systems. And however, registering a new Windows Holo for Business key requires an access token that contains something called an NGC MFA claim, which stands for Next Generation Credential Multi-Factor Authentication. And to have an access token with NGC MFA claim, you have to pass the MFA authentication again. And then within the last 10 minutes, the token will be validated and you will be able to register a new Windows Holo for Business key. Well, long story short, you can consider an NGC MFA claim as something as a fresh MFA status, which prevent adversary from stealing access token containing a cache MFA status to register a new Windows Holo for Business key. And another common conditional access policy is required device to be marked as compliant. And this could be achieved by PyTune that is released last year in Black Hat Europe. And however, PyTune does not support macOS for now. Okay, so here is our persistent flows. First, we get a token without device ID, then we find a way to re-authenticate via multi-factor authentication, register a new device and make the device compliant, then register a new Windows Holo for Business key. And the step three and step five can be done by Duracron's rule tool. And the step for device compliance can be done by a U.S. Trudeau's project, PyTune. So the true difficulty of our persistent flow lies on the initial step, which we cannot use a stolen PRT cookie with a cache MFA status to get a token without device ID and a token with NGC MFA claim. And this problem does not exist in the past, since Microsoft fixed them all. And we can no longer use the single-sign-on token for device registration, and the MFA claim would not transfer to the PRT after registration. And there are some other topics we are not mentioning here, but if you are interested in this topic, feel free to... I highly recommend you to read Duracron's blog post. So how do we get a token without device ID? Well, it is easy for a legitimate user to do it, since they just need to enter their ClearTask password on a non-single-sign-on device. However, it is difficult, a challenge for our adversary, since even if we compromise the victim's device, we don't know their ClearTask password. And so, a common technique to get a token without device ID is through phishing. And the upside of phishing is that it does not require compromising a device. It just needs to convince the user to enter their credential. And the downside of it is that phishing is unreliable. So since in our scenario, we would already compromise a device, we suggest another approach, which is abusing Kerbal's Simply Single Sign-On. The upside of it is that it keeps the noise level low. You don't need to unmodify with the authentication methods. You just need a service ticket in exchange for an SS token. And the downside of it is that only less than 25% of tenants have this setting enabled. And it can only abuse on a Windows system that is hybrid joined . So we start thinking that, could we just simply reset the victim's password? And the downside of it is obvious. It could use across all operating systems, regardless of its joint type. And the downside of it is that resetting the password may trigger some alerts. But the biggest problem here is that, could we reset the password without knowing the current one? Well, if we look into the MySign service of Microsoft and try to log in with an SS token containing password and MFA claim, then we can reset the password directly without knowing the original one. And in this case, we will call the API, API password reset. However, if we log in with passwordless authentication, it only contains MFA claim. So we have to enter the current password since we don't have the password claim in our SS token. And in this case, it will call the API password change. So of course, as adversary, we tend to abuse API password reset. But it seems this abuse is limited to password authentication user, not passwordless authentication user. But this is not true. And we found out there is inconsistent logic between the front-end and back-end logic of the MySign service. Actually, calling API password reset only requires the MFA claim. The password claim is not required. So we could also reset a password on passwordless authentication user without knowing their current password. And something you need to notice is that we can always reset a password without considering the SSPR, self-service password reset is enabled or not. So we can always reset user's password. And our last approach is adding a passkey in Microsoft Authenticator or your mobile device. And the upside of it, it keeps the noise level low. You add a new authentication method without modifying the old one. And since passkey is a passwordless authentication via FIDO, you also get a token with MFA claim. The only downside of it is that it requires user interaction with your browser and your mobile device, since you need to store your passkey in your mobile device. And however you may consider that adding a passkey is some sort of MFA bypass, well, it's not entirely correct. But it's not easy to get an SS token with an MFA claim. Is there something that I didn't mention? Other requirements? Let's talk about how do we find a way to re-authenticate via multi-factor authentication. So, as we said, general solution, if we try to reset the password, we have to know the current password. But we know in the last NASDAQ, Microsoft kind of like threw up. But they did a better protection for Windows Hello for Business, as they require a fresh MFA to add a new Windows Hello for Business key. However, if we just try to register a new MFA method or a single multi-factor authentication, such as a passkey or TLTP key, we don't need a fresh MFA token, which means we could use the stolen PRT to add a new one. And that makes the NGC MFA protection useless, since a hacker can register their own MFA to bypass the NGC MFA protection. So, the NGC MFA protection is a good idea. However, its actual implement is flawed, just like this French fries in the door. So, interesting thing is we report to Microsoft with a title, MFA bypass. And the response is that they determine this is not a vulnerability and claim that MFA bypass is a hyperhole. We agree with them, since we have to have a PRT cookie with a cache MFA status. However, this is not an MFA bypass. Actually, this is a next generation credential MFA bypass, which makes it sound even worse. So, it seems to imply that Microsoft forbid us from using stolen device credential, which is our PRT cookie, to directly register a new device. However, if we multiply the authentication info first and then register a new device, Microsoft seems to be okay with it. So, we think it's unreasonable, but we accept the result. However, Microsoft changed their mind in like July 30, and after we provide them with our slide with this picture on it. So, they determined that they have to provide stronger authentication in the future, such as fresh MFA to better protect Microsoft's service. And John will talk about the detail first, but I will rather show you the demo. So, okay. Here is our attachment. We'll first request a PRT cookie directly to a single sign invocation by an Apple API. And then, we'll abuse a device join scenario. First, we'll reset the password, get a token with our device ID, register a fake new device, add MFA, and register a new Windows Hello for Business key. And we skip the device compliance part to shorten the demo. And if the device registration requires multi-factor authentication, you just need to switch the step. Just add MFA before we register the fake device. So, here is our demo. First, we need to check our compliance policy or conditional access policy. It requires our user to pass multi-factor authentication to access to our target resource. Then, we are looking at the victim's device, which is a Mac OS system. And we know our victim's name is called Adele. And we request for a PRT cookie. And then we pass the PRT cookie from Mac OS to our attacker's machine. And we exchange for a MySignService token. And since we don't know the victim's password, we need to reset it to have a new one. Now, we try to call the API password reset to get a new password. Now, the password is reset successfully. Then, we can register our new device with our new password. And that is successfully. So, we try to log into Office 365 with our new password and our username. And now we are blocked by the multi-factor authentication. So, we try to the PRT cookie again and add a new multi-factor authentication. And this time, we'll not done by direct API call. We will open up the browser so that it's more easy to understand. Okay. We log into the MySignService website and try to add a new MFA. Okay. And in this process, we'll try to add our TOTP key into the key pass. And Microsoft will ask us to verify it again. Okay. Now, we successfully add our new MFA without prompting down another authentication. Now, we'll try to register our new Windows Hello for Business key. But we need a token with NGC MFA claim. So, we need to pass the MFA again and check our access token. It actually contains NGC MFA claim. Yeah. Okay. Now, we got our own Windows Hello for Business key and we try to log in on our new device with the Windows Hello for Business key. Now, we successfully log into the Office 365 and bypass the multi-factor authentication. And finally, we check our authentication method. And we register a new Windows Hello for Business key on our demo machine, which does not physically exist. And this is all for our demo. Okay. And if you like it, feel free to give us some applause. Thank you. Okay. Thanks for the demonstration. So, let me review what I just saw. In this demonstration, actually we got a PRT and a very strong MFA just like Microsoft say, they love the Windows Hello for Business. So, you have a strong MFA. And all this element is coming from the fake device. So, we are not just accessing the cloud resource, but also if we will have a PRT, we can let them run between the NHID joint device. This is a talk in this year in Troopers has mentioned about how to let them run movement in NHID joint device . By default setting, global administrator and device owner are local admin in NHID joint device. So, you can use the PRT, exchange it to the P2P certificate and the login in NHID joint device. You just saw a demo and you might think if you are familiar with the condition as a policy . You might think, hey, why require the MFA for joint device and I require MFA for update their security information. Actually it's not enough and you might encounter some deadlock problem in this scenario. I just share with my friend this tech master and he just apply this condition as policy and he encounter some problem. If you have new employee on boarding, you just give them your password and the account name. They just log in. The first time log in, they don't have MFA. NHID asking, hey, you need the MFA, but you have to pass MFA first. So, they encounter some problem. The new employee cannot add their own MFA. So, only way to escape out is on the documentation for the Microsoft. You need to log in with the tab for the initial login. This is the only way to escape out in this deadlock situation. If you apply this condition as policy, actually it's not enough. Just in case you didn't film the video, yeah, so I prepare a diagram for the easy to understand whole attack pass. We assume we have a compromise in tune or window hollow for business device. We extract the PRT cookie with MFA. And then we have a two thing need to do. First, add a new MFA. The conditional access require us need to pass MFA first and add in the new MFA. But we already have MFA client, so we can easily satisfy this policy check. And on the reset password, we just want to add on the fake device. So, we can change the user password without we know, we don't know the current password. It's a UI inconsistency in front end and back end. We are easy to get the new MFA and control the user password. And now we can persistence in Android ID. We can reduce a new device. And then you need, we're trying to reduce device user require MFA. But we already add our own MFA, so we can easily satisfy this policy check too. And then we can upgrade our fake device to windows hollow for business. We can easily authenticate MFA in five minutes. And then persistence in Android ID. How Microsoft response us our finding? This is very interesting. Because Microsoft for the Mac OS they already fix. But for the windows side, they never fix this. It still can get the PRT cookie on windows. But now it's not on the Mac OS. And for the Android ID persistence method, the first time the response, you have to compromise someone windows. Maybe very hard, right? So, just one week ago, they know we are speaking at DEF CON, they decide to fix it. Maybe one month or one week later, they will fix it. They also have a recommendation for the make a cookie PRT safe. Just update. If you cannot update yet, you can just monitor following criteria, like a call sign. It should be always running on the user bin folder. And monitor the header browser. If there is a binary, has a bundle ID we mentioned today, but there is a binary don't have enough, just trigger the. Also, even Microsoft implement this update, but you should check your Intune's policy. Because if you want some bundle ID, you still encounter some problem. You still possibly get the PRT cookie safe on your Mac OS system. And here is a summary. We found that the PRT cookie safe on Mac OS is now a reality. And we've also noticed other vendors, not just Microsoft, other vendors have implemented the SSO extension on Mac OS. We think there might be a similar problem. You are a Mac OS developer, you should choose a team ID, not a bundle ID to verify the binary. And before Microsoft already implement the patch, just pray for your end point never being compromised. And here is some mitigation for the persistent method. You can create a weak criteria from the condition as a policy. Like the IP location, user agent, just make the attacker very hard to add a new device or add a new MFA. And then monitor the new joint device and then add a new MFA. If you have an employee add a new device, you can trigger alert, but it's kind of annoying. Yeah. And thanks. And here is our cool release. You can check on this for Mac OS cookie safe. And thank you.