We have Dirk Jain here to talk about Active Directory and Entra ID Exploitation. Super excited for this talk. So everybody help me welcome him to the stage. Yeah! Hello, good afternoon everybody. Thanks for coming out. It's a full house. I'm gonna start my presentation by apologizing for two things. First of all, because my slides are in light mode and it seems kind of bright out there. So if your eyes hurt at the end of this talk, I'm sorry for that. The second thing is that the talk is called Advanced. 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. So we're gonna go through things fast and then we hopefully get to the interesting stuff as soon as we can. So I'm Dirk Jain. Thanks for coming out. I am all the way from the Netherlands. In my day job I have my own company. It's called Outsider Security and there I do a bit of a combination of research, pen testing and a lot of training. Maybe you've seen me here before. It's actually my third DEF CON and I like to do research. I like to write tools. But I don't want to talk about this today. I actually want to talk about lateral movement from Active Directory to Entra. 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. But the thing I am really excited to talk about are two things. Policies and exchange. Now, I get that's a little vague, but we'll make sense of that later on. Let's start with the existing attack surface and the changes that were there over the years. So if we talk about hybrid attacks, it means attacks that cover both AD and Entra. And for this talk, the starting point is going to be full control over the on-prem Active Directory. So this is not about like getting domain admin. 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. So AD is fully compromised. We have all the access that we want and we want to pivot to Entra. Now there are a few attacks that you can always do and there's also a few attacks that depend on the configuration. So ADFS and seamless single sign-on, they're two quite well-known attacks. They've been covered extensively in the past. They've been abused by threat actors in the past. Basically, if you have these components, there's always going to be an attack path from your on-prem AD to Entra. 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. Now these attack paths, they exist because basically you are putting sort of a trust in a on-prem AD system. 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. 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. 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. This is not super complicated like concept-wise because we are trusting the system. If the system is compromised, then the whole hybrid environment is compromised and you can impersonate users in Entra. Seamless single sign-on is kind of similar actually. 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. But the same thing is here. On-prem AD issues Kerberos tickets. The cloud accepts these Kerberos tickets because it has the key to validate they were issued legitimately. 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. It's called silver tickets. You're probably familiar with that because it's not exactly new. So this is already old stuff. 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. Because in on-prem AD we have active directory domains, they have their own structure, they're part of the forest. But in Entra, that doesn't really apply. So Entra is more of a flat structured identity provider. That means that all the users that you have, even if you sync users from multiple domains, they're all kind of pooled together. 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. So that leaves us in a bit of a weird place and I think that's kind of confusing. But it does have security consequences. 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. And the only actual security difference is between synchronized accounts, so accounts that come from on-prem, and cloud only accounts. So people think that it works like this, like with like silos. So we have two domains here or we have actually quite a few domains. One is managed, one is federated. They're synced from different on-prem AD domains that don't even need to be in the same forest. But there's not really this difference in the cloud. 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. 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. 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. And the only thing that we cannot do is we cannot target cloud only users. 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. So this is some of the existing attack service and conceptually actually these two concepts, seamless single sign-on and ADFS are quite similar. They both can be used to force authentication material. 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. 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. 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. 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. 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. 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. So seamless single sign -on, ADFS, we've covered that. 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. And there's also quite a few attack paths that are based on Entra ID connect. A few of these are already known so I'm not going to cover them extensively. But one thing I do want to highlight is the ability to actually convert cloud only users to hybrid users. Because I've just told you that cloud only users are out of scope of these attacks. We cannot reset password of cloud only accounts or impersonate them with SAML tokens. But there is actually a way to kind of move a cloud only account to make it a hybrid account. And then we can actually do these attacks with these accounts. So there's a technique for that. It's called soft matching. There's a variant of that that's called hard matching. And it's used to work for any account back in 2018 when I first looked at this. 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. And the synchronization engine will like match those together. It thinks it's the same account and then suddenly it becomes a hybrid account. And then it becomes in scope of all of these attacks. 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. But then somebody else, Sapir, a different researcher, she found out that they actually never fixed this for eligible admins. Which is a little weird because there's this feature, privileged identity management, that you actually need to pay extra for. 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. 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. There's mitigation for that. You can block soft matching, you can block hard matching. Again, I've never actually seen companies do this because it's quite an obscure setting. But there are mitigations for this that you can run in theory. Anyway, if you want to do this, then you need to have access to that Entra ID connect account. 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. And then you can dump the credentials because it was always using username password authentication. You can extract the plain text password from the server using several tools. I wrote the AD connect dump tool suite quite a couple years ago and then you have the credentials of that account. But maybe you're like, well, actually, we can now do this with a service principle. And Microsoft announced that a couple of months ago. And you're like, yeah, this is more secure. Is it though? Because if you have a service principle, then it uses certificates for authentication. But I can also just dump the certificates instead of dumping the password. So here I added one more tool to the tool suite, which I made open source like earlier this week, AD sync cert dump. And it will just dump the certificates. It will dump the private key. And with that, we can authenticate as a service principle. And then we can do the exact same as before. You're like, well, actually, we can also store these in a trusted platform module. And then it's actually hardware protected. You're again correct. We can do that. It's an option. But if there's a trusted platform module, then we can just very nicely ask the trusted platform module to sign something for us. That something is called an assertion. And that assertion allows us to authenticate. So if I ask the TPM for this assertion, it allows me to authenticate in the cloud. And once again, I have access to this account. You're like, well, actually, that does mean you need persistent access to this host, yes? Because it's stored in hardware and you don't have the actual private key. Not really. Because if we look at this assertion, we see that it's based on a time stamp. And it's basically a JSON web token that's valid for a limited amount of time. But of course there's no proof that this time was the actual time when I signed this. Because I can also sign a token for next week or next year or next month. So I can just sign the tokens in advance and then I can just use them whenever I want. Also, if we look at the documentation, it explicitly says that Entra actually doesn't care how large you make the time range. Because it doesn't enforce any limits on the expiry. So I can also just create an assertion that's valid for like a year and I can use that then whenever. So it's nice that it's in hardware protection. 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. 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. So there's not much difference in attack surface between the service principle based approach and the account based approach in that sense. So we can use these credentials to convert the accounts. And a different thing that's interesting is the ability to modify policies. So that's actually an attack that was documented. I've talked about it in the past. But it wasn't always clear what it actually meant. 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. 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. And then the question is, well, what exactly is a policy? Like what does a policy even mean? I can think of a few policies, but are these actually stored as policies? So let's have a look at policies in my favorite graph API. That is not this API. It's going to be this API, the graph.windows.net. Especially the internal version, the 1.61-internal. This is like the secret Microsoft version that they don't want you to know about. 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. 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. Now, one of the policies that is maybe the most obvious one are conditional access policies. So conditional access policies are the security policies that we use to enforce all these controls in the tenant, like multi-factor authentication. 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. So they patched this in 2023. Actually, I talked about this at BlueEd in 2019. I don't think many people actually realized this was possible, but they did fix it like a few years ago. 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. Over this API, you cannot modify conditional access policies anymore. But conditional access policies are not the only policies, and they block this specifically for conditional access policies, but not for other policies. So what are some other policies? You can list these over the policies API endpoints, and we get this on-prem authentication policy, password management policy, a default policy. Each of these policies is like an integer, is a type number, and this is default for type 24, whatever that means. And we also have an external identities policy. 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. The password management policy is where self-service password reset configuration is stored. 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. So this one was quite interesting, because we just talked about these on-prem attack techniques. So the on-prem authentication flow policy, it looks a little bit like this, and it has these things called key credentials. 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. 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. It also stores the keys per domain, like which keys are active for which domain. That's a bit of a weird structure. It basically stores the GUIDs of these keys. So there are actually two keys, or four if you rotated them recently, because it has like N minus one keys. But there's two key formats. 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. So initially I had no clue how these keys were actually stored, because it's a symmetric key, but which key? Like Kerberos has a lot of different key formats, like RC4, AES, 128, AES-256. But how do I fit these three key formats in two fields? I don't know. So I just tried a couple of combinations. I tried actually a lot of combinations. I didn't have any examples or API calls that I could observe. So I tried putting like the NT hash, or like the plain text password, AES keys, the salt, all that kind of things. 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. So if you do that, then at least RC4 works. I don't think I ever got AES working, but it's something. So that means if we can modify this, we can actually add our own backdoor seamless single sign-on keys. 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. I can enable seamless single sign-on from on-prem basically. 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. But you can also do this on Microsoft.com domains. 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. 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. So it looks like this. I added my own two keys to the on-microsoft.com domain. 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. Now, if you're on the defensive side, you may be wondering, what can I detect this for? Like, are there any logs that I can use to monitor for this behavior? Unfortunately, the answer is a plain no, because if you change this, there's like literally no events. Like, I was waiting for the logs to come in, and there just were no logs. 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. Funny enough, the only time that an event is generated is when you actually remove the keys again. Then there is an event, but if you add more keys, then there is not. So, if you want to detect this, yeah, good luck, because there is no log, so no detection. So, how do we use this? That's a bit of a combination of multiple tools. 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. 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. You're forgetting this thing called multi-factor authentication, because seamlessly on sign-on is only your replacement for the passwords. 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. 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. 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, because the Fido key will then be enabled, but it's not going to be magically linked to users. But then Microsoft actually added a new feature, and it was called the external authentication methods. 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. 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. 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. If you're interested in the actual protocols, I did give a talk about this earlier this year, about how to set this up. 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. Like, it was changed from null to some other version of null. So again, good luck detecting this kind of stuff. So, let's fill this in the attack graph. 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, even if seamless single sign-on is not configured, like, legitimately on the AD side. 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. 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. So now we cannot do this anymore from the on-prem side. The sync account doesn't have any privileges anymore to do this. 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. 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. So I had to look for some other paths, and that kind of led me to Exchange. Now, Exchange and I have a little bit of a history. I did talk about Exchange, like, when I started in security. I don't know if anybody remembers Brave Exchange. 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. 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. Who knows? 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. That's interesting. 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. 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. Now, how is Exchange Online global admin? Why is it global admin? That's a good question, but let's first look at how Exchange Hybrid is actually the same as Exchange Online. 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. 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. 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. 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. Now, this was like a super long process. It took me months of very advanced reverse engineering. Okay, not really. I just like remote desktops to the Exchange server. I clicked on certificates. I right-clicked. I chose exports. 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. 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, but again, that's kind of weird. Like, well, first of all, why does it need this? And second of all, what does this mean? 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, which means that even if you don't have ADFS, which most companies don't, Exchange can actually configure ADFS for you. 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. So let's look at this case. I have this federation config here. 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. And because I am Exchange, I can modify this. 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. We can also add our own symbol token signing certificates, and then we can again pretend to be any hybrid user in the tenants. 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. Okay, that's fun. Actually, this was not the first thing I was looking at. I just found that like somewhere in the middle. I was first looking to actually validate that my hybrid setup was even working. It was quite an effort actually to get hybrid exchange working. It was less effort to find the bugs than to actually get a complete working setup. But there is this nice command that you can use to test the OAuth connectivity, and it does authentication then. So we can actually test if our Exchange hybrid on-prem can successfully authenticate to Exchange online. 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. So we are authenticated. This also has a nice flag that you can use to get some more debug information. And I looked at the debug information, and that was a very large rabbit hole it turned out. So let's look at some of the information here. So it goes to outlook.office.com. It says, hello, I want to talk to the EWS API. And then that says, okay, you need to be authorized. I accept tokens from this issuer like 0001. That's actually the GUID for Entra, so it accepts Entra tokens. And then Exchange on-prem says, oh, it includes the off-server ACS. I've never heard of ACS. I don't know what ACS is. But then it's getting a token, so it's getting a token at the ACS off-server. And the token is apparently called a actor token. I don't know what that is either. ACS lives on accounts.access control.windows.net. I had also never, ever heard of that, so I don't know what it is. 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. And it was sending an assertion there. Well, at least I know what an assertion is, and the rest I had to figure out from there. And when it got that actor token, it generated some other token, and this token is actually not signed. 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. So I tried to find some documentation on this, which is quite hard. You're definitely not going to find it for Exchange. I did find a few documents for SharePoint. 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, very long margin. So let's have a look at ACS, or access control service it is called. 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. But no. 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. 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, because this actor token allows me to impersonate anybody in the tenant. 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. So this is how actor tokens look. 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. So if a token is trusted for delegation, it's allowed to impersonate other users. 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. So this is kind of shady, and this has quite a few security implications. So these things are called service-to-service tokens, or S2S tokens for short, and they have a lot of very interesting properties. So we're going to stare at this list for a while. Basically, they're valid for 24 hours. 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. There's no logs when they're issued, because when Microsoft apps request tokens, that doesn't generate any logging on our end. 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. 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. 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. 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. And these S2S tokens are apparently used by Microsoft in their back end to actually access data on behalf of users. So in the back end, they're just passing around these actor tokens and just impersonating users. It all sounds very secure and not shady whatsoever. If any of these tokens leak, basically each of these tokens impersonate like an entire tenant's worth of data. 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. So it's kind of shady. Microsoft also seems to be aware that this is kind of shady, so they are actually working quite hard on eliminating this. They wrote a blog like a month ago that's acknowledging this hyper-difficult access, service-to-service tokens. 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. And they've already successfully mitigated like a thousand high-privileged access scenarios, which is great of course. It's great that we're improving this. This also makes me wonder, why was this a thing in the first place? This sounds like a really bad design. And also, how many of these are still left? 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. So, we have Exchange, Exchange on-prem, and it can access any data in Exchange online, and also full access to SharePoint. So let's do a little demo with that. I'm going to request an access token, or actor token actually. I'm going to request that for SharePoint, because the nice thing with SharePoint is these tokens can also be used in the UI. So I'm requesting an access token for this user, and I'm impersonating this user. This user is actually global admin, so there's no policies that block me from doing this. And I can then access their OneDrive in my nice browser. I can click on things, and you see I'm really authenticated as this user, because I totally did a very secure login. 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. So this works for OneDrive, this works for SharePoint. This also works for the SharePoint admin center if you want to do that. 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. 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? Well, that was interesting. 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. 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. 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. 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. 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. So let's do another demo of that. 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. We can use our new accounts to authenticate, and we basically have full access to the tenant, we can do whatever we like. So let's go to the user list, and let's search for the user, show you that it really exists. There we go. This is your new global admin, and you see it actually has the role global administrator. 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. So it's fun. 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, but it shows both the user and it shows Exchange at the same time. So it shows the user principal name of the global admin, but it also shows the display name of Exchange. And this kind of unique combination of both Exchange and the user is kind of a telltale for this attack. So you can write a nice detection query that we can actually filter the audit logs. You have to filter out some of the legit operations that Exchange does, because Exchange actually uses this in the back end. They use this to modify groups, so if you act like over the Exchange PowerShell module, it will modify groups based on this logic. It also sometimes modifies the tenant settings, so we have to filter these out. 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. 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. So anything that hits from here should be malicious. Now if you have a tenant , then you might want to know like, does this affect me? So if you have Exchange Hybrid , then yes it affects you because you have this credentials on the Exchange service principle . But you can also see this from the cloud perspective. So if you go in RotaryCon , if you go to the service principles, then you can see the key credentials. 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. So there you cannot see it. But over the API you can see it. 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. It's no longer there. So the keys have all expired. Then you're not at risk. But if you have an active key, then it's really time to start wondering where is that key? Who has access to that key? Is that protected very well? And if you're not using it, just make sure to remove the keys. 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. So they announced this in April. So it's like somewhere between me submitting this talk and me giving the talk, they also realized themselves that this is not ideal. So you can split it up. It's actually going to be required by October 2025. 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. So they do consider this pretty important to do. So if you have Exchange Hybrid, definitely go do this. 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. Somebody legitimately thought like this is the way that we should do it. So I was like, okay, well it's not a bug, I think. 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. The product team did consider it a vulnerability . That's also a bit unusual. 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 . 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. 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. So first party service principles can no longer get these actor tokens for this API. 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. 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. 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. 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. So let's change the attack graph a little bit. We can no longer access any user, but we can of course still access Exchange online or SharePoint online. 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? Because they blocked the ability for Exchange to get tokens for graph. And I was like, what? They did? And it turns out, yes, they did. So they blocked Exchange service principles for getting tokens for the Microsoft graph like entirely. So this thing is also kind of fixed. I didn't know about this, but apparently it is fixed. So you can also no longer modify the federation configuration. So to conclude, ID connect was quite a bit more powerful than you probably knew about. It could modify a lot of things in the tenant, could modify policies, authentication methods, federation config, et cetera. 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. I think this whole actor token design shouldn't have been there in the first place. It's lacking very important security controls in kind of all places that exist. 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. 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. If you have Exchange on-prem, definitely go do the migrations. Lastly, some references. So I couldn't put all the references to existing or prior research in there. Here's a whole list of reading material. 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. And this was kind of my talk. I was very excited originally about this research. There is one more thing I'm a little excited about that's going to be my next talk. And my next talk has a slightly different title. I'm happy to take any questions on whatever I covered before. Not on this, but I promise you this is also going to be interesting. Thank you so much.