Azure Managed Identities: "Secure by Default"?, and yet...

Azure Managed Identities: "Secure by Default", and yet...

First we should understand what Managed Identities are. I think the best way is to understand the problem they are designed to solve.

We have a great recent example of this problem from the alleged Uber breach, where a PowerShell script may have been storing plain text credentials:

No alt text provided for this image

This problem is not new and not surprising to many people, as the results of this poll show:

Managed Identities are an effective answer to this problem for many scenarios. For example, say we have an Azure Virtual Machine using plain text credentials to perform some privileged task in Azure.

The process will read the credentials then get a token via STS:

No alt text provided for this image

The major risk here is that the username/password combo can be stored insecurely somewhere outside the VM, then stolen and used by an attacker for some nefarious purpose.

Managed Identities eliminate this risk while offering a familiar, low-friction authentication flow:

No alt text provided for this image

The Virtual Machine itself becomes the entity able to authenticate as the Service Principal, and it does this via its local Instance Metadata Service (IMDS).

This local service is not authenticated and any process on the VM can interact with it to request tokens for the SP:

No alt text provided for this image

This is "secure by default" and no risk exists because we haven't given the Service Principal any privileges yet.

But if you've gone through the trouble of configuring this, don't you think that Service Principal is going to need some privilege?

Let's say we give the SP "Subscription Owner", but that only a Global Admin can access the VM.

In that case, who cares? A Global Admin is already all-powerful, so no privilege escalation opportunity exists:

No alt text provided for this image

Dangerous attack paths emerge when the user with access to the VM has less privilege than the SP associated with the VM via a Managed Identity assignment:

No alt text provided for this image

Doubt this configuration would ever exist in the real world? We've seen it.

Don't just take my word for it. Read the replies to this to get an idea of what madness exists in the real world:

How do attackers abuse Managed Identity attack paths? Let's see three quick examples based on this overall attack path that mirrors different configurations we have observed in real environments:

No alt text provided for this image

Step 1: compromise User A and RDP into the Virtual Machine. Use our access to request a token for Service Principal B via the IMDS:

No alt text provided for this image

Step 2: Use the JWT for ServicePrincipalB to add a new evil function to the Function App. Fetch the Function App master key, then use the master key to retrieve the output of that function:

No alt text provided for this image

Step 3: Use ServicePrincipalC's JWT to add a new evil runbook to the Automation Account, then retrieve the output of that function:

No alt text provided for this image

The resulting token at the end of this attack path is for ServicePrincipalE, which is a Privileged Role Admin at the tenant. This is a Tier Zero role which allows escalation to Global Admin:

Admins need to audit for and eliminate these attack paths. Here's how:

Let's genericize the attack path and see it like this, where the SP has some sort of Tier Zero level of privilege:

No alt text provided for this image

Your first and most important step: identify any service principals with Tier Zero privileges.

You can easily discover all Service Principals with Tier Zero rights using BARK's Get-TierZeroServicePrincipals:

No alt text provided for this image

This function finds all service principals with the following privileges that are definitively Tier Zero:

  • Global Admin
  • Privileged Role Admin
  • Privileged Auth Admin
  • Partner Tier2 Support
  • RoleManagement.ReadWrite.Directory
  • AppRoleAssignment.ReadWrite.All

No results? Great! Keep it that way by periodically running that function and KEEPING the results empty.

If you have results, try to get rid of those privileges! This is where you will have the LARGEST positive impact on reducing attack paths with the LEAST amount of work.

Maybe you can't get rid of that privilege for that SP. That's valid.

Your next step is to enumerate all of the AzureRM resources with Managed Identity assignments.

You can do this with BARK's Get-AllAzureManagedIdentityAssignments:

No alt text provided for this image

Now compare the list of Tier Zero SPs to the list of Managed Identity SPs and see if there is any crossover.

There are many ways to do this, here's how to do this with PowerShell:

No alt text provided for this image

See results? Try to get rid of them! This will likely be more difficult than removing the SP's privileges, but is WAY easier than your next step...

Your next step is to audit who has control of the various AzureRM resources with Managed Identity assignments. This gets very complicated very quickly.

You can use #FOSS BloodHound to audit who controls any given AzureRM resource:

No alt text provided for this image

See results? Good luck. You need to compare the privileges held by each of those principals with the privileges held by the Tier Zero SP.

In other words, the Azure resource is now Tier Zero and must only be controllable by other Tier Zero principals.

All tools used in this thread are free and open source software:

要查看或添加评论,请登录

Andy Robbins的更多文章

  • How to Easily Identity Tier Zero Azure Assets

    How to Easily Identity Tier Zero Azure Assets

    First, you need to understand the problem we are trying to solve with Tiered Administration. Tiered Administration…

    2 条评论
  • Emergent Cloud Trust

    Emergent Cloud Trust

    Yesterday in my webinar on ACR Task abuse, I shared this slide with the question, "What privileges are needed to bridge…

  • Six Degrees of Global Admin at Nullcon

    Six Degrees of Global Admin at Nullcon

    In Windows and Active Directory, there is one system responsible for making access decisions in nearly *all* cases: the…

  • The Enormous Impact of New Abuse Primitives

    The Enormous Impact of New Abuse Primitives

    New abuse primitives that take advantage of legitimate administrative protocols and features are wildly exciting. Why?…

  • The Unexpected Impact of 3 New BloodHound Edges

    The Unexpected Impact of 3 New BloodHound Edges

    In the upcoming #BloodHound 4.1 release, we are introducing 3 new edges.

    7 条评论
  • Find and Fix These Three Common AD Issues

    Find and Fix These Three Common AD Issues

    Here are three of the most common issues BloodHound Enterprise finds, their impacts, and how you can use FOSS…

    3 条评论
  • Three Reasons Why We Need Empirical Security

    Three Reasons Why We Need Empirical Security

    What’s the problem? Administrators and security professionals have been dealing with a lot of bullshit for the last…

    1 条评论
  • Like it or not: Active Directory is here to stay

    Like it or not: Active Directory is here to stay

    Amidst the recent spike in ransomware events (or coverage), PrintNightmare, and our own work and research into how…

    8 条评论
  • It's time to stop ignoring prevention.

    It's time to stop ignoring prevention.

    Point #1: Red teamers know how year after year the same tools and methodologies can be used to take over almost any…

    1 条评论

社区洞察

其他会员也浏览了