1 00:00:00,000 --> 00:00:03,060 So, thanks everyone. 2 00:00:03,380 --> 00:00:04,440 I'm John. 3 00:00:04,440 --> 00:00:10,540 So today we are starting to share about how we steal the PRT cookie on macOS. 4 00:00:10,920 --> 00:00:13,960 And use the PRT cookie persistent in Android. 5 00:00:14,140 --> 00:00:25,940 That's a very funny fact is we realize Microsoft implementation on macOS for PRT cookie is more security implementation than on Windows. 6 00:00:26,340 --> 00:00:30,560 So I will starting first and I will hand over to the next speaker. 7 00:00:31,340 --> 00:00:32,320 I'm John. 8 00:00:32,320 --> 00:00:34,860 I'm the director of research at Sidecraft. 9 00:00:35,020 --> 00:00:37,700 And I have a blogger called HackerPenisJohn. 10 00:00:37,720 --> 00:00:41,240 And I'm a researcher so of course I speak at several conferences. 11 00:00:41,240 --> 00:00:43,020 But it's my first time in DEF CON. 12 00:00:43,620 --> 00:00:45,940 So let's jump in on today's topic. 13 00:00:47,640 --> 00:00:50,760 Because macOS has a lot of different type of service. 14 00:00:50,760 --> 00:00:52,600 Maybe 100, 200. 15 00:00:53,460 --> 00:01:05,080 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. 16 00:01:05,080 --> 00:01:11,300 You can log in all of them using the Android ID account or we call, consumer site we call Microsoft account. 17 00:01:11,920 --> 00:01:14,680 So you can use this account to do a single sign-on. 18 00:01:14,680 --> 00:01:15,980 But how it work? 19 00:01:17,240 --> 00:01:22,860 This is how it work when Windows generate SSL token for your browser. 20 00:01:23,580 --> 00:01:29,260 I will explain about Windows part and later on Cosmo will introduce about the macOS part. 21 00:01:30,480 --> 00:01:35,860 There's a two component, LSAS, which is handle the authentication process. 22 00:01:35,860 --> 00:01:39,680 And there's inside LSAS, there's a plugin called CloudAT. 23 00:01:39,700 --> 00:01:44,860 CloudAT will interact with the TPN, which is trust platform module. 24 00:01:45,520 --> 00:01:51,640 The TPN is designed for make sure the private key and secret key never leave on this device. 25 00:01:52,460 --> 00:01:56,420 And then there's a two element stored in the TPNs. 26 00:01:56,740 --> 00:02:00,680 PRT, primary refresh token, represent the user identity. 27 00:02:00,940 --> 00:02:03,800 And the session key is a device identity. 28 00:02:05,800 --> 00:02:10,780 So if you have a PRT, we can exchange everything we want. 29 00:02:10,780 --> 00:02:15,720 But by the design, the PRT will not directly single out the TPN. 30 00:02:15,720 --> 00:02:19,700 We need to calculate the PRT to the PRT cookie. 31 00:02:19,800 --> 00:02:22,760 The PRT cookie only has a 50 minutes lifetime. 32 00:02:23,620 --> 00:02:29,420 And we can use the PRT cookie to token exchange to the refresh token and access token. 33 00:02:29,420 --> 00:02:31,860 The max lifetime is 24 hours. 34 00:02:32,160 --> 00:02:36,320 And then we can use the access token to log in the cloud service. 35 00:02:40,180 --> 00:02:44,800 And here is how it go in detail process in the Windows system. 36 00:02:45,040 --> 00:02:55,120 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. 37 00:02:55,960 --> 00:03:03,680 And the browser code will interact with Microsoft account token provider DLL and send a request to LSATS process. 38 00:03:03,680 --> 00:03:08,120 LSATS process will calculate the PRT cookie sent to the browser. 39 00:03:08,540 --> 00:03:19,020 And in this process, there's at least three way to abuse the process and get a PRT cookie. 40 00:03:19,020 --> 00:03:26,080 First, the raw tools and the second is request a refresh token and the token broker. 41 00:03:26,080 --> 00:03:35,220 They are leveraging a different stage and abuse until today they can still can get a PRT cookie from the Windows system. 42 00:03:37,900 --> 00:03:42,080 The PRT cookie will contain some information very important for us. 43 00:03:42,080 --> 00:03:45,320 Like a user identity and the link device information. 44 00:03:46,280 --> 00:03:54,460 Which means if you have a PRT cookie from a device, usually we can get the MFA claim and the device claim. 45 00:03:54,460 --> 00:04:01,640 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. 46 00:04:01,700 --> 00:04:05,900 This can help us pass some condition as a policy check. 47 00:04:05,900 --> 00:04:09,100 So it's why stealing a PRT cookie is so valuable. 48 00:04:10,900 --> 00:04:13,160 Here is our today's objective. 49 00:04:13,500 --> 00:04:20,880 We will steal the PRT cookie from macOS because Windows have already researched it but macOS are not. 50 00:04:21,540 --> 00:04:26,380 But a PRT cookie only has a short term lifetime so we want a long term persistence. 51 00:04:26,980 --> 00:04:33,160 And comply some security requirement for the condition as a policy and as a critical resource. 52 00:04:33,160 --> 00:04:37,120 And now I will hand it over to Kazuma to introduce macOS part. 53 00:04:41,510 --> 00:04:44,350 Thanks John for the great overview. 54 00:04:44,730 --> 00:04:48,550 And welcome everyone to the wonderful world of Apple. 55 00:04:48,730 --> 00:04:54,430 Today in my session I'm going to talk about how do we steal the macOS PRT cookie. 56 00:04:55,450 --> 00:04:58,350 Before we dive in let me introduce myself first. 57 00:04:58,350 --> 00:05:02,210 My name is Kazuma, but feel free to just call me Kazuma. 58 00:05:02,450 --> 00:05:06,850 And I'm a university student from Taiwan and also I'm a CD player. 59 00:05:07,350 --> 00:05:15,770 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. 60 00:05:16,430 --> 00:05:21,410 Recently I'm just transitioning from the intern to researcher at Cycler Technology. 61 00:05:21,950 --> 00:05:28,970 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. 62 00:05:29,690 --> 00:05:31,950 So let's dive in with one question. 63 00:05:32,690 --> 00:05:36,190 Why do we research steal the macOS PRT cookies? 64 00:05:36,970 --> 00:05:44,050 Today many organizations rely on Intune as their end-to-end solution for both Windows and macOS. 65 00:05:44,370 --> 00:05:52,530 And with conditional access now extending to the macOS part, zero trust policy is no longer just a Windows story. 66 00:05:53,170 --> 00:05:54,550 But here's the thing. 67 00:05:54,550 --> 00:05:58,110 Most research and detection still focus on the Windows. 68 00:05:58,230 --> 00:06:02,150 And macOS on the other hand remains largely unsolved. 69 00:06:02,390 --> 00:06:09,630 And of course Dirk Jong and Olaf's research on macOS was a huge inspiration for us and gave us a solid starting point. 70 00:06:09,670 --> 00:06:17,590 From there we decided to dive deeper into how macOS handles the PRT cookies and more importantly where the weaknesses are. 71 00:06:19,390 --> 00:06:27,810 So if we want to steal the macOS PRT cookie, we must enroll our macOS device into Entral ID first. 72 00:06:28,130 --> 00:06:36,510 And according to the Microsoft documentation we can see that it needs us to download and use this company portal app. 73 00:06:37,710 --> 00:06:40,390 And the company portal app has two main parts. 74 00:06:40,570 --> 00:06:44,950 On the left you can see it's interrelated part for device management. 75 00:06:45,190 --> 00:06:48,610 But what we really care about here is on the right. 76 00:06:48,610 --> 00:06:52,990 This is where even like the macOS apps and even Safari go through. 77 00:06:52,990 --> 00:06:55,050 It's SSL extension for it. 78 00:06:55,470 --> 00:06:58,310 You need to do the single sign thing to the Entral ID. 79 00:06:59,110 --> 00:07:05,590 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. 80 00:07:09,240 --> 00:07:15,100 And now let me put out some components that are related to the SSL part in the company portal. 81 00:07:15,760 --> 00:07:24,100 There are two main plugins and one is the SSL extension what we mentioned earlier and it used to be called platform SSL extension. 82 00:07:24,820 --> 00:07:29,400 And the other one start with the autofill which we are not going to cover today. 83 00:07:29,400 --> 00:07:36,740 Also we can see there is a framework under the SSL extension called the authentication broker macOS. 84 00:07:37,160 --> 00:07:43,720 And this is the library most of performing more for the color validation checks. 85 00:07:44,320 --> 00:07:49,920 And a framework on the macOS is kind of like DL on the Windows. 86 00:07:49,920 --> 00:07:55,820 Both provide libraries but a framework on the macOS contains more bundle resources. 87 00:07:56,360 --> 00:07:59,000 But it's pretty much the same concept though. 88 00:08:00,040 --> 00:08:04,740 Also at the same time we can see there is browser core under the resources folder. 89 00:08:04,740 --> 00:08:08,860 Which also appear earlier in the Windows SSL floor. 90 00:08:10,500 --> 00:08:19,680 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. 91 00:08:20,360 --> 00:08:25,900 So as we saw that company portal also has this app is cross core. 92 00:08:25,900 --> 00:08:32,740 We immediately suspect it might serve a similar purpose for handling SSL requests on the macOS as well. 93 00:08:34,460 --> 00:08:42,760 So to help visualize the comparison I put together the macOS diagram from the Windows one. 94 00:08:42,880 --> 00:08:47,980 We can see that Apple provide app SSL agent to do the SSL part. 95 00:08:48,020 --> 00:08:50,360 Handle requests from different vendors. 96 00:08:50,660 --> 00:08:53,120 But this diagram is a little simplifier. 97 00:08:53,120 --> 00:08:58,640 Actually it has authentication framework to offer API and do the front end part. 98 00:08:58,680 --> 00:09:01,700 And the app SSL agent is just doing the back end part. 99 00:09:01,700 --> 00:09:04,040 But it's easier to understand that. 100 00:09:04,860 --> 00:09:07,180 And macOS doesn't have LSS. 101 00:09:07,180 --> 00:09:14,460 So the component responsible for computing the final PID cookie is the SSL extension under the company portal. 102 00:09:15,640 --> 00:09:24,920 And any request passed into the company portal will go through its ID authentication framework to do the color validation checks. 103 00:09:26,900 --> 00:09:34,800 And after we have the basic understanding of the macOS ecosystem, now we have let's summarize what we have found. 104 00:09:34,960 --> 00:09:39,880 Totally we found three methods to fill the macOS PID cookie. 105 00:09:40,640 --> 00:09:44,560 Next I will get through each of them and explain how they work. 106 00:09:45,500 --> 00:09:49,220 The first one is head browser pass method. 107 00:09:49,660 --> 00:09:58,020 The first one is pretty straight forward but Microsoft provide us this extension called Microsoft SSL Chrome extension. 108 00:09:58,220 --> 00:10:03,660 And we can just initiate an SSL request and directly retrieve the output there. 109 00:10:03,660 --> 00:10:16,800 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. 110 00:10:17,640 --> 00:10:27,500 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. 111 00:10:29,620 --> 00:10:37,220 But this method does come with some limitations is that we need the victim to be logging into their desktop session. 112 00:10:37,300 --> 00:10:41,000 Because headless browser doesn't mean there's no GUI dependencies. 113 00:10:41,240 --> 00:10:45,440 It's more like a transparent browser running in the background. 114 00:10:45,520 --> 00:10:49,680 So we need it to log in their session. 115 00:10:49,740 --> 00:10:57,540 And also there's also another limitation is that this technique only works with official Chrome and Microsoft Edge. 116 00:10:58,080 --> 00:11:00,840 And we'll know why when we get to the third method. 117 00:11:01,980 --> 00:11:11,600 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. 118 00:11:12,040 --> 00:11:14,880 Next we'll move to the second one. 119 00:11:16,380 --> 00:11:19,000 The bypass browser core's parent process check. 120 00:11:19,840 --> 00:11:34,700 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. 121 00:11:35,280 --> 00:11:46,840 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. 122 00:11:47,540 --> 00:11:54,380 Also when it has this two value, it will concatenate it and hash it and check against internal wireless. 123 00:11:55,040 --> 00:12:05,420 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. 124 00:12:05,420 --> 00:12:11,500 So later in our POC, you will see that we package the whole script into a direct process. 125 00:12:13,780 --> 00:12:20,720 And here you might find some terms that I'm familiar with, which is team ID and the bundle ID. 126 00:12:21,520 --> 00:12:23,300 And let me explain them quickly. 127 00:12:23,300 --> 00:12:29,460 The team ID is the identifier included in the certificate issued by Apple to each developer. 128 00:12:29,540 --> 00:12:35,840 So only the developer owns the certificate can sign the app with their own team ID. 129 00:12:36,180 --> 00:12:40,620 But bundle ID on the other hand is just a string for identification. 130 00:12:40,680 --> 00:12:42,840 It has no real security value. 131 00:12:42,840 --> 00:12:45,320 So we can change it to whatever we want. 132 00:12:45,940 --> 00:12:50,620 In short, attacker can affect the bundle ID but team ID doesn't. 133 00:12:51,500 --> 00:12:57,620 Also we can found that there are some similar mechanism on the Windows 4. 134 00:12:57,620 --> 00:13:01,720 It's called security identifier or somebody call it SID. 135 00:13:02,260 --> 00:13:11,140 In this flow we can see that security identifier is more like a bundle ID is just for identification. 136 00:13:11,160 --> 00:13:14,680 So we can also change it to whatever we want. 137 00:13:15,140 --> 00:13:22,640 And this is interesting because that Microsoft never implement something like the team ID on their operating system. 138 00:13:22,640 --> 00:13:27,080 So they check this security identifier is a bit pointless. 139 00:13:28,940 --> 00:13:36,600 And also we found that this SSL flow involves a lot of components and that means a lot of coders. 140 00:13:36,600 --> 00:13:40,000 And more coders means more coder validation checks. 141 00:13:40,000 --> 00:13:44,940 So let me clear things up and focus on the most two important one. 142 00:13:44,940 --> 00:13:47,780 The first one is the coder of the browser core. 143 00:13:48,000 --> 00:13:51,260 And of course as the name suggests is the browser. 144 00:13:51,260 --> 00:13:55,780 And in this case it can be the Google Chrome or Microsoft Edge. 145 00:13:56,420 --> 00:14:01,040 And also it is the parent in the parent process check in our earlier talk. 146 00:14:02,280 --> 00:14:08,420 And this is what we have mentioned about here in the diagram. 147 00:14:08,420 --> 00:14:12,320 This is the part like the Google Chrome call into the browser core. 148 00:14:14,020 --> 00:14:16,840 So let me read off the attack strategy. 149 00:14:16,840 --> 00:14:24,640 First we create a parallel binary and second we have a fake call site and put it in the slash TMP directly. 150 00:14:24,640 --> 00:14:30,180 And we have it use the binary ID for Google Chrome and the team ID. 151 00:14:30,520 --> 00:14:41,020 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. 152 00:14:41,700 --> 00:14:50,000 And here's the real problem is that browser core runs this call site HDB function just without the absolute pass. 153 00:14:50,000 --> 00:14:58,260 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. 154 00:15:00,200 --> 00:15:02,680 And here's the screen shot of our POC. 155 00:15:02,840 --> 00:15:09,000 And this execution is clients and so running it, showing the video will be kind of funny. 156 00:15:09,080 --> 00:15:12,560 But we will release this tool at the end of our talk. 157 00:15:14,360 --> 00:15:18,540 And here's let me share some little funny story here. 158 00:15:19,480 --> 00:15:27,720 At first, when we try to do the second method, we first do the pass to browser core. 159 00:15:27,720 --> 00:15:32,180 And when we run it from the terminal, we found it running an error. 160 00:15:32,480 --> 00:15:34,400 Caller is not allowed to invoke. 161 00:15:34,400 --> 00:15:36,680 With an error call, it's minus 6,000. 162 00:15:37,200 --> 00:15:41,620 So we decided to use the LDB to dynamic debug it. 163 00:15:42,160 --> 00:15:46,120 And to our surprise, we just get the PID cookie right here. 164 00:15:46,120 --> 00:15:50,000 So that led us to dig into what happened behind the scenes. 165 00:15:50,960 --> 00:15:57,500 And from the logs, we can see that in the fail run, it can't retrieve the bundle ID and team ID. 166 00:15:58,140 --> 00:16:03,320 And the component responsible for this function is app SSL agent. 167 00:16:03,420 --> 00:16:19,640 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. 168 00:16:19,920 --> 00:16:28,640 So this explain everything because earlier when we patched the browser core, the CS value flake became false. 169 00:16:28,640 --> 00:16:33,160 And when we attach it with the LDB, the CS debug flake was true. 170 00:16:36,600 --> 00:16:42,940 Somebody will think that maybe LDB can be one of our method to get the PID cookie. 171 00:16:42,940 --> 00:16:45,680 But actually, we think about that too. 172 00:16:45,680 --> 00:16:56,280 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. 173 00:16:56,820 --> 00:17:02,420 So if we want to use it with LDB, we must need some extra privilege escalation. 174 00:17:02,580 --> 00:17:07,340 So we want to try find some method just in the browser core to get the user privilege. 175 00:17:09,020 --> 00:17:10,880 And here come the second caller. 176 00:17:10,880 --> 00:17:13,660 It's called caller of the app SSL agent. 177 00:17:13,680 --> 00:17:15,640 And in this case, it's browser core. 178 00:17:15,640 --> 00:17:19,380 Also, it can be other vendors helper tool. 179 00:17:20,040 --> 00:17:31,400 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. 180 00:17:32,250 --> 00:17:34,700 And this is why we are talking right now. 181 00:17:34,700 --> 00:17:39,640 Is the browser core calling to the app SSL agent part here. 182 00:17:40,800 --> 00:17:48,800 So to wrap up the second method, this method can run without any dependency and also it can run in the user privilege. 183 00:17:50,420 --> 00:18:02,020 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. 184 00:18:03,740 --> 00:18:08,220 Actually, we found that there are four paths for the SSL. 185 00:18:08,380 --> 00:18:10,800 And that lead us to the third method. 186 00:18:12,400 --> 00:18:15,540 Direct SSL invocation via the Apple's API. 187 00:18:16,720 --> 00:18:21,100 And this SSL method, the first one is browser native message. 188 00:18:21,100 --> 00:18:23,740 This is the same route of the browser core. 189 00:18:23,940 --> 00:18:27,120 And the second one is passkey credential operation. 190 00:18:27,320 --> 00:18:32,420 And this two method checks bundle ID and the team ID. 191 00:18:32,420 --> 00:18:34,760 So there's no problem with that. 192 00:18:34,900 --> 00:18:39,320 But the problem is there are two paths not check the team ID at all. 193 00:18:39,320 --> 00:18:42,000 Is the general SSL extension request. 194 00:18:42,000 --> 00:18:49,120 This is mainly used by the Microsoft apps like the PowerPoint, Outlook, Teams, Excel, something like that. 195 00:18:49,220 --> 00:18:56,220 And there are also cookie SSL acquisition is for the third party apps like the Firefox or the Opera. 196 00:18:57,540 --> 00:19:04,320 And like the cookie SSL one, it also, this bundle ID is content for three subsets. 197 00:19:04,380 --> 00:19:10,740 It's like edge bundle IDs, third party browser bundle IDs, non-native browser bundle IDs. 198 00:19:10,740 --> 00:19:13,600 Totally there are 39 bundle IDs. 199 00:19:13,720 --> 00:19:19,920 And if it only checks the bundle IDs, what we need to do here is only pick anything we like. 200 00:19:20,760 --> 00:19:24,040 And just like that, we can also get a PID cookie right here. 201 00:19:24,340 --> 00:19:29,380 And this tool will also like the second one releasing at the end of our talk. 202 00:19:30,660 --> 00:19:38,900 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. 203 00:19:40,920 --> 00:19:47,820 So here in my session, I'm successfully make the PID cookie thief into a reality. 204 00:19:47,960 --> 00:19:49,740 But here's some problem. 205 00:19:51,700 --> 00:19:55,820 PID cookies only survives for about 15 minute-ish. 206 00:19:55,980 --> 00:19:59,900 And how can we achieve persistence and keep the attack going? 207 00:20:03,140 --> 00:20:05,840 So, how can we achieve persistence? 208 00:20:06,380 --> 00:20:10,940 Before we started, allow me to first introduce myself. 209 00:20:10,940 --> 00:20:12,240 My name is Echo. 210 00:20:12,240 --> 00:20:14,860 I'm also a cloud security researcher at Sidecraft. 211 00:20:14,860 --> 00:20:22,000 I have presented in multiple security conferences, such as RootCon and FIRST, and most of my research focus on cloud security. 212 00:20:22,760 --> 00:20:26,140 So back to our subject, why do we need persistence? 213 00:20:26,320 --> 00:20:30,820 As Kazuma said, PRT cookie is only valid for a few minutes. 214 00:20:30,820 --> 00:20:45,000 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. 215 00:20:45,000 --> 00:20:47,100 So how do we achieve persistence? 216 00:20:47,100 --> 00:20:50,560 A general solution is to abuse the device during scenarios. 217 00:20:51,100 --> 00:21:01,740 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. 218 00:21:01,740 --> 00:21:10,400 However, by registering a new device, we cannot only achieve persistence, we could also bypass some conditional access policies. 219 00:21:10,540 --> 00:21:25,900 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. 220 00:21:26,600 --> 00:21:30,920 And as I just said, we also want to bypass conditional access policy. 221 00:21:30,920 --> 00:21:35,520 And the most common conditional access policy is to require multi-factor authentication. 222 00:21:36,340 --> 00:21:42,660 However, token issued through passwordless authentication also contain the MFA claim. 223 00:21:42,840 --> 00:21:55,200 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. 224 00:21:55,200 --> 00:22:06,860 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. 225 00:22:07,420 --> 00:22:20,420 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. 226 00:22:20,420 --> 00:22:26,200 And to have an access token with NGC MFA claim, you have to pass the MFA authentication again. 227 00:22:26,440 --> 00:22:32,540 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. 228 00:22:32,540 --> 00:22:51,740 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. 229 00:22:52,980 --> 00:22:58,700 And another common conditional access policy is required device to be marked as compliant. 230 00:22:58,780 --> 00:23:03,860 And this could be achieved by PyTune that is released last year in Black Hat Europe. 231 00:23:04,520 --> 00:23:07,920 And however, PyTune does not support macOS for now. 232 00:23:09,140 --> 00:23:12,360 Okay, so here is our persistent flows. 233 00:23:12,360 --> 00:23:23,380 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. 234 00:23:23,700 --> 00:23:28,740 And the step three and step five can be done by Duracron's rule tool. 235 00:23:28,800 --> 00:23:31,740 And the step for device compliance can be done by a U.S. 236 00:23:31,740 --> 00:23:33,580 Trudeau's project, PyTune. 237 00:23:33,780 --> 00:23:47,740 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. 238 00:23:47,920 --> 00:23:55,700 And this problem does not exist in the past, since Microsoft fixed them all. 239 00:23:55,780 --> 00:24:04,300 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. 240 00:24:04,660 --> 00:24:15,220 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. 241 00:24:16,120 --> 00:24:20,300 So how do we get a token without device ID? 242 00:24:20,460 --> 00:24:29,900 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. 243 00:24:30,740 --> 00:24:40,100 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. 244 00:24:41,220 --> 00:24:46,700 And so, a common technique to get a token without device ID is through phishing. 245 00:24:47,120 --> 00:24:51,480 And the upside of phishing is that it does not require compromising a device. 246 00:24:51,860 --> 00:24:55,120 It just needs to convince the user to enter their credential. 247 00:24:55,600 --> 00:24:59,100 And the downside of it is that phishing is unreliable. 248 00:24:59,100 --> 00:25:09,140 So since in our scenario, we would already compromise a device, we suggest another approach, which is abusing Kerbal's Simply Single Sign-On. 249 00:25:09,140 --> 00:25:12,580 The upside of it is that it keeps the noise level low. 250 00:25:12,580 --> 00:25:16,520 You don't need to unmodify with the authentication methods. 251 00:25:16,520 --> 00:25:20,400 You just need a service ticket in exchange for an SS token. 252 00:25:20,460 --> 00:25:26,020 And the downside of it is that only less than 25% of tenants have this setting enabled. 253 00:25:26,020 --> 00:25:30,640 And it can only abuse on a Windows system that is hybrid joined . 254 00:25:30,640 --> 00:25:35,060 So we start thinking that, could we just simply reset the victim's password? 255 00:25:35,100 --> 00:25:36,940 And the downside of it is obvious. 256 00:25:36,940 --> 00:25:41,740 It could use across all operating systems, regardless of its joint type. 257 00:25:41,740 --> 00:25:45,880 And the downside of it is that resetting the password may trigger some alerts. 258 00:25:46,020 --> 00:25:52,860 But the biggest problem here is that, could we reset the password without knowing the current one? 259 00:25:53,020 --> 00:26:04,820 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. 260 00:26:04,820 --> 00:26:09,160 And in this case, we will call the API, API password reset. 261 00:26:09,160 --> 00:26:15,100 However, if we log in with passwordless authentication, it only contains MFA claim. 262 00:26:15,100 --> 00:26:21,460 So we have to enter the current password since we don't have the password claim in our SS token. 263 00:26:21,460 --> 00:26:25,600 And in this case, it will call the API password change. 264 00:26:25,600 --> 00:26:29,600 So of course, as adversary, we tend to abuse API password reset. 265 00:26:29,600 --> 00:26:37,280 But it seems this abuse is limited to password authentication user, not passwordless authentication user. 266 00:26:37,280 --> 00:26:39,320 But this is not true. 267 00:26:40,120 --> 00:26:47,200 And we found out there is inconsistent logic between the front-end and back-end logic of the MySign service. 268 00:26:47,340 --> 00:26:51,600 Actually, calling API password reset only requires the MFA claim. 269 00:26:51,600 --> 00:26:53,680 The password claim is not required. 270 00:26:53,680 --> 00:27:00,320 So we could also reset a password on passwordless authentication user without knowing their current password. 271 00:27:01,020 --> 00:27:11,820 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. 272 00:27:11,820 --> 00:27:14,660 So we can always reset user's password. 273 00:27:15,760 --> 00:27:22,980 And our last approach is adding a passkey in Microsoft Authenticator or your mobile device. 274 00:27:22,980 --> 00:27:26,080 And the upside of it, it keeps the noise level low. 275 00:27:26,080 --> 00:27:30,420 You add a new authentication method without modifying the old one. 276 00:27:30,480 --> 00:27:37,540 And since passkey is a passwordless authentication via FIDO, you also get a token with MFA claim. 277 00:27:37,540 --> 00:27:49,360 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. 278 00:27:50,780 --> 00:28:00,780 And however you may consider that adding a passkey is some sort of MFA bypass, well, it's not entirely correct. 279 00:28:00,780 --> 00:28:06,100 But it's not easy to get an SS token with an MFA claim. 280 00:28:06,100 --> 00:28:08,300 Is there something that I didn't mention? 281 00:28:08,300 --> 00:28:09,860 Other requirements? 282 00:28:09,980 --> 00:28:15,120 Let's talk about how do we find a way to re-authenticate via multi-factor authentication. 283 00:28:15,840 --> 00:28:23,860 So, as we said, general solution, if we try to reset the password, we have to know the current password. 284 00:28:23,860 --> 00:28:28,860 But we know in the last NASDAQ, Microsoft kind of like threw up. 285 00:28:28,860 --> 00:28:38,320 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. 286 00:28:39,500 --> 00:28:54,880 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. 287 00:28:54,880 --> 00:29:05,500 And that makes the NGC MFA protection useless, since a hacker can register their own MFA to bypass the NGC MFA protection. 288 00:29:05,940 --> 00:29:10,340 So, the NGC MFA protection is a good idea. 289 00:29:10,340 --> 00:29:16,320 However, its actual implement is flawed, just like this French fries in the door. 290 00:29:17,760 --> 00:29:25,360 So, interesting thing is we report to Microsoft with a title, MFA bypass. 291 00:29:25,360 --> 00:29:35,460 And the response is that they determine this is not a vulnerability and claim that MFA bypass is a hyperhole. 292 00:29:35,460 --> 00:29:42,440 We agree with them, since we have to have a PRT cookie with a cache MFA status. 293 00:29:42,440 --> 00:29:45,180 However, this is not an MFA bypass. 294 00:29:45,180 --> 00:29:51,500 Actually, this is a next generation credential MFA bypass, which makes it sound even worse. 295 00:29:52,980 --> 00:30:02,880 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. 296 00:30:02,880 --> 00:30:12,020 However, if we multiply the authentication info first and then register a new device, Microsoft seems to be okay with it. 297 00:30:12,020 --> 00:30:16,700 So, we think it's unreasonable, but we accept the result. 298 00:30:17,100 --> 00:30:26,860 However, Microsoft changed their mind in like July 30, and after we provide them with our slide with this picture on it. 299 00:30:26,860 --> 00:30:37,980 So, they determined that they have to provide stronger authentication in the future, such as fresh MFA to better protect Microsoft's service. 300 00:30:38,780 --> 00:30:42,840 And John will talk about the detail first, but I will rather show you the demo. 301 00:30:45,930 --> 00:30:47,570 So, okay. 302 00:30:48,250 --> 00:30:50,330 Here is our attachment. 303 00:30:50,330 --> 00:30:57,070 We'll first request a PRT cookie directly to a single sign invocation by an Apple API. 304 00:30:57,310 --> 00:31:00,810 And then, we'll abuse a device join scenario. 305 00:31:00,810 --> 00:31:09,310 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. 306 00:31:09,570 --> 00:31:15,910 And we skip the device compliance part to shorten the demo. 307 00:31:16,030 --> 00:31:21,430 And if the device registration requires multi-factor authentication, you just need to switch the step. 308 00:31:21,530 --> 00:31:25,770 Just add MFA before we register the fake device. 309 00:31:25,970 --> 00:31:28,030 So, here is our demo. 310 00:31:29,670 --> 00:31:38,720 First, we need to check our compliance policy or conditional access policy. 311 00:31:38,720 --> 00:31:46,260 It requires our user to pass multi-factor authentication to access to our target resource. 312 00:31:46,260 --> 00:31:50,900 Then, we are looking at the victim's device, which is a Mac OS system. 313 00:31:52,920 --> 00:31:56,020 And we know our victim's name is called Adele. 314 00:31:56,280 --> 00:31:59,540 And we request for a PRT cookie. 315 00:31:59,580 --> 00:32:05,620 And then we pass the PRT cookie from Mac OS to our attacker's machine. 316 00:32:05,680 --> 00:32:08,680 And we exchange for a MySignService token. 317 00:32:09,200 --> 00:32:15,960 And since we don't know the victim's password, we need to reset it to have a new one. 318 00:32:16,840 --> 00:32:22,940 Now, we try to call the API password reset to get a new password. 319 00:32:27,720 --> 00:32:30,700 Now, the password is reset successfully. 320 00:32:39,310 --> 00:32:45,510 Then, we can register our new device with our new password. 321 00:32:45,730 --> 00:32:47,730 And that is successfully. 322 00:32:47,730 --> 00:32:53,670 So, we try to log into Office 365 with our new password and our username. 323 00:33:03,200 --> 00:33:06,140 And now we are blocked by the multi-factor authentication. 324 00:33:06,280 --> 00:33:12,360 So, we try to the PRT cookie again and add a new multi-factor authentication. 325 00:33:16,600 --> 00:33:20,200 And this time, we'll not done by direct API call. 326 00:33:20,200 --> 00:33:25,180 We will open up the browser so that it's more easy to understand. 327 00:33:26,960 --> 00:33:27,700 Okay. 328 00:33:27,700 --> 00:33:34,200 We log into the MySignService website and try to add a new MFA. 329 00:33:35,340 --> 00:33:36,620 Okay. 330 00:33:39,040 --> 00:33:44,980 And in this process, we'll try to add our TOTP key into the key pass. 331 00:33:46,580 --> 00:33:49,600 And Microsoft will ask us to verify it again. 332 00:33:58,520 --> 00:33:59,180 Okay. 333 00:33:59,180 --> 00:34:06,000 Now, we successfully add our new MFA without prompting down another authentication. 334 00:34:06,700 --> 00:34:12,320 Now, we'll try to register our new Windows Hello for Business key. 335 00:34:12,940 --> 00:34:15,480 But we need a token with NGC MFA claim. 336 00:34:15,480 --> 00:34:20,020 So, we need to pass the MFA again and check our access token. 337 00:34:20,040 --> 00:34:23,420 It actually contains NGC MFA claim. 338 00:34:24,700 --> 00:34:25,300 Yeah. 339 00:34:29,220 --> 00:34:29,860 Okay. 340 00:34:29,860 --> 00:34:37,980 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. 341 00:34:37,980 --> 00:34:42,640 Now, we successfully log into the Office 365 and bypass the multi-factor authentication. 342 00:34:42,640 --> 00:34:45,620 And finally, we check our authentication method. 343 00:34:46,740 --> 00:34:52,900 And we register a new Windows Hello for Business key on our demo machine, which does not physically exist. 344 00:34:53,460 --> 00:34:56,980 And this is all for our demo. 345 00:34:59,340 --> 00:35:00,340 Okay. 346 00:35:00,560 --> 00:35:04,020 And if you like it, feel free to give us some applause. 347 00:35:04,020 --> 00:35:04,460 Thank you. 348 00:35:11,110 --> 00:35:12,030 Okay. 349 00:35:12,030 --> 00:35:13,990 Thanks for the demonstration. 350 00:35:14,010 --> 00:35:15,970 So, let me review what I just saw. 351 00:35:15,970 --> 00:35:24,310 In this demonstration, actually we got a PRT and a very strong MFA just like Microsoft say, they love the Windows Hello for Business. 352 00:35:24,350 --> 00:35:26,130 So, you have a strong MFA. 353 00:35:26,130 --> 00:35:30,870 And all this element is coming from the fake device. 354 00:35:32,290 --> 00:35:41,250 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. 355 00:35:41,250 --> 00:35:49,390 This is a talk in this year in Troopers has mentioned about how to let them run movement in NHID joint device . 356 00:35:49,390 --> 00:35:58,750 By default setting, global administrator and device owner are local admin in NHID joint device. 357 00:35:58,750 --> 00:36:06,670 So, you can use the PRT, exchange it to the P2P certificate and the login in NHID joint device. 358 00:36:09,780 --> 00:36:14,760 You just saw a demo and you might think if you are familiar with the condition as a policy . 359 00:36:14,800 --> 00:36:22,380 You might think, hey, why require the MFA for joint device and I require MFA for update their security information. 360 00:36:22,720 --> 00:36:28,440 Actually it's not enough and you might encounter some deadlock problem in this scenario. 361 00:36:28,440 --> 00:36:36,080 I just share with my friend this tech master and he just apply this condition as policy and he encounter some problem. 362 00:36:37,220 --> 00:36:43,400 If you have new employee on boarding, you just give them your password and the account name. 363 00:36:43,400 --> 00:36:44,700 They just log in. 364 00:36:44,700 --> 00:36:46,440 The first time log in, they don't have MFA. 365 00:36:46,440 --> 00:36:51,960 NHID asking, hey, you need the MFA, but you have to pass MFA first. 366 00:36:52,140 --> 00:36:53,660 So, they encounter some problem. 367 00:36:53,660 --> 00:36:56,320 The new employee cannot add their own MFA. 368 00:36:56,440 --> 00:37:01,420 So, only way to escape out is on the documentation for the Microsoft. 369 00:37:01,420 --> 00:37:04,800 You need to log in with the tab for the initial login. 370 00:37:04,800 --> 00:37:08,080 This is the only way to escape out in this deadlock situation. 371 00:37:10,340 --> 00:37:14,680 If you apply this condition as policy, actually it's not enough. 372 00:37:14,780 --> 00:37:23,060 Just in case you didn't film the video, yeah, so I prepare a diagram for the easy to understand whole attack pass. 373 00:37:23,060 --> 00:37:26,780 We assume we have a compromise in tune or window hollow for business device. 374 00:37:26,780 --> 00:37:29,660 We extract the PRT cookie with MFA. 375 00:37:30,520 --> 00:37:33,700 And then we have a two thing need to do. 376 00:37:33,700 --> 00:37:35,520 First, add a new MFA. 377 00:37:35,640 --> 00:37:42,420 The conditional access require us need to pass MFA first and add in the new MFA. 378 00:37:42,680 --> 00:37:47,440 But we already have MFA client, so we can easily satisfy this policy check. 379 00:37:47,660 --> 00:37:52,040 And on the reset password, we just want to add on the fake device. 380 00:37:52,080 --> 00:37:57,600 So, we can change the user password without we know, we don't know the current password. 381 00:37:58,260 --> 00:38:02,020 It's a UI inconsistency in front end and back end. 382 00:38:03,880 --> 00:38:09,000 We are easy to get the new MFA and control the user password. 383 00:38:09,000 --> 00:38:11,340 And now we can persistence in Android ID. 384 00:38:11,340 --> 00:38:12,880 We can reduce a new device. 385 00:38:12,880 --> 00:38:17,620 And then you need, we're trying to reduce device user require MFA. 386 00:38:17,620 --> 00:38:22,700 But we already add our own MFA, so we can easily satisfy this policy check too. 387 00:38:23,720 --> 00:38:27,920 And then we can upgrade our fake device to windows hollow for business. 388 00:38:27,920 --> 00:38:30,980 We can easily authenticate MFA in five minutes. 389 00:38:31,220 --> 00:38:33,600 And then persistence in Android ID. 390 00:38:35,120 --> 00:38:37,540 How Microsoft response us our finding? 391 00:38:37,540 --> 00:38:38,860 This is very interesting. 392 00:38:39,060 --> 00:38:43,220 Because Microsoft for the Mac OS they already fix. 393 00:38:43,220 --> 00:38:45,160 But for the windows side, they never fix this. 394 00:38:45,160 --> 00:38:47,840 It still can get the PRT cookie on windows. 395 00:38:47,840 --> 00:38:50,360 But now it's not on the Mac OS. 396 00:38:51,060 --> 00:38:58,740 And for the Android ID persistence method, the first time the response, you have to compromise someone windows. 397 00:38:58,740 --> 00:39:00,500 Maybe very hard, right? 398 00:39:01,140 --> 00:39:08,380 So, just one week ago, they know we are speaking at DEF CON, they decide to fix it. 399 00:39:08,380 --> 00:39:12,580 Maybe one month or one week later, they will fix it. 400 00:39:13,340 --> 00:39:17,300 They also have a recommendation for the make a cookie PRT safe. 401 00:39:17,300 --> 00:39:18,480 Just update. 402 00:39:18,640 --> 00:39:24,060 If you cannot update yet, you can just monitor following criteria, like a call sign. 403 00:39:24,060 --> 00:39:27,160 It should be always running on the user bin folder. 404 00:39:27,480 --> 00:39:29,500 And monitor the header browser. 405 00:39:29,660 --> 00:39:39,400 If there is a binary, has a bundle ID we mentioned today, but there is a binary don't have enough, just trigger the. 406 00:39:39,400 --> 00:39:46,280 Also, even Microsoft implement this update, but you should check your Intune's policy. 407 00:39:46,280 --> 00:39:50,620 Because if you want some bundle ID, you still encounter some problem. 408 00:39:50,980 --> 00:39:56,080 You still possibly get the PRT cookie safe on your Mac OS system. 409 00:39:59,260 --> 00:40:00,800 And here is a summary. 410 00:40:00,880 --> 00:40:04,980 We found that the PRT cookie safe on Mac OS is now a reality. 411 00:40:05,180 --> 00:40:12,360 And we've also noticed other vendors, not just Microsoft, other vendors have implemented the SSO extension on Mac OS. 412 00:40:12,360 --> 00:40:14,900 We think there might be a similar problem. 413 00:40:15,920 --> 00:40:22,620 You are a Mac OS developer, you should choose a team ID, not a bundle ID to verify the binary. 414 00:40:23,660 --> 00:40:30,460 And before Microsoft already implement the patch, just pray for your end point never being compromised. 415 00:40:30,920 --> 00:40:35,420 And here is some mitigation for the persistent method. 416 00:40:35,940 --> 00:40:39,960 You can create a weak criteria from the condition as a policy. 417 00:40:39,960 --> 00:40:48,960 Like the IP location, user agent, just make the attacker very hard to add a new device or add a new MFA. 418 00:40:49,020 --> 00:40:53,600 And then monitor the new joint device and then add a new MFA. 419 00:40:53,600 --> 00:40:59,240 If you have an employee add a new device, you can trigger alert, but it's kind of annoying. 420 00:40:59,420 --> 00:40:59,860 Yeah. 421 00:41:00,760 --> 00:41:01,720 And thanks. 422 00:41:01,720 --> 00:41:03,200 And here is our cool release. 423 00:41:03,200 --> 00:41:06,020 You can check on this for Mac OS cookie safe. 424 00:41:06,020 --> 00:41:07,020 And thank you.