1 00:00:00,000 --> 00:00:05,800 We have Dirk Jain here to talk about Active Directory and Entra ID Exploitation. 2 00:00:05,840 --> 00:00:07,260 Super excited for this talk. 3 00:00:07,260 --> 00:00:09,540 So everybody help me welcome him to the stage. 4 00:00:09,540 --> 00:00:10,260 Yeah! 5 00:00:16,460 --> 00:00:18,460 Hello, good afternoon everybody. 6 00:00:18,920 --> 00:00:20,000 Thanks for coming out. 7 00:00:20,000 --> 00:00:21,320 It's a full house. 8 00:00:21,420 --> 00:00:25,180 I'm gonna start my presentation by apologizing for two things. 9 00:00:25,180 --> 00:00:29,380 First of all, because my slides are in light mode and it seems kind of bright out there. 10 00:00:29,380 --> 00:00:33,380 So if your eyes hurt at the end of this talk, I'm sorry for that. 11 00:00:33,440 --> 00:00:36,700 The second thing is that the talk is called Advanced. 12 00:00:36,700 --> 00:00:50,620 So that's gonna be my excuse to go over the basics like really, really quick because there's a lot of information in this talk and I don't have time to talk about everything because otherwise I'd be standing here for two hours and you have other things to do today. 13 00:00:50,620 --> 00:00:56,640 So we're gonna go through things fast and then we hopefully get to the interesting stuff as soon as we can. 14 00:00:57,440 --> 00:00:58,840 So I'm Dirk Jain. 15 00:00:58,840 --> 00:00:59,980 Thanks for coming out. 16 00:00:59,980 --> 00:01:02,480 I am all the way from the Netherlands. 17 00:01:02,680 --> 00:01:04,900 In my day job I have my own company. 18 00:01:04,900 --> 00:01:11,440 It's called Outsider Security and there I do a bit of a combination of research, pen testing and a lot of training. 19 00:01:11,860 --> 00:01:13,380 Maybe you've seen me here before. 20 00:01:13,380 --> 00:01:18,320 It's actually my third DEF CON and I like to do research. 21 00:01:18,320 --> 00:01:19,700 I like to write tools. 22 00:01:19,820 --> 00:01:21,680 But I don't want to talk about this today. 23 00:01:21,680 --> 00:01:26,620 I actually want to talk about lateral movement from Active Directory to Entra. 24 00:01:26,840 --> 00:01:35,900 And if you want to talk about that, we need to cover a little bit of the existing attacks because some of the existing attacks will actually make a comeback later in the talk. 25 00:01:36,120 --> 00:01:39,880 But the thing I am really excited to talk about are two things. 26 00:01:40,260 --> 00:01:42,700 Policies and exchange. 27 00:01:42,800 --> 00:01:47,820 Now, I get that's a little vague, but we'll make sense of that later on. 28 00:01:47,820 --> 00:01:53,840 Let's start with the existing attack surface and the changes that were there over the years. 29 00:01:54,420 --> 00:02:00,660 So if we talk about hybrid attacks, it means attacks that cover both AD and Entra. 30 00:02:00,660 --> 00:02:05,400 And for this talk, the starting point is going to be full control over the on-prem Active Directory. 31 00:02:05,500 --> 00:02:07,760 So this is not about like getting domain admin. 32 00:02:07,760 --> 00:02:15,240 This is what you can do if you already have domain admin and you want to move to somebody's cloud environment from that point of view. 33 00:02:15,760 --> 00:02:17,580 So AD is fully compromised. 34 00:02:17,580 --> 00:02:21,320 We have all the access that we want and we want to pivot to Entra. 35 00:02:21,620 --> 00:02:27,880 Now there are a few attacks that you can always do and there's also a few attacks that depend on the configuration. 36 00:02:28,400 --> 00:02:33,320 So ADFS and seamless single sign-on, they're two quite well-known attacks. 37 00:02:33,320 --> 00:02:35,200 They've been covered extensively in the past. 38 00:02:35,200 --> 00:02:37,600 They've been abused by threat actors in the past. 39 00:02:37,900 --> 00:02:43,040 Basically, if you have these components, there's always going to be an attack path from your on-prem AD to Entra. 40 00:02:43,520 --> 00:02:51,740 Also, if you have Entra ID connect, which most companies have because you need that for the synchronization, there's also going to be attack paths with that. 41 00:02:52,040 --> 00:02:59,400 Now these attack paths, they exist because basically you are putting sort of a trust in a on-prem AD system. 42 00:02:59,400 --> 00:03:08,200 So if you have ADFS, then by the whole definition of the thing, you are authorizing this ADFS server on-prem to issue tokens for the cloud. 43 00:03:08,200 --> 00:03:18,540 So the way it works is that ADFS has a certificate, ADFS has a private key, Entra also has a certificate and ADFS issues SAML tokens and these SAML tokens are used to authenticate users. 44 00:03:18,920 --> 00:03:33,520 So we have this private key on-prem and with most private key schemes, if somebody manages to steal that private key and that certificate, then they can basically remove all these security layers and they can enforce their own tokens. 45 00:03:33,780 --> 00:03:39,200 This is not super complicated like concept-wise because we are trusting the system. 46 00:03:39,200 --> 00:03:45,220 If the system is compromised, then the whole hybrid environment is compromised and you can impersonate users in Entra. 47 00:03:45,800 --> 00:03:48,720 Seamless single sign-on is kind of similar actually. 48 00:03:49,060 --> 00:04:00,020 Seamless single sign-on is Kerberos based so that means that it's a different protocol than SAML and also it uses symmetric keys in this case so there's no asymmetric cryptography but actually symmetric cryptography. 49 00:04:00,460 --> 00:04:01,920 But the same thing is here. 50 00:04:02,020 --> 00:04:04,260 On-prem AD issues Kerberos tickets. 51 00:04:04,420 --> 00:04:10,260 The cloud accepts these Kerberos tickets because it has the key to validate they were issued legitimately. 52 00:04:10,600 --> 00:04:17,860 And if an attacker steals these keys, then of course they can craft their own Kerberos tickets and they can impersonate users in the cloud. 53 00:04:17,860 --> 00:04:19,540 It's called silver tickets. 54 00:04:19,600 --> 00:04:23,180 You're probably familiar with that because it's not exactly new. 55 00:04:23,200 --> 00:04:25,620 So this is already old stuff. 56 00:04:25,620 --> 00:04:38,620 However, a few important things with this is that even though these concepts are configured per domain, there's quite a difference between how domains work in on-prem AD versus how domains work in Entra. 57 00:04:38,620 --> 00:04:44,240 Because in on-prem AD we have active directory domains, they have their own structure, they're part of the forest. 58 00:04:44,580 --> 00:04:46,820 But in Entra, that doesn't really apply. 59 00:04:46,820 --> 00:04:49,860 So Entra is more of a flat structured identity provider. 60 00:04:50,100 --> 00:04:56,700 That means that all the users that you have, even if you sync users from multiple domains, they're all kind of pooled together. 61 00:04:57,360 --> 00:05:07,560 So even though Entra doesn't really have the concept of domains, we can configure some things per domain which is kind of weird because we have a configuration per domain but domains are not really a thing. 62 00:05:07,560 --> 00:05:13,380 So that leaves us in a bit of a weird place and I think that's kind of confusing. 63 00:05:13,620 --> 00:05:15,940 But it does have security consequences. 64 00:05:15,940 --> 00:05:28,800 Because there's no security boundary between individual domains in Entra, then basically it means that most of the authentication material that you have in any domain on-prem works for any domain in the cloud. 65 00:05:28,800 --> 00:05:35,860 And the only actual security difference is between synchronized accounts, so accounts that come from on-prem, and cloud only accounts. 66 00:05:35,860 --> 00:05:40,180 So people think that it works like this, like with like silos. 67 00:05:40,180 --> 00:05:43,600 So we have two domains here or we have actually quite a few domains. 68 00:05:43,600 --> 00:05:45,900 One is managed, one is federated. 69 00:05:45,960 --> 00:05:50,800 They're synced from different on-prem AD domains that don't even need to be in the same forest. 70 00:05:50,840 --> 00:05:53,480 But there's not really this difference in the cloud. 71 00:05:53,480 --> 00:06:03,840 So it's not that these domains are isolated but actually all these domains are kind of pooled together and the only actual difference is between hybrid users and cloud only users. 72 00:06:04,100 --> 00:06:15,140 So that means that if we compromise the on-prem domains here, in the case of password hashing, we can override passwords of any hybrid user, not just in this domain but actually also in any other domain. 73 00:06:15,160 --> 00:06:26,240 Same with federation, if we compromise one federation server or if you only have like one federated domain in your tenant, actually these tokens are valid for any hybrid account in any of the domains that you have. 74 00:06:26,400 --> 00:06:30,560 And the only thing that we cannot do is we cannot target cloud only users. 75 00:06:30,560 --> 00:06:38,500 So if we try to reset the password of a cloud only user, that's not going to work because cloud only users are separate from like hybrid users. 76 00:06:39,020 --> 00:06:46,360 So this is some of the existing attack service and conceptually actually these two concepts, seamless single sign-on and ADFS are quite similar. 77 00:06:46,360 --> 00:06:49,460 They both can be used to force authentication material. 78 00:06:49,460 --> 00:07:00,860 The main difference impact wise is that ADFS can also cover multi-factor authentication so you can add a MFA claim to a SAML token while seamless single sign-on is only about single factor. 79 00:07:01,060 --> 00:07:12,220 So it's 2025, hopefully you have an MFA policy and that means if you have seamless single sign-on then you would still need to bypass the MFA while with ADFS you can also bypass MFA. 80 00:07:12,220 --> 00:07:22,280 There is a setting that you can use to mitigate this, however I've almost never seen anybody enable this so in most cases if you have ADFS in the environment you can also bypass multi-factor. 81 00:07:22,360 --> 00:07:37,240 But both methods are not limited to one domain, actually they work for all of the domains in Entra and even though the authentication material is technically per domain, which is a little weird but that's just how it works because the difference is architecture wise between on-prem and the cloud. 82 00:07:37,720 --> 00:07:47,300 So if you have this, if you have seamless single sign-on, if you have ADFS, there's always going to be an attack path and you can be used to impersonate any hybrid accounts. 83 00:07:47,740 --> 00:08:05,500 So I'm going to extend this attack graph a little bit as we go through the talk and basically on the left-hand side we have Active Directory , on the right-hand side we have the Entra ID and if you have any of the components on the AD side then you can perform the following attacks in Entra. 84 00:08:05,900 --> 00:08:08,780 So seamless single sign -on, ADFS, we've covered that. 85 00:08:09,100 --> 00:08:15,260 Actually I'm going to assume that you don't have this in this talk because if you have it, there is like a by design attack path. 86 00:08:15,920 --> 00:08:19,980 And there's also quite a few attack paths that are based on Entra ID connect. 87 00:08:20,060 --> 00:08:23,160 A few of these are already known so I'm not going to cover them extensively. 88 00:08:23,380 --> 00:08:29,300 But one thing I do want to highlight is the ability to actually convert cloud only users to hybrid users. 89 00:08:29,320 --> 00:08:33,960 Because I've just told you that cloud only users are out of scope of these attacks. 90 00:08:33,960 --> 00:08:38,500 We cannot reset password of cloud only accounts or impersonate them with SAML tokens. 91 00:08:38,600 --> 00:08:44,360 But there is actually a way to kind of move a cloud only account to make it a hybrid account. 92 00:08:44,360 --> 00:08:47,640 And then we can actually do these attacks with these accounts. 93 00:08:48,060 --> 00:08:49,600 So there's a technique for that. 94 00:08:49,600 --> 00:08:51,020 It's called soft matching. 95 00:08:51,020 --> 00:08:52,980 There's a variant of that that's called hard matching. 96 00:08:53,020 --> 00:08:57,560 And it's used to work for any account back in 2018 when I first looked at this. 97 00:08:57,560 --> 00:09:06,400 And basically the way that it works is that you pretend that there's a on-prem account that's the same user principle name or the same email address as a cloud account. 98 00:09:06,400 --> 00:09:09,420 And the synchronization engine will like match those together. 99 00:09:09,440 --> 00:09:13,100 It thinks it's the same account and then suddenly it becomes a hybrid account. 100 00:09:13,100 --> 00:09:16,160 And then it becomes in scope of all of these attacks. 101 00:09:16,600 --> 00:09:23,720 So this solves this for global admins because this used to be the case you could just override the global admins password and you were a global admin. 102 00:09:24,200 --> 00:09:30,780 But then somebody else, Sapir, a different researcher, she found out that they actually never fixed this for eligible admins. 103 00:09:30,780 --> 00:09:36,720 Which is a little weird because there's this feature, privileged identity management, that you actually need to pay extra for. 104 00:09:37,200 --> 00:09:43,640 And if you have that, then apparently it's less secure because then you have eligible admins and they're not protected from this attack. 105 00:09:43,640 --> 00:09:54,620 So eligible admins, eligible global admins, you can convert them to hybrid accounts and then you can impersonate them with ADFS or with things like Golden SAML or with single sign-on. 106 00:09:54,620 --> 00:09:55,820 There's mitigation for that. 107 00:09:55,820 --> 00:09:58,460 You can block soft matching, you can block hard matching. 108 00:09:58,560 --> 00:10:03,280 Again, I've never actually seen companies do this because it's quite an obscure setting. 109 00:10:03,280 --> 00:10:06,140 But there are mitigations for this that you can run in theory. 110 00:10:07,340 --> 00:10:12,760 Anyway, if you want to do this, then you need to have access to that Entra ID connect account. 111 00:10:13,160 --> 00:10:19,160 And that means you need to have access to that server, which is not going to be a problem because we consider the on-prem AD compromised. 112 00:10:19,220 --> 00:10:24,540 And then you can dump the credentials because it was always using username password authentication. 113 00:10:24,540 --> 00:10:28,100 You can extract the plain text password from the server using several tools. 114 00:10:28,200 --> 00:10:33,860 I wrote the AD connect dump tool suite quite a couple years ago and then you have the credentials of that account. 115 00:10:34,520 --> 00:10:38,640 But maybe you're like, well, actually, we can now do this with a service principle. 116 00:10:38,760 --> 00:10:41,140 And Microsoft announced that a couple of months ago. 117 00:10:41,140 --> 00:10:42,780 And you're like, yeah, this is more secure. 118 00:10:43,280 --> 00:10:44,240 Is it though? 119 00:10:44,320 --> 00:10:48,580 Because if you have a service principle, then it uses certificates for authentication. 120 00:10:48,920 --> 00:10:52,180 But I can also just dump the certificates instead of dumping the password. 121 00:10:52,180 --> 00:10:59,080 So here I added one more tool to the tool suite, which I made open source like earlier this week, AD sync cert dump. 122 00:10:59,080 --> 00:11:00,640 And it will just dump the certificates. 123 00:11:00,640 --> 00:11:01,900 It will dump the private key. 124 00:11:01,900 --> 00:11:04,080 And with that, we can authenticate as a service principle. 125 00:11:04,080 --> 00:11:06,260 And then we can do the exact same as before. 126 00:11:06,780 --> 00:11:11,120 You're like, well, actually, we can also store these in a trusted platform module. 127 00:11:11,120 --> 00:11:13,020 And then it's actually hardware protected. 128 00:11:13,480 --> 00:11:14,500 You're again correct. 129 00:11:14,500 --> 00:11:15,260 We can do that. 130 00:11:15,260 --> 00:11:16,200 It's an option. 131 00:11:16,620 --> 00:11:23,060 But if there's a trusted platform module, then we can just very nicely ask the trusted platform module to sign something for us. 132 00:11:23,060 --> 00:11:24,900 That something is called an assertion. 133 00:11:24,900 --> 00:11:27,240 And that assertion allows us to authenticate. 134 00:11:27,240 --> 00:11:31,260 So if I ask the TPM for this assertion, it allows me to authenticate in the cloud. 135 00:11:31,260 --> 00:11:33,380 And once again, I have access to this account. 136 00:11:33,880 --> 00:11:38,540 You're like, well, actually, that does mean you need persistent access to this host, yes? 137 00:11:38,540 --> 00:11:42,080 Because it's stored in hardware and you don't have the actual private key. 138 00:11:42,820 --> 00:11:44,000 Not really. 139 00:11:44,000 --> 00:11:48,720 Because if we look at this assertion, we see that it's based on a time stamp. 140 00:11:49,100 --> 00:11:53,880 And it's basically a JSON web token that's valid for a limited amount of time. 141 00:11:54,080 --> 00:11:58,700 But of course there's no proof that this time was the actual time when I signed this. 142 00:11:58,700 --> 00:12:02,500 Because I can also sign a token for next week or next year or next month. 143 00:12:02,720 --> 00:12:06,820 So I can just sign the tokens in advance and then I can just use them whenever I want. 144 00:12:07,560 --> 00:12:14,500 Also, if we look at the documentation, it explicitly says that Entra actually doesn't care how large you make the time range. 145 00:12:14,500 --> 00:12:17,160 Because it doesn't enforce any limits on the expiry. 146 00:12:17,160 --> 00:12:22,340 So I can also just create an assertion that's valid for like a year and I can use that then whenever. 147 00:12:22,340 --> 00:12:25,140 So it's nice that it's in hardware protection. 148 00:12:25,140 --> 00:12:33,260 But hardware protection is quite useless if you can extract like a assertion from there that's just as valuable as the actual private key. 149 00:12:33,260 --> 00:12:38,540 So I don't need the key, I just need the assertion in the end and the assertion I can create that for a very long time. 150 00:12:39,000 --> 00:12:45,500 So there's not much difference in attack surface between the service principle based approach and the account based approach in that sense. 151 00:12:46,340 --> 00:12:49,500 So we can use these credentials to convert the accounts. 152 00:12:49,620 --> 00:12:55,160 And a different thing that's interesting is the ability to modify policies. 153 00:12:55,240 --> 00:12:59,680 So that's actually an attack that was documented. 154 00:12:59,680 --> 00:13:01,560 I've talked about it in the past. 155 00:13:01,560 --> 00:13:04,640 But it wasn't always clear what it actually meant. 156 00:13:04,640 --> 00:13:13,980 So if we look at the documentation, then documentation actually says that the sync account can modify policies, it can delete policies, it can change policies. 157 00:13:14,180 --> 00:13:22,660 The problem with this is that like all these permissions in Entra, they're so vague that nobody really knows what they mean, like each of these individual permissions. 158 00:13:22,940 --> 00:13:26,100 And then the question is, well, what exactly is a policy? 159 00:13:26,100 --> 00:13:28,020 Like what does a policy even mean? 160 00:13:28,020 --> 00:13:32,360 I can think of a few policies, but are these actually stored as policies? 161 00:13:32,680 --> 00:13:37,760 So let's have a look at policies in my favorite graph API. 162 00:13:38,380 --> 00:13:40,080 That is not this API. 163 00:13:40,340 --> 00:13:44,360 It's going to be this API, the graph.windows.net. 164 00:13:44,360 --> 00:13:48,740 Especially the internal version, the 1.61-internal. 165 00:13:48,740 --> 00:13:52,620 This is like the secret Microsoft version that they don't want you to know about. 166 00:13:52,940 --> 00:14:00,220 I've given some talks on that in the past, but basically this API version exposes a lot more information than all the official APIs. 167 00:14:00,420 --> 00:14:08,560 It also allows you to, for example, to enumerate more data with a normal user account that you normally can, and it just shows a lot of internal Entra data. 168 00:14:09,100 --> 00:14:13,860 Now, one of the policies that is maybe the most obvious one are conditional access policies. 169 00:14:13,860 --> 00:14:21,120 So conditional access policies are the security policies that we use to enforce all these controls in the tenant, like multi-factor authentication. 170 00:14:22,100 --> 00:14:38,020 And if you can just change these policies from on-prem, if you can just delete them from on-prem, which the sync account could do, yeah, then MFA is not really a great control anymore because we can just turn it off, or we can just add exclusions, or any other policy can be just disabled or deleted. 171 00:14:38,580 --> 00:14:40,220 So they patched this in 2023. 172 00:14:40,460 --> 00:14:43,160 Actually, I talked about this at BlueEd in 2019. 173 00:14:43,160 --> 00:14:48,420 I don't think many people actually realized this was possible, but they did fix it like a few years ago. 174 00:14:48,620 --> 00:14:55,820 And now when you try to do this, even as global admin, you get like this error message that says only confidential clients can do this, so you cannot do this anymore. 175 00:14:55,820 --> 00:14:59,960 Over this API, you cannot modify conditional access policies anymore. 176 00:15:00,480 --> 00:15:08,880 But conditional access policies are not the only policies, and they block this specifically for conditional access policies, but not for other policies. 177 00:15:09,420 --> 00:15:11,540 So what are some other policies? 178 00:15:11,540 --> 00:15:20,320 You can list these over the policies API endpoints, and we get this on-prem authentication policy, password management policy, a default policy. 179 00:15:20,340 --> 00:15:25,660 Each of these policies is like an integer, is a type number, and this is default for type 24, whatever that means. 180 00:15:25,820 --> 00:15:28,380 And we also have an external identities policy. 181 00:15:28,500 --> 00:15:38,700 So I did some digging into this, and it turns out that the on-prem authentication flow policy is where the seamless single sign-on settings are stored, and the pass-through authentication settings. 182 00:15:38,720 --> 00:15:43,520 The password management policy is where self-service password reset configuration is stored. 183 00:15:43,520 --> 00:15:53,700 Default policy type 24 is the authentication methods, and the external identities policy is how you interact with other tenants, basically your B2B collaboration settings. 184 00:15:54,180 --> 00:16:00,220 So this one was quite interesting, because we just talked about these on-prem attack techniques. 185 00:16:00,580 --> 00:16:09,180 So the on-prem authentication flow policy, it looks a little bit like this, and it has these things called key credentials. 186 00:16:09,280 --> 00:16:17,900 So it turns out these key credentials are actually the symmetric Kerberos keys, where it stores the keys that are used for the seamless single sign-on. 187 00:16:17,900 --> 00:16:24,900 So you create that account on-prem for seamless single sign-on, and it adds the keys here to the key credentials in that policy. 188 00:16:25,240 --> 00:16:29,700 It also stores the keys per domain, like which keys are active for which domain. 189 00:16:29,700 --> 00:16:31,500 That's a bit of a weird structure. 190 00:16:31,680 --> 00:16:34,140 It basically stores the GUIDs of these keys. 191 00:16:34,140 --> 00:16:40,680 So there are actually two keys, or four if you rotated them recently, because it has like N minus one keys. 192 00:16:40,940 --> 00:16:43,160 But there's two key formats. 193 00:16:43,560 --> 00:16:50,920 And the problem is that I cannot see the keys, I cannot extract the keys, not even if I'm global admin, it's not going to return them to me. 194 00:16:51,180 --> 00:16:57,680 So initially I had no clue how these keys were actually stored, because it's a symmetric key, but which key? 195 00:16:57,680 --> 00:17:04,200 Like Kerberos has a lot of different key formats, like RC4, AES, 128, AES-256. 196 00:17:04,420 --> 00:17:07,580 But how do I fit these three key formats in two fields? 197 00:17:07,580 --> 00:17:08,460 I don't know. 198 00:17:08,900 --> 00:17:10,920 So I just tried a couple of combinations. 199 00:17:11,180 --> 00:17:13,220 I tried actually a lot of combinations. 200 00:17:13,480 --> 00:17:17,160 I didn't have any examples or API calls that I could observe. 201 00:17:17,260 --> 00:17:24,020 So I tried putting like the NT hash, or like the plain text password, AES keys, the salt, all that kind of things. 202 00:17:24,200 --> 00:17:33,200 In the end I got it working by just putting like the plain text keys, like the base Kerberos key in both of the fields, and then I could authenticate with RC4. 203 00:17:33,320 --> 00:17:36,460 So if you do that, then at least RC4 works. 204 00:17:36,460 --> 00:17:39,300 I don't think I ever got AES working, but it's something. 205 00:17:39,900 --> 00:17:46,020 So that means if we can modify this, we can actually add our own backdoor seamless single sign-on keys. 206 00:17:46,020 --> 00:17:55,880 And it means that even if you are not using seamless single sign-on, which I hope you're not, because it's not a very good protocol, but we can just add seamless single sign-on keys. 207 00:17:55,880 --> 00:17:59,380 I can enable seamless single sign-on from on-prem basically. 208 00:17:59,760 --> 00:18:10,840 I can do that on an existing domain, but the problem with that is that it will either break the existing seamless single sign-on, which is a bit annoying for the client, or it will be rotated out, which is a bit annoying for me. 209 00:18:11,020 --> 00:18:14,020 But you can also do this on Microsoft.com domains. 210 00:18:14,020 --> 00:18:22,260 So these of course are not even hybrid domains, so there's no, that doesn't make any sense that you configure seamless single sign-on on that, but it does work. 211 00:18:22,260 --> 00:18:33,960 And I can just add these keys on this on-microsoft.com domain, and since all of these keys work for any domain in the tenant, I can then also use these keys on the on-microsoft.com domain to authenticate to regular domains. 212 00:18:35,120 --> 00:18:36,640 So it looks like this. 213 00:18:36,640 --> 00:18:41,020 I added my own two keys to the on-microsoft.com domain. 214 00:18:41,020 --> 00:18:48,680 I put them in the right format, and then I can authenticate with Kerberos tickets to Entra, and I can do seamless single sign-on. 215 00:18:49,280 --> 00:18:54,100 Now, if you're on the defensive side, you may be wondering, what can I detect this for? 216 00:18:54,100 --> 00:18:57,800 Like, are there any logs that I can use to monitor for this behavior? 217 00:18:58,140 --> 00:19:04,480 Unfortunately, the answer is a plain no, because if you change this, there's like literally no events. 218 00:19:04,480 --> 00:19:07,780 Like, I was waiting for the logs to come in, and there just were no logs. 219 00:19:07,780 --> 00:19:14,600 I was going to put a screenshot here of the event, but there is no event if you modify this policy over this internal API. 220 00:19:14,680 --> 00:19:19,560 Funny enough, the only time that an event is generated is when you actually remove the keys again. 221 00:19:19,560 --> 00:19:22,300 Then there is an event, but if you add more keys, then there is not. 222 00:19:22,300 --> 00:19:26,920 So, if you want to detect this, yeah, good luck, because there is no log, so no detection. 223 00:19:27,580 --> 00:19:29,020 So, how do we use this? 224 00:19:29,160 --> 00:19:31,740 That's a bit of a combination of multiple tools. 225 00:19:31,740 --> 00:19:38,720 We need to deal with Kerberos, so you can do it with Impact, with Rubius, whatever tools you like to issue your own Kerberos tickets. 226 00:19:39,080 --> 00:19:47,120 Then we can use road tools hybrids to actually do the Kerberos authentication, and we can authenticate as any hybrid user in the tenants, in any of the domains. 227 00:19:47,720 --> 00:19:54,900 You're forgetting this thing called multi-factor authentication, because seamlessly on sign-on is only your replacement for the passwords. 228 00:19:55,060 --> 00:20:06,100 Again, you're correct, and if we ignore the fact that we could just delete the conditional access policies, there is also a different solution actually for this, and that is in the policy type 24. 229 00:20:06,220 --> 00:20:15,560 So, this actually stores the authentication method policies, and that means that it stores the data from which authentication methods are enabled in the tenants. 230 00:20:16,200 --> 00:20:29,580 I've known about this for a few years, but there was never really an attack path here, because of course I can change the configuration for authentication, but if I enable, for example, Fido keys, it's not suddenly going to allow me to authenticate to accounts, 231 00:20:29,580 --> 00:20:34,780 because the Fido key will then be enabled, but it's not going to be magically linked to users. 232 00:20:35,020 --> 00:20:40,320 But then Microsoft actually added a new feature, and it was called the external authentication methods. 233 00:20:40,560 --> 00:20:52,560 And with that you can basically bring your own external MFA provider, and if I just add an MFA provider to the list, and I put people in scope of that MFA provider, then they can do multi-factor authentication on any external platform. 234 00:20:52,980 --> 00:20:58,960 There's legit providers, of course, but I can also add a fake MFA provider, and I just need to talk to the right protocols. 235 00:20:59,540 --> 00:21:10,560 It's all based on OIDC, and I can just provision a new, like, fake MFA provider that just approves all the MFA requests, and then we can also bypass multi-factor authentication. 236 00:21:10,840 --> 00:21:16,200 If you're interested in the actual protocols, I did give a talk about this earlier this year, about how to set this up. 237 00:21:16,500 --> 00:21:27,180 I also showed there that, again, the logs don't really tell you anything, so if you change this configuration over the internal API, it's going to tell you, like, oh yeah, something was changed, but I'm not going to tell you what. 238 00:21:27,180 --> 00:21:31,280 Like, it was changed from null to some other version of null. 239 00:21:31,380 --> 00:21:33,960 So again, good luck detecting this kind of stuff. 240 00:21:34,900 --> 00:21:37,080 So, let's fill this in the attack graph. 241 00:21:37,080 --> 00:21:50,220 We can modify policies, and with those policies, anything that's contained in policies we can change, and it means we can actually configure seamless single sign-on, we can configure external authentication methods, and then we can, again, impersonate any hybrid user, 242 00:21:50,220 --> 00:21:55,220 even if seamless single sign-on is not configured, like, legitimately on the AD side. 243 00:21:55,980 --> 00:22:06,620 So it was kind of nice, but actually last year, around this time, Microsoft changed a lot of the permissions here, so they hardened all the permissions that the sync accounts had, that it didn't actually need. 244 00:22:06,780 --> 00:22:12,560 And I think this is, like, the best change that Microsoft did in years, because it really reduces the attack service that you have from on-prem. 245 00:22:12,680 --> 00:22:15,660 So now we cannot do this anymore from the on-prem side. 246 00:22:15,660 --> 00:22:18,580 The sync account doesn't have any privileges anymore to do this. 247 00:22:18,620 --> 00:22:27,340 Of course, it still remains, like, a valid scenario if you have control over the tenant to add your own back doors, but that means you're usually already global admin to do this. 248 00:22:27,900 --> 00:22:38,240 So we need to remove a few paths, again, from our attack tree, and unfortunately, well, fortunately or unfortunately, depending on which side of the fence you're on, these things are fixed, so you no longer abuse them. 249 00:22:39,520 --> 00:22:45,000 So I had to look for some other paths, and that kind of led me to Exchange. 250 00:22:45,400 --> 00:22:47,920 Now, Exchange and I have a little bit of a history. 251 00:22:48,080 --> 00:22:51,260 I did talk about Exchange, like, when I started in security. 252 00:22:51,260 --> 00:22:54,160 I don't know if anybody remembers Brave Exchange. 253 00:22:54,160 --> 00:23:03,890 It was one of the first, like, coercion techniques before people figured out that you can coerce, like, literally every protocol against literally every other protocol, and it made this one a little bit less interesting. 254 00:23:04,430 --> 00:23:15,490 But I decided to look at Exchange again, and especially Exchange Hybrid, because Exchange in AD is usually domain admin, and well, maybe Exchange in AD is also privileged in Entra. 255 00:23:15,490 --> 00:23:16,390 Who knows? 256 00:23:16,790 --> 00:23:29,790 And it turns out that Exchange Hybrid on-prem is actually the same thing as Exchange Online, because they share a service principle, and that means that you kind of have this Exchange Online service principle sort of running in your on-prem AD. 257 00:23:29,790 --> 00:23:30,970 That's interesting. 258 00:23:31,390 --> 00:23:40,510 What's also interesting is that Exchange Online is essentially global admin, so that means that we can get global admin from on-prem if you have Exchange Hybrid. 259 00:23:40,510 --> 00:23:51,090 Now, not everybody is going to have Exchange Hybrid, but usually the organizations that should be concerned about these attacks, they're more likely to have this kind of hybrid setup also maybe with Exchange. 260 00:23:51,430 --> 00:23:54,250 Now, how is Exchange Online global admin? 261 00:23:54,250 --> 00:23:55,770 Why is it global admin? 262 00:23:55,830 --> 00:24:01,610 That's a good question, but let's first look at how Exchange Hybrid is actually the same as Exchange Online. 263 00:24:01,650 --> 00:24:11,670 So it turns out that for communication between the on-prem service and the cloud service, they actually have a certificate credential on the service principle on the cloud side. 264 00:24:11,670 --> 00:24:22,710 So that means that if you authenticate to Exchange Hybrid with OAuth, it's going to use the exact same credentials or exactly the same authentication flow as if you authenticate to Outlook on the web. 265 00:24:23,090 --> 00:24:33,110 So it's configured on the service principle of Exchange Online, and that means that we can also use these credentials to authenticate as Exchange Online, and we can essentially become Exchange Online. 266 00:24:33,430 --> 00:24:40,070 We can do that with the OAuth 2.0 client credentials flow, and to do that, we need to have, of course, access to these credentials. 267 00:24:40,630 --> 00:24:42,810 Now, this was like a super long process. 268 00:24:42,810 --> 00:24:45,610 It took me months of very advanced reverse engineering. 269 00:24:46,130 --> 00:24:47,250 Okay, not really. 270 00:24:47,250 --> 00:24:50,170 I just like remote desktops to the Exchange server. 271 00:24:50,170 --> 00:24:51,630 I clicked on certificates. 272 00:24:51,630 --> 00:24:52,470 I right-clicked. 273 00:24:52,470 --> 00:24:53,910 I chose exports. 274 00:24:54,070 --> 00:25:05,210 I choose export private key because for some reason the private key was more affordable, and then I had the credentials basically of Exchange Online, and I could authenticate as Exchange Online in my tenants. 275 00:25:06,130 --> 00:25:21,430 I can do this with RoadTX, so I got a token for the Microsoft Graph, and it's a little bit small, but if we zoom in here, we see the roles that it has, and the interesting here is actually the domain read-write all, and that means that it can modify domains, 276 00:25:21,430 --> 00:25:22,950 but again, that's kind of weird. 277 00:25:23,050 --> 00:25:24,990 Like, well, first of all, why does it need this? 278 00:25:24,990 --> 00:25:26,390 And second of all, what does this mean? 279 00:25:26,430 --> 00:25:44,050 Because domains is quite a broad term, and the ability to read-write domains means that we can actually modify custom domains in a tenant, but it also means that we can configure like some of these hybrid settings that are configured on domains, so we can actually configure the federation information, 280 00:25:44,050 --> 00:25:50,810 which means that even if you don't have ADFS, which most companies don't, Exchange can actually configure ADFS for you. 281 00:25:50,810 --> 00:25:59,230 So it can just add like a symbol token signing certificate on one of these domains, and then of course we can authenticate as any user in the tenants. 282 00:25:59,430 --> 00:26:01,330 So let's look at this case. 283 00:26:01,330 --> 00:26:02,970 I have this federation config here. 284 00:26:02,970 --> 00:26:16,610 This is actually a federated domain, and they made the effort to actually harden this, so they're saying like, well, okay, we're not accepting any MFA claims that are coming from on-prem, so it's rejecting the MFA claims coming from ADFS. 285 00:26:17,230 --> 00:26:20,430 And because I am Exchange, I can modify this. 286 00:26:20,430 --> 00:26:38,210 I just get the current config, I patch it, I do the road DX graph request, which is basically just a wrapper around curl to make my life a bit easier, and then we change the configuration to actually accept multi-factor authentication, and then we can again issue symbol tokens with like fake MFA claims. 287 00:26:38,210 --> 00:26:44,210 We can also add our own symbol token signing certificates, and then we can again pretend to be any hybrid user in the tenants. 288 00:26:45,290 --> 00:26:55,710 So we're adding extra box, we're adding Exchange, and Exchange can actually configure the federation information, and once we've done that, then we can again impersonate any hybrid user in the tenants. 289 00:26:56,310 --> 00:26:57,910 Okay, that's fun. 290 00:26:58,770 --> 00:27:01,290 Actually, this was not the first thing I was looking at. 291 00:27:01,290 --> 00:27:03,530 I just found that like somewhere in the middle. 292 00:27:03,770 --> 00:27:08,290 I was first looking to actually validate that my hybrid setup was even working. 293 00:27:08,370 --> 00:27:11,810 It was quite an effort actually to get hybrid exchange working. 294 00:27:11,810 --> 00:27:15,870 It was less effort to find the bugs than to actually get a complete working setup. 295 00:27:16,310 --> 00:27:22,750 But there is this nice command that you can use to test the OAuth connectivity, and it does authentication then. 296 00:27:22,890 --> 00:27:29,030 So we can actually test if our Exchange hybrid on-prem can successfully authenticate to Exchange online. 297 00:27:29,130 --> 00:27:38,030 And it seems it can, so we're telling it to test the connectivity against outlook.office.com, talking to the EWS API, and the result is success. 298 00:27:38,030 --> 00:27:39,210 So we are authenticated. 299 00:27:39,850 --> 00:27:44,770 This also has a nice flag that you can use to get some more debug information. 300 00:27:45,390 --> 00:27:51,410 And I looked at the debug information, and that was a very large rabbit hole it turned out. 301 00:27:51,650 --> 00:27:54,250 So let's look at some of the information here. 302 00:27:54,310 --> 00:27:56,690 So it goes to outlook.office.com. 303 00:27:56,690 --> 00:27:59,690 It says, hello, I want to talk to the EWS API. 304 00:27:59,930 --> 00:28:02,810 And then that says, okay, you need to be authorized. 305 00:28:03,090 --> 00:28:06,790 I accept tokens from this issuer like 0001. 306 00:28:06,830 --> 00:28:10,470 That's actually the GUID for Entra, so it accepts Entra tokens. 307 00:28:10,790 --> 00:28:15,570 And then Exchange on-prem says, oh, it includes the off-server ACS. 308 00:28:15,750 --> 00:28:17,090 I've never heard of ACS. 309 00:28:17,090 --> 00:28:18,530 I don't know what ACS is. 310 00:28:18,630 --> 00:28:23,490 But then it's getting a token, so it's getting a token at the ACS off-server. 311 00:28:23,830 --> 00:28:27,230 And the token is apparently called a actor token. 312 00:28:27,570 --> 00:28:29,210 I don't know what that is either. 313 00:28:29,330 --> 00:28:33,670 ACS lives on accounts.access control.windows.net. 314 00:28:33,750 --> 00:28:37,510 I had also never, ever heard of that, so I don't know what it is. 315 00:28:37,530 --> 00:28:42,530 I actually still don't know what it is or why it's even there, but it appears to be like some weird legacy thing. 316 00:28:43,150 --> 00:28:45,070 And it was sending an assertion there. 317 00:28:45,070 --> 00:28:49,410 Well, at least I know what an assertion is, and the rest I had to figure out from there. 318 00:28:49,810 --> 00:28:55,790 And when it got that actor token, it generated some other token, and this token is actually not signed. 319 00:28:55,870 --> 00:29:04,970 It's an unsigned JSON web token, and apparently that is used as like an outer mechanism for the inner actor token or something like that. 320 00:29:05,310 --> 00:29:08,790 So I tried to find some documentation on this, which is quite hard. 321 00:29:08,790 --> 00:29:10,630 You're definitely not going to find it for Exchange. 322 00:29:10,630 --> 00:29:13,170 I did find a few documents for SharePoint. 323 00:29:13,390 --> 00:29:29,030 I did also manage to create an image that kind of captures this whole scenario pretty well, because this protocol, these actor tokens, I mean I've seen a lot of shady protocols, a lot of bad protocols, and like this one wins in shadiness by like a very, 324 00:29:29,030 --> 00:29:30,190 very long margin. 325 00:29:30,650 --> 00:29:36,970 So let's have a look at ACS, or access control service it is called. 326 00:29:37,170 --> 00:29:48,910 So you would think that if Exchange wants to access other service in the cloud, that it talks to Entra, that it gets like some tokens with the OAuth like on behalf of Flow, something like that, and it gets some secure scope token. 327 00:29:49,230 --> 00:29:50,370 But no. 328 00:29:50,470 --> 00:30:12,510 So Entra is like this shady friend that's called ACS, and that gives out tokens, if you ask nicely, and Exchange requests an actor token, and ACS issues an actor token, and those actor tokens, as the name implies, they allow Exchange to act on behalf of anybody that it likes. 329 00:30:12,850 --> 00:30:27,230 So if Exchange wants to talk to Exchange online, it's going to say I have this actor token, this actor token allows me to impersonate users, and I'm going to impersonate Bob, or I'm going to impersonate Alice, or I'm going to impersonate whoever I would like to be, 330 00:30:27,230 --> 00:30:31,190 because this actor token allows me to impersonate anybody in the tenant. 331 00:30:31,870 --> 00:30:42,110 And the only time that we actually need to talk to a cloud-based service is when we request the actor token, because the users of the actor token is in this unsigned JSON web token. 332 00:30:42,610 --> 00:30:44,370 So this is how actor tokens look. 333 00:30:44,370 --> 00:30:57,530 So they are signed by Entra actually, the audience in this case is Office, or outlook.office.com, the issuer is this thing called ACS, and the important field here is this trusted for delegation. 334 00:30:57,530 --> 00:31:02,370 So if a token is trusted for delegation, it's allowed to impersonate other users. 335 00:31:02,610 --> 00:31:13,970 Then we take this signed actor token, we embed this in a unsigned bearer token, that's this one, the actor token, and we say, okay, we want to impersonate this user today. 336 00:31:14,890 --> 00:31:19,390 So this is kind of shady, and this has quite a few security implications. 337 00:31:19,630 --> 00:31:27,090 So these things are called service-to-service tokens, or S2S tokens for short, and they have a lot of very interesting properties. 338 00:31:27,730 --> 00:31:29,770 So we're going to stare at this list for a while. 339 00:31:30,170 --> 00:31:32,430 Basically, they're valid for 24 hours. 340 00:31:32,810 --> 00:31:43,710 They cannot be revoked, so once an actor has this token, once an actor has this actor token, they can just access data in your tenant for 24 hours without any restrictions whatsoever, and nothing you can do about it. 341 00:31:43,970 --> 00:31:50,850 There's no logs when they're issued, because when Microsoft apps request tokens, that doesn't generate any logging on our end. 342 00:31:51,050 --> 00:32:01,830 They're unsigned, so to use them, we generate a unsigned token, which means that we don't need to talk to any authentication service, which again means that there's no logs for the actual impersonation itself. 343 00:32:02,010 --> 00:32:16,410 And we can impersonate anybody in the tenant for all the apps, all the Microsoft apps that have this trusted for delegation flag, and basically every Microsoft app I looked at had this, so I think that's a bit of a trend, that Microsoft apps just generally are allowed to do this for you. 344 00:32:17,230 --> 00:32:28,750 This authentication is not subject to conditional access or any security checks whatsoever, so even if you're in a very locked down environment, these actor tokens just bypass all the things, basically. 345 00:32:28,770 --> 00:32:42,090 You can access any mailbox in Exchange online with this, and for some reason it also works for SharePoint, because Exchange can also access SharePoint, which means we can access the OneDrive of anybody, all SharePoint sites, basically anything that we would like. 346 00:32:42,550 --> 00:32:51,050 And these S2S tokens are apparently used by Microsoft in their back end to actually access data on behalf of users. 347 00:32:51,050 --> 00:32:55,750 So in the back end, they're just passing around these actor tokens and just impersonating users. 348 00:32:55,750 --> 00:32:59,210 It all sounds very secure and not shady whatsoever. 349 00:32:59,450 --> 00:33:06,850 If any of these tokens leak, basically each of these tokens impersonate like an entire tenant's worth of data. 350 00:33:06,930 --> 00:33:14,510 So if you get some of these actor tokens out of any Microsoft service, you can just access all the data in that tenant that this token is scoped to. 351 00:33:14,890 --> 00:33:16,210 So it's kind of shady. 352 00:33:16,370 --> 00:33:22,350 Microsoft also seems to be aware that this is kind of shady, so they are actually working quite hard on eliminating this. 353 00:33:22,350 --> 00:33:28,870 They wrote a blog like a month ago that's acknowledging this hyper-difficult access, service-to-service tokens. 354 00:33:28,930 --> 00:33:45,110 I don't know that, I don't think that anybody that read this blog actually has a single clue what's written here, because this just means that all these apps that Microsoft has, they are accessing all this data with high-privileged tokens, impersonation tokens that don't have any security checks. 355 00:33:45,410 --> 00:33:51,950 And they've already successfully mitigated like a thousand high-privileged access scenarios, which is great of course. 356 00:33:51,950 --> 00:33:53,690 It's great that we're improving this. 357 00:33:53,830 --> 00:33:57,350 This also makes me wonder, why was this a thing in the first place? 358 00:33:57,350 --> 00:33:59,810 This sounds like a really bad design. 359 00:34:00,010 --> 00:34:02,510 And also, how many of these are still left? 360 00:34:02,510 --> 00:34:12,510 Because it's nice that you mitigated the thousands, but if there's still like 5,000 left where all these tokens are just like being sent between all these services, still sounds kind of risky. 361 00:34:13,110 --> 00:34:21,790 So, we have Exchange, Exchange on-prem, and it can access any data in Exchange online, and also full access to SharePoint. 362 00:34:21,830 --> 00:34:24,490 So let's do a little demo with that. 363 00:34:24,830 --> 00:34:28,490 I'm going to request an access token, or actor token actually. 364 00:34:28,530 --> 00:34:34,110 I'm going to request that for SharePoint, because the nice thing with SharePoint is these tokens can also be used in the UI. 365 00:34:34,490 --> 00:34:40,150 So I'm requesting an access token for this user, and I'm impersonating this user. 366 00:34:40,150 --> 00:34:45,030 This user is actually global admin, so there's no policies that block me from doing this. 367 00:34:45,070 --> 00:34:48,110 And I can then access their OneDrive in my nice browser. 368 00:34:48,110 --> 00:34:54,690 I can click on things, and you see I'm really authenticated as this user, because I totally did a very secure login. 369 00:34:55,470 --> 00:35:09,190 If I want to impersonate somebody else, I just change the user name in this unsigned token, so I don't need to talk to Entra for this, and I basically can do this for 24 hours with nothing to stop me, and then now I will be authenticated as a different user. 370 00:35:09,770 --> 00:35:11,990 So this works for OneDrive, this works for SharePoint. 371 00:35:12,110 --> 00:35:15,450 This also works for the SharePoint admin center if you want to do that. 372 00:35:15,590 --> 00:35:23,970 It also works for Exchange, but in Exchange they made some changes, so it no longer works in the GUI, but of course over the API it's not a problem if you want to do this. 373 00:35:24,650 --> 00:35:37,050 Now, I was originally going to sort of end it here, and then when I was preparing these slides, I was like, well, what if I request a token for my favorite API, the graph.windows.net? 374 00:35:37,770 --> 00:35:39,250 Well, that was interesting. 375 00:35:39,250 --> 00:35:55,090 I was getting back a token for graph.windows.net, and it was for delegation, so I sent this token to graph.windows.net, or actually I embedded it, the actor token, in a unsigned JSON web token, and it actually worked. 376 00:35:55,370 --> 00:36:11,970 So for this I need to do one more little thing, because the Exchange and SharePoint, they just care about the user principal name, but graph.windows.net actually cares about this thing called a net ID or name ID, and that's like a unique GUI for each user that you have in Entra. 377 00:36:12,730 --> 00:36:27,930 I could talk about it for a while, but basically you can just query this data, Exchange can query this data, you can query this with road recon, so I can just query the net ID of any user I want to impersonate, I put that in the token, and then I can talk to graph.windows.net on behalf of anybody. 378 00:36:28,510 --> 00:36:37,370 And it means that Exchange can basically just impersonate anybody in the tenants over graph.windows.net, and that means it can kind of do anything that it wants. 379 00:36:37,370 --> 00:36:51,690 It can add new users, it can add admins, it can modify settings, it can modify policies, because Exchange is actually a first party app, so it can again modify the conditional access policies, and we can just do whatever, we are basically anybody which includes global admins. 380 00:36:52,250 --> 00:36:54,130 So let's do another demo of that. 381 00:36:54,210 --> 00:37:12,590 This time we get an actor token for graph.windows.net, and I impersonate this user, which is a global admin, and then I just call the API, I add a new user, I give that new user global admin rights, and then we sign into the admin portal to show you that it really works. 382 00:37:13,370 --> 00:37:20,890 We can use our new accounts to authenticate, and we basically have full access to the tenant, we can do whatever we like. 383 00:37:22,130 --> 00:37:29,010 So let's go to the user list, and let's search for the user, show you that it really exists. 384 00:37:31,900 --> 00:37:32,960 There we go. 385 00:37:32,960 --> 00:37:38,320 This is your new global admin, and you see it actually has the role global administrator. 386 00:37:38,320 --> 00:37:48,980 So we compromised Exchange on prem, and then we became anybody, and then we also became global admin in Entra, and we compromised the entire tenant while bypassing all the security features that we have. 387 00:37:49,460 --> 00:37:50,340 So it's fun. 388 00:37:51,000 --> 00:38:05,660 If you look at the audit logs, there are actually audit logs if you perform actions with this, and the nice thing about this, for defenders at least, is that you can detect this quite nicely, because these audit logs look quite weird, because in this case I'm impersonating this user, 389 00:38:05,660 --> 00:38:10,140 but it shows both the user and it shows Exchange at the same time. 390 00:38:10,140 --> 00:38:15,200 So it shows the user principal name of the global admin, but it also shows the display name of Exchange. 391 00:38:15,200 --> 00:38:22,120 And this kind of unique combination of both Exchange and the user is kind of a telltale for this attack. 392 00:38:22,120 --> 00:38:26,180 So you can write a nice detection query that we can actually filter the audit logs. 393 00:38:26,360 --> 00:38:32,580 You have to filter out some of the legit operations that Exchange does, because Exchange actually uses this in the back end. 394 00:38:32,620 --> 00:38:40,240 They use this to modify groups, so if you act like over the Exchange PowerShell module, it will modify groups based on this logic. 395 00:38:40,240 --> 00:38:44,060 It also sometimes modifies the tenant settings, so we have to filter these out. 396 00:38:44,240 --> 00:38:55,820 But then any event that emerges from this query, unless like another weird Exchange thing that I'm not aware of, that should be like somebody misusing this or abusing this. 397 00:38:55,820 --> 00:39:03,820 Thanks to my friends at work in detection for actually validating this across multiple tenants, that this is the only legit behavior that they could find. 398 00:39:03,820 --> 00:39:06,180 So anything that hits from here should be malicious. 399 00:39:06,800 --> 00:39:11,080 Now if you have a tenant , then you might want to know like, does this affect me? 400 00:39:11,080 --> 00:39:18,420 So if you have Exchange Hybrid , then yes it affects you because you have this credentials on the Exchange service principle . 401 00:39:18,460 --> 00:39:20,440 But you can also see this from the cloud perspective. 402 00:39:20,440 --> 00:39:25,420 So if you go in RotaryCon , if you go to the service principles, then you can see the key credentials. 403 00:39:25,820 --> 00:39:35,400 The funny thing is that you cannot see this in the portal because Microsoft tries to hide the ability that service principles can even have secrets in the Azure portal and Entra portal. 404 00:39:35,400 --> 00:39:36,840 So there you cannot see it. 405 00:39:36,840 --> 00:39:38,600 But over the API you can see it. 406 00:39:38,620 --> 00:39:48,300 And if you have key credentials here, then it means that if they're still valid, because you see this sometimes that companies have a Exchange Hybrid set up in the past. 407 00:39:48,300 --> 00:39:49,480 It's no longer there. 408 00:39:49,480 --> 00:39:51,020 So the keys have all expired. 409 00:39:51,020 --> 00:39:51,920 Then you're not at risk. 410 00:39:51,920 --> 00:39:56,580 But if you have an active key, then it's really time to start wondering where is that key? 411 00:39:56,580 --> 00:39:57,740 Who has access to that key? 412 00:39:57,740 --> 00:39:59,260 Is that protected very well? 413 00:39:59,500 --> 00:40:02,620 And if you're not using it, just make sure to remove the keys. 414 00:40:03,280 --> 00:40:11,680 And there's actually a different mitigation because it's now possible to split up the service principle from Exchange Online and Exchange On-Prem. 415 00:40:11,680 --> 00:40:13,380 So they announced this in April. 416 00:40:13,380 --> 00:40:20,520 So it's like somewhere between me submitting this talk and me giving the talk, they also realized themselves that this is not ideal. 417 00:40:20,520 --> 00:40:21,620 So you can split it up. 418 00:40:21,620 --> 00:40:24,500 It's actually going to be required by October 2025. 419 00:40:25,160 --> 00:40:42,800 Actually this, I don't have a screenshot of this, but I gave this talk at Black Hat a few days ago and on that day the Exchange team released another blog and they're like, well not enough of you have been doing this, so we're going to turn off the API for like two days in August to make sure that your stuff breaks and that you really migrate from here. 420 00:40:42,800 --> 00:40:46,340 So they do consider this pretty important to do. 421 00:40:46,340 --> 00:40:49,640 So if you have Exchange Hybrid, definitely go do this. 422 00:40:50,940 --> 00:41:00,360 I didn't actually think this was a vulnerability because I just think it's like an extremely flawed design, but it's not like somebody made that design by accident, like Microsoft uses this. 423 00:41:01,000 --> 00:41:04,360 Somebody legitimately thought like this is the way that we should do it. 424 00:41:04,580 --> 00:41:08,020 So I was like, okay, well it's not a bug, I think. 425 00:41:08,060 --> 00:41:15,520 But I still reported to MSRC like a whole three weeks before I gave this talk, which gave them like plenty of time to think about what to do with it. 426 00:41:16,200 --> 00:41:18,820 The product team did consider it a vulnerability . 427 00:41:18,840 --> 00:41:20,160 That's also a bit unusual. 428 00:41:20,160 --> 00:41:26,460 Usually I think something is a vulnerability and they think it's not a vulnerability, but in this case they definitely thought it was a vulnerability . 429 00:41:27,180 --> 00:41:35,600 And I'm very happy that they actually managed to get out a fix so that I can talk about this without them being angry with me. 430 00:41:35,740 --> 00:41:44,420 But they basically released a fix last week and they also did another fix over the weekend to actually block the behavior for GraffledWindows.net. 431 00:41:45,040 --> 00:41:50,540 So first party service principles can no longer get these actor tokens for this API. 432 00:41:50,880 --> 00:42:01,680 You can still do this for Exchange and SharePoint, so you can still use Exchange on-prem to access Exchange online and get access to all the data that is stored in the cloud service. 433 00:42:01,940 --> 00:42:11,880 They also assigned a CVE, basically they told me on Monday they were going to assign a CVE and on Tuesday, anyway, there was a CVE on the day I was doing my talk. 434 00:42:12,000 --> 00:42:22,060 And then also like CISA released like an emergency patch notice that people should really be doing this, so apparently it caused a little bit of a storm. 435 00:42:22,580 --> 00:42:34,660 And there's the CVE with like the migration things that you should do, which means that you should actually split up the service principle, remove any key credentials that you don't need to mitigate from this on-prem to cloud attack. 436 00:42:35,080 --> 00:42:38,340 So let's change the attack graph a little bit. 437 00:42:38,340 --> 00:42:45,260 We can no longer access any user, but we can of course still access Exchange online or SharePoint online. 438 00:42:45,460 --> 00:42:52,520 I thought that was it, and then yesterday I was actually having a chat with Katie from Datadog, and she was like, did you do something with Exchange? 439 00:42:52,720 --> 00:42:55,480 Because they blocked the ability for Exchange to get tokens for graph. 440 00:42:55,480 --> 00:42:56,300 And I was like, what? 441 00:42:56,300 --> 00:42:56,980 They did? 442 00:42:57,040 --> 00:42:58,380 And it turns out, yes, they did. 443 00:42:58,380 --> 00:43:03,320 So they blocked Exchange service principles for getting tokens for the Microsoft graph like entirely. 444 00:43:03,640 --> 00:43:05,180 So this thing is also kind of fixed. 445 00:43:05,180 --> 00:43:07,940 I didn't know about this, but apparently it is fixed. 446 00:43:08,200 --> 00:43:13,020 So you can also no longer modify the federation configuration. 447 00:43:14,360 --> 00:43:20,720 So to conclude, ID connect was quite a bit more powerful than you probably knew about. 448 00:43:20,740 --> 00:43:26,740 It could modify a lot of things in the tenant, could modify policies, authentication methods, federation config, et cetera. 449 00:43:27,220 --> 00:43:41,580 Exchange hybrid on-prem is essentially the same thing as Exchange online, and Exchange online can just, or could at least access whatever on behalf of anybody with very little logging and not really, yeah, it's just that basically. 450 00:43:41,580 --> 00:43:45,560 I think this whole actor token design shouldn't have been there in the first place. 451 00:43:45,560 --> 00:43:50,480 It's lacking very important security controls in kind of all places that exist. 452 00:43:50,740 --> 00:44:00,940 And I also think that like the whole thing Microsoft is doing in the back ends, they should be a little bit more transparent about this because this has been the case for I don't know how many years. 453 00:44:01,400 --> 00:44:12,840 And if they are doing these insecure things in the back end, at least I'd like to know about this because if they were more transparent about this, maybe I would have found this a few years ago and it would have been more secure like a few years back. 454 00:44:13,080 --> 00:44:16,800 If you have Exchange on-prem, definitely go do the migrations. 455 00:44:18,080 --> 00:44:19,720 Lastly, some references. 456 00:44:19,720 --> 00:44:23,500 So I couldn't put all the references to existing or prior research in there. 457 00:44:23,500 --> 00:44:25,120 Here's a whole list of reading material. 458 00:44:25,120 --> 00:44:32,340 You can also find this version of the slide deck on the DEF CON media server so you don't necessarily need to write all of these down. 459 00:44:33,140 --> 00:44:34,560 And this was kind of my talk. 460 00:44:34,740 --> 00:44:37,340 I was very excited originally about this research. 461 00:44:37,500 --> 00:44:41,180 There is one more thing I'm a little excited about that's going to be my next talk. 462 00:44:41,240 --> 00:44:44,780 And my next talk has a slightly different title. 463 00:44:45,060 --> 00:44:48,680 I'm happy to take any questions on whatever I covered before. 464 00:44:48,680 --> 00:44:51,720 Not on this, but I promise you this is also going to be interesting. 465 00:44:51,780 --> 00:44:52,560 Thank you so much.