start	end	text
0	5800	We have Dirk Jain here to talk about Active Directory and Entra ID Exploitation.
5840	7260	Super excited for this talk.
7260	9540	So everybody help me welcome him to the stage.
9540	10260	Yeah!
16460	18460	Hello, good afternoon everybody.
18920	20000	Thanks for coming out.
20000	21320	It's a full house.
21420	25180	I'm gonna start my presentation by apologizing for two things.
25180	29380	First of all, because my slides are in light mode and it seems kind of bright out there.
29380	33380	So if your eyes hurt at the end of this talk, I'm sorry for that.
33440	36700	The second thing is that the talk is called Advanced.
36700	50620	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.
50620	56640	So we're gonna go through things fast and then we hopefully get to the interesting stuff as soon as we can.
57440	58840	So I'm Dirk Jain.
58840	59980	Thanks for coming out.
59980	62480	I am all the way from the Netherlands.
62680	64900	In my day job I have my own company.
64900	71440	It's called Outsider Security and there I do a bit of a combination of research, pen testing and a lot of training.
71860	73380	Maybe you've seen me here before.
73380	78320	It's actually my third DEF CON and I like to do research.
78320	79700	I like to write tools.
79820	81680	But I don't want to talk about this today.
81680	86620	I actually want to talk about lateral movement from Active Directory to Entra.
86840	95900	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.
96120	99880	But the thing I am really excited to talk about are two things.
100260	102700	Policies and exchange.
102800	107820	Now, I get that's a little vague, but we'll make sense of that later on.
107820	113840	Let's start with the existing attack surface and the changes that were there over the years.
114420	120660	So if we talk about hybrid attacks, it means attacks that cover both AD and Entra.
120660	125400	And for this talk, the starting point is going to be full control over the on-prem Active Directory.
125500	127760	So this is not about like getting domain admin.
127760	135240	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.
135760	137580	So AD is fully compromised.
137580	141320	We have all the access that we want and we want to pivot to Entra.
141620	147880	Now there are a few attacks that you can always do and there's also a few attacks that depend on the configuration.
148400	153320	So ADFS and seamless single sign-on, they're two quite well-known attacks.
153320	155200	They've been covered extensively in the past.
155200	157600	They've been abused by threat actors in the past.
157900	163040	Basically, if you have these components, there's always going to be an attack path from your on-prem AD to Entra.
163520	171740	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.
172040	179400	Now these attack paths, they exist because basically you are putting sort of a trust in a on-prem AD system.
179400	188200	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.
188200	198540	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.
198920	213520	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.
213780	219200	This is not super complicated like concept-wise because we are trusting the system.
219200	225220	If the system is compromised, then the whole hybrid environment is compromised and you can impersonate users in Entra.
225800	228720	Seamless single sign-on is kind of similar actually.
229060	240020	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.
240460	241920	But the same thing is here.
242020	244260	On-prem AD issues Kerberos tickets.
244420	250260	The cloud accepts these Kerberos tickets because it has the key to validate they were issued legitimately.
250600	257860	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.
257860	259540	It's called silver tickets.
259600	263180	You're probably familiar with that because it's not exactly new.
263200	265620	So this is already old stuff.
265620	278620	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.
278620	284240	Because in on-prem AD we have active directory domains, they have their own structure, they're part of the forest.
284580	286820	But in Entra, that doesn't really apply.
286820	289860	So Entra is more of a flat structured identity provider.
290100	296700	That means that all the users that you have, even if you sync users from multiple domains, they're all kind of pooled together.
297360	307560	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.
307560	313380	So that leaves us in a bit of a weird place and I think that's kind of confusing.
313620	315940	But it does have security consequences.
315940	328800	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.
328800	335860	And the only actual security difference is between synchronized accounts, so accounts that come from on-prem, and cloud only accounts.
335860	340180	So people think that it works like this, like with like silos.
340180	343600	So we have two domains here or we have actually quite a few domains.
343600	345900	One is managed, one is federated.
345960	350800	They're synced from different on-prem AD domains that don't even need to be in the same forest.
350840	353480	But there's not really this difference in the cloud.
353480	363840	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.
364100	375140	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.
375160	386240	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.
386400	390560	And the only thing that we cannot do is we cannot target cloud only users.
390560	398500	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.
399020	406360	So this is some of the existing attack service and conceptually actually these two concepts, seamless single sign-on and ADFS are quite similar.
406360	409460	They both can be used to force authentication material.
409460	420860	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.
421060	432220	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.
432220	442280	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.
442360	457240	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.
457720	467300	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.
467740	485500	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.
485900	488780	So seamless single sign -on, ADFS, we've covered that.
489100	495260	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.
495920	499980	And there's also quite a few attack paths that are based on Entra ID connect.
500060	503160	A few of these are already known so I'm not going to cover them extensively.
503380	509300	But one thing I do want to highlight is the ability to actually convert cloud only users to hybrid users.
509320	513960	Because I've just told you that cloud only users are out of scope of these attacks.
513960	518500	We cannot reset password of cloud only accounts or impersonate them with SAML tokens.
518600	524360	But there is actually a way to kind of move a cloud only account to make it a hybrid account.
524360	527640	And then we can actually do these attacks with these accounts.
528060	529600	So there's a technique for that.
529600	531020	It's called soft matching.
531020	532980	There's a variant of that that's called hard matching.
533020	537560	And it's used to work for any account back in 2018 when I first looked at this.
537560	546400	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.
546400	549420	And the synchronization engine will like match those together.
549440	553100	It thinks it's the same account and then suddenly it becomes a hybrid account.
553100	556160	And then it becomes in scope of all of these attacks.
556600	563720	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.
564200	570780	But then somebody else, Sapir, a different researcher, she found out that they actually never fixed this for eligible admins.
570780	576720	Which is a little weird because there's this feature, privileged identity management, that you actually need to pay extra for.
577200	583640	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.
583640	594620	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.
594620	595820	There's mitigation for that.
595820	598460	You can block soft matching, you can block hard matching.
598560	603280	Again, I've never actually seen companies do this because it's quite an obscure setting.
603280	606140	But there are mitigations for this that you can run in theory.
607340	612760	Anyway, if you want to do this, then you need to have access to that Entra ID connect account.
613160	619160	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.
619220	624540	And then you can dump the credentials because it was always using username password authentication.
624540	628100	You can extract the plain text password from the server using several tools.
628200	633860	I wrote the AD connect dump tool suite quite a couple years ago and then you have the credentials of that account.
634520	638640	But maybe you're like, well, actually, we can now do this with a service principle.
638760	641140	And Microsoft announced that a couple of months ago.
641140	642780	And you're like, yeah, this is more secure.
643280	644240	Is it though?
644320	648580	Because if you have a service principle, then it uses certificates for authentication.
648920	652180	But I can also just dump the certificates instead of dumping the password.
652180	659080	So here I added one more tool to the tool suite, which I made open source like earlier this week, AD sync cert dump.
659080	660640	And it will just dump the certificates.
660640	661900	It will dump the private key.
661900	664080	And with that, we can authenticate as a service principle.
664080	666260	And then we can do the exact same as before.
666780	671120	You're like, well, actually, we can also store these in a trusted platform module.
671120	673020	And then it's actually hardware protected.
673480	674500	You're again correct.
674500	675260	We can do that.
675260	676200	It's an option.
676620	683060	But if there's a trusted platform module, then we can just very nicely ask the trusted platform module to sign something for us.
683060	684900	That something is called an assertion.
684900	687240	And that assertion allows us to authenticate.
687240	691260	So if I ask the TPM for this assertion, it allows me to authenticate in the cloud.
691260	693380	And once again, I have access to this account.
693880	698540	You're like, well, actually, that does mean you need persistent access to this host, yes?
698540	702080	Because it's stored in hardware and you don't have the actual private key.
702820	704000	Not really.
704000	708720	Because if we look at this assertion, we see that it's based on a time stamp.
709100	713880	And it's basically a JSON web token that's valid for a limited amount of time.
714080	718700	But of course there's no proof that this time was the actual time when I signed this.
718700	722500	Because I can also sign a token for next week or next year or next month.
722720	726820	So I can just sign the tokens in advance and then I can just use them whenever I want.
727560	734500	Also, if we look at the documentation, it explicitly says that Entra actually doesn't care how large you make the time range.
734500	737160	Because it doesn't enforce any limits on the expiry.
737160	742340	So I can also just create an assertion that's valid for like a year and I can use that then whenever.
742340	745140	So it's nice that it's in hardware protection.
745140	753260	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.
753260	758540	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.
759000	765500	So there's not much difference in attack surface between the service principle based approach and the account based approach in that sense.
766340	769500	So we can use these credentials to convert the accounts.
769620	775160	And a different thing that's interesting is the ability to modify policies.
775240	779680	So that's actually an attack that was documented.
779680	781560	I've talked about it in the past.
781560	784640	But it wasn't always clear what it actually meant.
784640	793980	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.
794180	802660	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.
802940	806100	And then the question is, well, what exactly is a policy?
806100	808020	Like what does a policy even mean?
808020	812360	I can think of a few policies, but are these actually stored as policies?
812680	817760	So let's have a look at policies in my favorite graph API.
818380	820080	That is not this API.
820340	824360	It's going to be this API, the graph.windows.net.
824360	828740	Especially the internal version, the 1.61-internal.
828740	832620	This is like the secret Microsoft version that they don't want you to know about.
832940	840220	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.
840420	848560	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.
849100	853860	Now, one of the policies that is maybe the most obvious one are conditional access policies.
853860	861120	So conditional access policies are the security policies that we use to enforce all these controls in the tenant, like multi-factor authentication.
862100	878020	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.
878580	880220	So they patched this in 2023.
880460	883160	Actually, I talked about this at BlueEd in 2019.
883160	888420	I don't think many people actually realized this was possible, but they did fix it like a few years ago.
888620	895820	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.
895820	899960	Over this API, you cannot modify conditional access policies anymore.
900480	908880	But conditional access policies are not the only policies, and they block this specifically for conditional access policies, but not for other policies.
909420	911540	So what are some other policies?
911540	920320	You can list these over the policies API endpoints, and we get this on-prem authentication policy, password management policy, a default policy.
920340	925660	Each of these policies is like an integer, is a type number, and this is default for type 24, whatever that means.
925820	928380	And we also have an external identities policy.
928500	938700	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.
938720	943520	The password management policy is where self-service password reset configuration is stored.
943520	953700	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.
954180	960220	So this one was quite interesting, because we just talked about these on-prem attack techniques.
960580	969180	So the on-prem authentication flow policy, it looks a little bit like this, and it has these things called key credentials.
969280	977900	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.
977900	984900	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.
985240	989700	It also stores the keys per domain, like which keys are active for which domain.
989700	991500	That's a bit of a weird structure.
991680	994140	It basically stores the GUIDs of these keys.
994140	1000680	So there are actually two keys, or four if you rotated them recently, because it has like N minus one keys.
1000940	1003160	But there's two key formats.
1003560	1010920	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.
1011180	1017680	So initially I had no clue how these keys were actually stored, because it's a symmetric key, but which key?
1017680	1024200	Like Kerberos has a lot of different key formats, like RC4, AES, 128, AES-256.
1024420	1027580	But how do I fit these three key formats in two fields?
1027580	1028460	I don't know.
1028900	1030920	So I just tried a couple of combinations.
1031180	1033220	I tried actually a lot of combinations.
1033480	1037160	I didn't have any examples or API calls that I could observe.
1037260	1044020	So I tried putting like the NT hash, or like the plain text password, AES keys, the salt, all that kind of things.
1044200	1053200	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.
1053320	1056460	So if you do that, then at least RC4 works.
1056460	1059300	I don't think I ever got AES working, but it's something.
1059900	1066020	So that means if we can modify this, we can actually add our own backdoor seamless single sign-on keys.
1066020	1075880	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.
1075880	1079380	I can enable seamless single sign-on from on-prem basically.
1079760	1090840	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.
1091020	1094020	But you can also do this on Microsoft.com domains.
1094020	1102260	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.
1102260	1113960	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.
1115120	1116640	So it looks like this.
1116640	1121020	I added my own two keys to the on-microsoft.com domain.
1121020	1128680	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.
1129280	1134100	Now, if you're on the defensive side, you may be wondering, what can I detect this for?
1134100	1137800	Like, are there any logs that I can use to monitor for this behavior?
1138140	1144480	Unfortunately, the answer is a plain no, because if you change this, there's like literally no events.
1144480	1147780	Like, I was waiting for the logs to come in, and there just were no logs.
1147780	1154600	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.
1154680	1159560	Funny enough, the only time that an event is generated is when you actually remove the keys again.
1159560	1162300	Then there is an event, but if you add more keys, then there is not.
1162300	1166920	So, if you want to detect this, yeah, good luck, because there is no log, so no detection.
1167580	1169020	So, how do we use this?
1169160	1171740	That's a bit of a combination of multiple tools.
1171740	1178720	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.
1179080	1187120	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.
1187720	1194900	You're forgetting this thing called multi-factor authentication, because seamlessly on sign-on is only your replacement for the passwords.
1195060	1206100	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.
1206220	1215560	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.
1216200	1229580	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,
1229580	1234780	because the Fido key will then be enabled, but it's not going to be magically linked to users.
1235020	1240320	But then Microsoft actually added a new feature, and it was called the external authentication methods.
1240560	1252560	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.
1252980	1258960	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.
1259540	1270560	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.
1270840	1276200	If you're interested in the actual protocols, I did give a talk about this earlier this year, about how to set this up.
1276500	1287180	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.
1287180	1291280	Like, it was changed from null to some other version of null.
1291380	1293960	So again, good luck detecting this kind of stuff.
1294900	1297080	So, let's fill this in the attack graph.
1297080	1310220	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,
1310220	1315220	even if seamless single sign-on is not configured, like, legitimately on the AD side.
1315980	1326620	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.
1326780	1332560	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.
1332680	1335660	So now we cannot do this anymore from the on-prem side.
1335660	1338580	The sync account doesn't have any privileges anymore to do this.
1338620	1347340	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.
1347900	1358240	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.
1359520	1365000	So I had to look for some other paths, and that kind of led me to Exchange.
1365400	1367920	Now, Exchange and I have a little bit of a history.
1368080	1371260	I did talk about Exchange, like, when I started in security.
1371260	1374160	I don't know if anybody remembers Brave Exchange.
1374160	1383890	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.
1384430	1395490	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.
1395490	1396390	Who knows?
1396790	1409790	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.
1409790	1410970	That's interesting.
1411390	1420510	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.
1420510	1431090	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.
1431430	1434250	Now, how is Exchange Online global admin?
1434250	1435770	Why is it global admin?
1435830	1441610	That's a good question, but let's first look at how Exchange Hybrid is actually the same as Exchange Online.
1441650	1451670	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.
1451670	1462710	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.
1463090	1473110	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.
1473430	1480070	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.
1480630	1482810	Now, this was like a super long process.
1482810	1485610	It took me months of very advanced reverse engineering.
1486130	1487250	Okay, not really.
1487250	1490170	I just like remote desktops to the Exchange server.
1490170	1491630	I clicked on certificates.
1491630	1492470	I right-clicked.
1492470	1493910	I chose exports.
1494070	1505210	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.
1506130	1521430	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,
1521430	1522950	but again, that's kind of weird.
1523050	1524990	Like, well, first of all, why does it need this?
1524990	1526390	And second of all, what does this mean?
1526430	1544050	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,
1544050	1550810	which means that even if you don't have ADFS, which most companies don't, Exchange can actually configure ADFS for you.
1550810	1559230	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.
1559430	1561330	So let's look at this case.
1561330	1562970	I have this federation config here.
1562970	1576610	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.
1577230	1580430	And because I am Exchange, I can modify this.
1580430	1598210	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.
1598210	1604210	We can also add our own symbol token signing certificates, and then we can again pretend to be any hybrid user in the tenants.
1605290	1615710	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.
1616310	1617910	Okay, that's fun.
1618770	1621290	Actually, this was not the first thing I was looking at.
1621290	1623530	I just found that like somewhere in the middle.
1623770	1628290	I was first looking to actually validate that my hybrid setup was even working.
1628370	1631810	It was quite an effort actually to get hybrid exchange working.
1631810	1635870	It was less effort to find the bugs than to actually get a complete working setup.
1636310	1642750	But there is this nice command that you can use to test the OAuth connectivity, and it does authentication then.
1642890	1649030	So we can actually test if our Exchange hybrid on-prem can successfully authenticate to Exchange online.
1649130	1658030	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.
1658030	1659210	So we are authenticated.
1659850	1664770	This also has a nice flag that you can use to get some more debug information.
1665390	1671410	And I looked at the debug information, and that was a very large rabbit hole it turned out.
1671650	1674250	So let's look at some of the information here.
1674310	1676690	So it goes to outlook.office.com.
1676690	1679690	It says, hello, I want to talk to the EWS API.
1679930	1682810	And then that says, okay, you need to be authorized.
1683090	1686790	I accept tokens from this issuer like 0001.
1686830	1690470	That's actually the GUID for Entra, so it accepts Entra tokens.
1690790	1695570	And then Exchange on-prem says, oh, it includes the off-server ACS.
1695750	1697090	I've never heard of ACS.
1697090	1698530	I don't know what ACS is.
1698630	1703490	But then it's getting a token, so it's getting a token at the ACS off-server.
1703830	1707230	And the token is apparently called a actor token.
1707570	1709210	I don't know what that is either.
1709330	1713670	ACS lives on accounts.access control.windows.net.
1713750	1717510	I had also never, ever heard of that, so I don't know what it is.
1717530	1722530	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.
1723150	1725070	And it was sending an assertion there.
1725070	1729410	Well, at least I know what an assertion is, and the rest I had to figure out from there.
1729810	1735790	And when it got that actor token, it generated some other token, and this token is actually not signed.
1735870	1744970	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.
1745310	1748790	So I tried to find some documentation on this, which is quite hard.
1748790	1750630	You're definitely not going to find it for Exchange.
1750630	1753170	I did find a few documents for SharePoint.
1753390	1769030	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,
1769030	1770190	very long margin.
1770650	1776970	So let's have a look at ACS, or access control service it is called.
1777170	1788910	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.
1789230	1790370	But no.
1790470	1812510	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.
1812850	1827230	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,
1827230	1831190	because this actor token allows me to impersonate anybody in the tenant.
1831870	1842110	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.
1842610	1844370	So this is how actor tokens look.
1844370	1857530	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.
1857530	1862370	So if a token is trusted for delegation, it's allowed to impersonate other users.
1862610	1873970	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.
1874890	1879390	So this is kind of shady, and this has quite a few security implications.
1879630	1887090	So these things are called service-to-service tokens, or S2S tokens for short, and they have a lot of very interesting properties.
1887730	1889770	So we're going to stare at this list for a while.
1890170	1892430	Basically, they're valid for 24 hours.
1892810	1903710	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.
1903970	1910850	There's no logs when they're issued, because when Microsoft apps request tokens, that doesn't generate any logging on our end.
1911050	1921830	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.
1922010	1936410	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.
1937230	1948750	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.
1948770	1962090	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.
1962550	1971050	And these S2S tokens are apparently used by Microsoft in their back end to actually access data on behalf of users.
1971050	1975750	So in the back end, they're just passing around these actor tokens and just impersonating users.
1975750	1979210	It all sounds very secure and not shady whatsoever.
1979450	1986850	If any of these tokens leak, basically each of these tokens impersonate like an entire tenant's worth of data.
1986930	1994510	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.
1994890	1996210	So it's kind of shady.
1996370	2002350	Microsoft also seems to be aware that this is kind of shady, so they are actually working quite hard on eliminating this.
2002350	2008870	They wrote a blog like a month ago that's acknowledging this hyper-difficult access, service-to-service tokens.
2008930	2025110	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.
2025410	2031950	And they've already successfully mitigated like a thousand high-privileged access scenarios, which is great of course.
2031950	2033690	It's great that we're improving this.
2033830	2037350	This also makes me wonder, why was this a thing in the first place?
2037350	2039810	This sounds like a really bad design.
2040010	2042510	And also, how many of these are still left?
2042510	2052510	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.
2053110	2061790	So, we have Exchange, Exchange on-prem, and it can access any data in Exchange online, and also full access to SharePoint.
2061830	2064490	So let's do a little demo with that.
2064830	2068490	I'm going to request an access token, or actor token actually.
2068530	2074110	I'm going to request that for SharePoint, because the nice thing with SharePoint is these tokens can also be used in the UI.
2074490	2080150	So I'm requesting an access token for this user, and I'm impersonating this user.
2080150	2085030	This user is actually global admin, so there's no policies that block me from doing this.
2085070	2088110	And I can then access their OneDrive in my nice browser.
2088110	2094690	I can click on things, and you see I'm really authenticated as this user, because I totally did a very secure login.
2095470	2109190	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.
2109770	2111990	So this works for OneDrive, this works for SharePoint.
2112110	2115450	This also works for the SharePoint admin center if you want to do that.
2115590	2123970	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.
2124650	2137050	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?
2137770	2139250	Well, that was interesting.
2139250	2155090	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.
2155370	2171970	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.
2172730	2187930	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.
2188510	2197370	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.
2197370	2211690	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.
2212250	2214130	So let's do another demo of that.
2214210	2232590	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.
2233370	2240890	We can use our new accounts to authenticate, and we basically have full access to the tenant, we can do whatever we like.
2242130	2249010	So let's go to the user list, and let's search for the user, show you that it really exists.
2251900	2252960	There we go.
2252960	2258320	This is your new global admin, and you see it actually has the role global administrator.
2258320	2268980	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.
2269460	2270340	So it's fun.
2271000	2285660	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,
2285660	2290140	but it shows both the user and it shows Exchange at the same time.
2290140	2295200	So it shows the user principal name of the global admin, but it also shows the display name of Exchange.
2295200	2302120	And this kind of unique combination of both Exchange and the user is kind of a telltale for this attack.
2302120	2306180	So you can write a nice detection query that we can actually filter the audit logs.
2306360	2312580	You have to filter out some of the legit operations that Exchange does, because Exchange actually uses this in the back end.
2312620	2320240	They use this to modify groups, so if you act like over the Exchange PowerShell module, it will modify groups based on this logic.
2320240	2324060	It also sometimes modifies the tenant settings, so we have to filter these out.
2324240	2335820	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.
2335820	2343820	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.
2343820	2346180	So anything that hits from here should be malicious.
2346800	2351080	Now if you have a tenant , then you might want to know like, does this affect me?
2351080	2358420	So if you have Exchange Hybrid , then yes it affects you because you have this credentials on the Exchange service principle .
2358460	2360440	But you can also see this from the cloud perspective.
2360440	2365420	So if you go in RotaryCon , if you go to the service principles, then you can see the key credentials.
2365820	2375400	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.
2375400	2376840	So there you cannot see it.
2376840	2378600	But over the API you can see it.
2378620	2388300	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.
2388300	2389480	It's no longer there.
2389480	2391020	So the keys have all expired.
2391020	2391920	Then you're not at risk.
2391920	2396580	But if you have an active key, then it's really time to start wondering where is that key?
2396580	2397740	Who has access to that key?
2397740	2399260	Is that protected very well?
2399500	2402620	And if you're not using it, just make sure to remove the keys.
2403280	2411680	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.
2411680	2413380	So they announced this in April.
2413380	2420520	So it's like somewhere between me submitting this talk and me giving the talk, they also realized themselves that this is not ideal.
2420520	2421620	So you can split it up.
2421620	2424500	It's actually going to be required by October 2025.
2425160	2442800	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.
2442800	2446340	So they do consider this pretty important to do.
2446340	2449640	So if you have Exchange Hybrid, definitely go do this.
2450940	2460360	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.
2461000	2464360	Somebody legitimately thought like this is the way that we should do it.
2464580	2468020	So I was like, okay, well it's not a bug, I think.
2468060	2475520	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.
2476200	2478820	The product team did consider it a vulnerability .
2478840	2480160	That's also a bit unusual.
2480160	2486460	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 .
2487180	2495600	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.
2495740	2504420	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.
2505040	2510540	So first party service principles can no longer get these actor tokens for this API.
2510880	2521680	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.
2521940	2531880	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.
2532000	2542060	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.
2542580	2554660	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.
2555080	2558340	So let's change the attack graph a little bit.
2558340	2565260	We can no longer access any user, but we can of course still access Exchange online or SharePoint online.
2565460	2572520	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?
2572720	2575480	Because they blocked the ability for Exchange to get tokens for graph.
2575480	2576300	And I was like, what?
2576300	2576980	They did?
2577040	2578380	And it turns out, yes, they did.
2578380	2583320	So they blocked Exchange service principles for getting tokens for the Microsoft graph like entirely.
2583640	2585180	So this thing is also kind of fixed.
2585180	2587940	I didn't know about this, but apparently it is fixed.
2588200	2593020	So you can also no longer modify the federation configuration.
2594360	2600720	So to conclude, ID connect was quite a bit more powerful than you probably knew about.
2600740	2606740	It could modify a lot of things in the tenant, could modify policies, authentication methods, federation config, et cetera.
2607220	2621580	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.
2621580	2625560	I think this whole actor token design shouldn't have been there in the first place.
2625560	2630480	It's lacking very important security controls in kind of all places that exist.
2630740	2640940	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.
2641400	2652840	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.
2653080	2656800	If you have Exchange on-prem, definitely go do the migrations.
2658080	2659720	Lastly, some references.
2659720	2663500	So I couldn't put all the references to existing or prior research in there.
2663500	2665120	Here's a whole list of reading material.
2665120	2672340	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.
2673140	2674560	And this was kind of my talk.
2674740	2677340	I was very excited originally about this research.
2677500	2681180	There is one more thing I'm a little excited about that's going to be my next talk.
2681240	2684780	And my next talk has a slightly different title.
2685060	2688680	I'm happy to take any questions on whatever I covered before.
2688680	2691720	Not on this, but I promise you this is also going to be interesting.
2691780	2692560	Thank you so much.
