Access our demo library to view BeyondTrust products in action.
Learn More Learn MoreComplete your PAM journey with detailed guidance, hands-on capability checklists, and more.
Learn More Learn MoreLearn why Gartner® has named BeyondTrust as a PAM Leader once again.
Learn More Learn MoreExplore how customers are using our solutions to advance security and productivity.
Learn More Learn MoreOffering a wide array of services and benefits tailored to your specific needs
Learn More Learn MoreLearn how BeyondTrust solutions protect companies from cyber threats.
Learn More Learn MoreAccess our demo library to view BeyondTrust products in action.
Learn More Learn MoreThis blog reveals a novel attack path in Microsoft Entra ID (formerly Azure AD) that leverages a little-known Azure VM feature to escalate privileges from guest access to full Entra admin. By combining device identity abuse with phishing techniques to steal Primary Refresh Tokens (PRTs), attackers can bypass traditional security controls and perform stealthy lateral movement. Building on our previous Restless Guests research, we unpack each stage of the “Evil VM” attack chain and provide practical guidance for defenders to detect and mitigate these risks.
In this blog, we explore how a niche Azure VM feature can be leveraged to bypass controls that typically prevent users from joining devices to Entra ID. We will then demonstrate how to combine this abuse with known primary refresh token (PRT) theft techniques and show how these techniques amplify the risk for defenders. Finally, we will cover the essential defenses to mitigate these Entra ID lateral movement techniques.
This blog builds on our previous Restless Guests research, in which we demonstrated how B2B guests in Entra ID (formerly Azure AD) can become subscription owners in your tenant without explicit authorization. We will also spend some time detailing the process of inserting a “restless guest” into a target directory.
“If I have seen further it is by standing on the shoulders of giants” - Isaac Newton
A massive thank you to Dirk-jan Mollema for publishing ROADtools, authoring the phishing attack I reference below, and for graciously helping me debug and fix my transport key decryption problems. Endless gratitude to Dr. Nestori Syynimaa for sharing AADInternals, a treasure trove of useful blogs and tools that were also essential to the attack detailed. A final thanks to my manager, Fletcher Davis, who pointed me in the right direction and pushed me not to give up.
Let’s begin with the basics of devices in Entra ID. Devices are nuanced security principals. While they can authenticate against the directory, they cannot be directly assigned Directory roles or RBAC roles like users or service principals. For instance, a device cannot request an access token on its own.
Their primary purpose is to provide identities so they can be monitored, secured, and leveraged by administrators to determine access to resources. For example, a user on a trusted device may be granted more access than they would get on a machine that is not a trusted device identity. This is achieved through Conditional Access Policies, where devices are a key signal as to whether a policy will grant a user access to a resource.
Devices (endpoints) are a crucial part of Microsoft’s Zero Trust concept. Devices can be Registered, Joined, or Hybrid Joined to Azure AD. Conditional Access uses the device information as one of the decisions criteria to allow or block access to services. -- Dr Nestori Syynimaa (@DrAzureAD)
Devices gain an identity in the Entra directory either as "registered devices" (user-owned "bring-your-own-devices"), or "joined devices" (organization-owned). In both scenarios, Entra ID generates a unique device identity through a private/public certificate.
Beyond the certificate, a transport key adds an essential layer of security. This key encrypts sensitive data sent from Entra ID to the device, serving as a "proof of possession", since only the device holding the key can decrypt the content. Given their critical role in device identity and security, these certificates and keys are typically secured within a Trusted Platform Module (TPM). The TPM is a hardware security chip (or firmware module) found on Windows machines, designed specifically for the secure storage and management of cryptographic keys and secrets.
An aspect of device behavior that is especially important to attackers is how Entra ID will issue Primary Refresh Tokens to joined devices. So, let’s dive into PRTs next.
Primary Refresh Tokens (PRTs) are used for single sign-on (SSO) within Entra ID. They are issued to users logging in to Entra ID from a joined device. A PRT is initially valid for 14 days and can extend to 90 days with continuous renewal, provided the user remains active on the device. The core function of a PRT is to enable seamless SSO, allowing users to request subsequent refresh and access tokens for various Microsoft applications and services without re-authenticating. To protect these high-value tokens, it is highly recommended that you secure them using the TPM.
For a deeper dive into PRTs, I recommend the following articles:
Given that Entra-joined devices are a crucial signal in Conditional Access Policy evaluation, we were surprised to learn that the default permission assigned to Entra users allows them to join a device to the Entra tenant. This default, however, does not apply to Entra B2B guests. Unless explicitly granted, guests have no rights to join or register devices in Entra ID.
Implementation: Within Entra ID, configure the “Users may join devices to Entra ID” setting to restrict device registration to a specified group. For example, assign onboarding teams to handle device registrations, limiting broad access.
Benefit: Only approved users can join devices, reducing the risk of unwanted devices in your environment. -- msp4msps
In the context of our previous Restless Guests research—where an Entra guest account can obtain ownership over a subscription—it appears possible to circumvent the device joining controls shown in Figure 1 and Figure 2. Virtual machines (VMs) created within this subscription can be configured without device protections, exposing key data and token material, such as device certificates, transport keys, and any PRTs that are issued to it.
Since the user can create a Windows VM, they can choose to provision it with the “Azure AD based Windows Login” extension. During deployment, this VM will be joined to Entra ID, as shown below in Figure 3. The extension’s purpose is to facilitate login to the VM using the user’s Entra ID credentials. Remote access to the VM can then be granted by assigning the user one of the following RBAC roles: “Virtual Machine User Login” or “Virtual Machine Administrator Login”.
When a device is joined to Entra ID, Conditional Access Policies are configured with the expectation that these devices are owned by the organization.
Recalling our prior Restless Guest research, by default, a guest with the appropriate billing role in their home directory can obtain ownership of a subscription in your directory. If a threat actor were to sign up for a simple pay-as-you-go Microsoft Account, they would become the billing owner of the account, granting them the privilege to create subscriptions. Another default is that any user/guest can invite other guests into the directory. Therefore, if a threat actor compromises any user or guest in your directory, they could invite their newly created Microsoft Account owner into your tenant and create a rogue subscription within.
Subscription owners have the privilege to create any infrastructure within their subscriptions. This allows an attacker to provision a Windows VM with the Azure AD login extension, which will then automatically join as a device. This remains true even if no users are allowed to join devices, as the process can leverage a managed identity. What makes these “evil VMs” particularly dangerous is that the attacker can choose whether this Windows VM has TPM enabled. This is accomplished by selecting “Gen 1” type images and “Standard” security type, which results in no TPM protections.
In summary:
A threat actor who is in control of any starting guest/user, with default settings, can laterally move to gain local admin rights to a VM joined device that doesn’t have TPM protections!
The absence of TPM protections means any PRT issued to the VM will be easy to harvest with a red-team tool such as Mimikatz. The remainder of this article will detail how to escalate privileges further by outlining how a known phishing attack, “device code phishing”, could operate in this context.
This attack, first detailed by Dirk-Jan Mollema, exploits our ability to upgrade a refresh token, specifically for the Microsoft Authentication Broker application, to gain access to a full Primary Refresh Token.
The key advantage of device code phishing is that at no point is the user redirected to a bad URL; the phished users only ever interact with legitimate Entra ID URLs. We leverage the OAuth2 device code standard flow, which allows one device to start an authentication process that is completed by another, with the resulting token then sent back to the original device.
As stated in the original article, a usual limitation of the attack is the following:
Registering or joining devices could be restricted in the tenant to only specific users. In general, joining devices is restricted more often than registering them. -- Dirk-Jan Mollema
Furthermore, guests have no out-of-the-box rights to register or join devices; only members can do either. However, as we just demonstrated, we can overcome this limitation using the Entra ID login extension. The full attack path then unfolds as follows:
Let’s go through each step in the process.
Let’s assume a threat actor compromises a B2B guest account within a target tenant. We’ll assume this guest has no role assignments, group memberships, or any access explicitly granted by the tenant’s administrators. Our subsequent lateral movement will rely solely on out-of-the-box privileges and default tenant controls, demonstrating a real-world Entra ID guest account takeover scenario.
It's worth pointing out that there are a few different ways we could establish a viable foothold:
To introduce a “restless guest” in the resource tenant we are attacking, a specific setup is required. Let’s create a user in a separate tenant that we, as the attacker, control (our home tenant). The easiest way to achieve this is to sign up for a Microsoft Account using a credit card. We’ll even get $200 worth of free credits! The account used for signing up will automatically become the billing owner, as it is directly linked to the credit card used for billing.
“By default, all users in your organization, including B2B collaboration guest users, can invite external users to B2B collaboration. If you want to limit the ability to send invitations, you can turn invitations on or off for everyone, or limit invitations to certain roles.” -- Microsoft Ignite
Next, we need to invite this billing owner into the tenant we intend to attack. Due to the permissive Entra ID invite defaults, we can use our initial compromised guest account to invite this billing owner into the target tenant. Consequently, we now have a guest user in the resource tenant we are attacking, who is also a billing account owner in their home tenant.
While in our home tenant, we can create a subscription. By default, we are also allowed to transfer this subscription into the resource tenant where this user is a guest.
If performing this in the portal, when creating a subscription, we specify the ‘subscription directory’ dropdown under ‘Advanced’ as resource. Once this is done, our guest is now the proud owner of a subscription.
Subscription owners are free to create any resources they like within their subscription, giving us full privileges to make an evil VM. The primary goal of this step is to gain local admin access to a VM without TPM protections. We want a VM without TPM protections to make stealing the PRT easy. We accomplish this by choosing a “Gen 1” with security type “Standard”.
Doing so in the portal looks something like this:
We will also ensure the VM becomes an Entra ID-joined device. This configuration means the VM will have its own identity, allowing it to authenticate against the directory.
In the portal, we can achieve this during the VM creation process, by navigating to the “Management” tab, and selecting “Login with Microsoft Entra ID”.
We will also enter local admin credentials for the machine and then hit create. Once the VM is deployed, we can run “dsregcmd /status” on it to check both its TPM protection and join status.
Interestingly, we can also join devices without necessarily installing this extension. This technique was first explored in this article. Decompiling the extension’s binary reveals that it is essentially a simple wrapper for dsregcmd.exe. We can manually attach our own Managed Identity, change some registry settings, and then call “dsregcmd.exe /AzureSecureVMJoin”.
Since we have local admin access on the VM, we can steal the device certificate. This device identity will persist even if the guest account, the VM itself, or the entire subscription is deleted. Once stolen, we can authenticate as this device identity on a completely different machine. Congratulations, we are the proud owner of a device backdoor.
We can achieve this with AADInternals-Endpoints:
To successfully phish users, we will need their details, such as names and emails. Thankfully, we can often obtain admin details by inspecting our newly created subscription’s IAM role assignments. Any users who have a role at the root management group will automatically inherit those permissions into our guest-created subscription. This typically happens when Global Admins toggle a setting in Entra ID that grants them basic access to all subscriptions within the tenant.
In the portal we do this by simply inspecting the “Access Control (IAM)” tab of the subscription, and then looking at the “Role Assignments”.
Because we have a stolen device certificate, we can combine it with a special kind of refresh token and upgrade it to a PRT. This technique was first published by Dirk-jan Mollema. While we recommend reading the original article for a detailed understanding of the technique, at a high level, this is what we are doing:
If you want to try the phishing step, it can be implemented using ROADtools:
Attackers are using this technique in the wild, succeeding, and making news on Microsoft’s own blog. In fact, there are phishing kits for red teamers that support this flow. So, assuming we land a successful phish, we simply upgrade our refresh token to a PRT by using ROADtools again:
We can then use this PRT to gain access to any Azure service we like:
Congratulations; you are now global admin!
The above attack chain leverages default settings at each stage, so preventing attacks of this nature requires careful systems hardening. The following steps are HIGHLY recommended:
Allowing only specified users to invite guests into the directory drastically reduces the initial attack vector.
Allowing only specified users to transfer subscriptions into the directory prevents any guest from utilizing their billing role permissions to become a subscription owner inside the directory.
Block the creation of “Gen 1” VMs within any subscription attached to the directory. Gen 1 VMs lack TPM (Trusted Platform Module) protections, making it significantly easier for threat actors to extract certificates and secrets from the device.
Refer to the Azure policy for allowed VM SKUs and apply it at the root management group level.
If business constraints mean guest controls in the prior steps can’t be put in place, defenders may need to resort to detections to catch restless guests that are moving laterally. This poses challenges because an attacker can evade detections by creating persistent federated access via a managed identity, as detailed by this article. After creating such a backdoor, guests can transfer the subscription ownership and evade the “Guest accounts with owner permissions on Azure Resources” displayed by Microsoft Defender for Cloud. Ironically as a subscription owner, attackers can manually silence these alerts as well.
Moreover, attackers could be sneaky and give ownership of the subscription / Azure resources to real admins (gaining the principal id using the enumeration technique above). This would go a long way to make a subscription and its resources appear legitimate; the attacker only needs ‘contributor’ level RBAC permission. Even then, an attacker could relinquish all RBAC privileges once they have local admin to an Evil VM. In this case, the following detection rules provide a best effort for detecting the full range of possible attacks:
The “Evil VM” attack path reveals how default configurations in Entra ID can be exploited to escalate privileges from guest access to full admin control through device identity abuse and Primary Refresh Token (PRT) theft. By tightening guest invitation policies, restricting subscription transfers, and enforcing secure VM configurations, organizations can significantly reduce the risk of lateral movement in Entra ID environments. Defenders must treat device identities and token-based access with the same scrutiny as user accounts to close these hidden privilege escalation pathways.
Want to understand how your Entra ID environment holds up against identity-based attack paths? Let our Identity Security Risk Assessment uncover any misconfigurations in your environment before threat actors can.
Simon Maxwell-Stewart is a University of Oxford physics graduate with over a decade of experience in the big data environment. Before joining BeyondTrust, he worked as a Lead Data Scientist in healthcare, and successfully brought multiple machine learning projects into production. Now working as a "resident graph nerd" on BeyondTrust's security research team, Simon applies his expertise in graph analysis to help drive identity security innovation.
BeyondTrust Phantom Labs™ believes the best way to fully understand cybersecurity threats is to work closely with our customers and partners, conducting real world research into the attacks that matter most to them. By dissecting emerging attack methods and exploitation techniques of threat actors, as well as conducting novel research, the team’s mission is to help organizations defend against identity threats.