Andy Robbins Profile picture
Sep 20 25 tweets 8 min read
#Azure Managed Identity assignments are "secure by default."

Dangerous attack paths can emerge around these assignments.

Here's those attack paths emerge, how attackers abuse them, and how defenders can eliminate them: 🧵
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 creds:
This problem is not new and not surprising to many people:
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 creds then get a token via STS:
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:
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.
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:
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:
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:
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:
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:
Step 3: Use ServicePrincipalC's JWT to add a new evil runbook to the Automation Account, then retrieve the output of that function:
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: medium.com/p/210ae2be2a5
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:
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:
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:
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:
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:
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:

BARK: github.com/BloodHoundAD/B…
BloodHound: github.com/BloodHoundAD/B…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Andy Robbins

Andy Robbins Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @_wald0

Sep 13
Tiered Administration is among the strongest security controls that exist.

But the vast majority of organizations do not use it.

Here is how you can get started using Tiered Administration TODAY in your #Azure environments: 🧵
First, understand the problem we are trying to solve with Tiered Administration:

Tiered Administration protects your most privileged assets from compromise in the event that less privileged assets are compromised.

It's the wombo combo of least privilege and defense in depth.
Do Tiered Administration effectively and you DRAMATICALLY reduce risks posed by ransomware actors, insider threats, etc.

Most efforts get stuck in the very first step: identifying which assets go into which tiers.

Here's how you do this:
Read 11 tweets
Aug 25
How to prevent Kerberoasting:

Kerberoasting is an incredibly powerful and reliable attack against Active Directory. In some situations it can result in an attacker becoming Domain Admin nearly instantaneously.

Here's how to prevent this attack: 🧵 Image
First we need to identify Active Directory users that are "kerberoastable" - possible targets for the attacker to choose to Kerberoast.

Kerberoast relies on a user having some value in their "serviceprincipalnames" attribute.

Find all of them instantly with no 3rd party tools:
dsquery has been built in to Windows Server since Server 2008. You also get it when installing RSAT.

Here's the command:

dsquery * "dc=contoso,dc=com" -filter "(&(objectcategory=user)(servicePrincipalName=*))" -attr distinguishedName servicePrincipalName
Read 12 tweets
Aug 8
Take a close look at BARK's functions and you will see that most of them are simple wrappers around basic REST API calls. This means it's very easy to extend BARK.

For example, BARK is missing a function to list virtual machines. Here's how easy this is to add: 🧵
Let's look at an existing function that lists objects in AzureRM, "Get-AllAzureRMResourceGroups":
The most "difficult" line we need to change is line 24. We must ensure we are hitting the right URL.

The Microsoft documentation can help us here. We will Google "azure api list virtual machines", and the first result is this page:

docs.microsoft.com/en-us/rest/api…
Read 7 tweets
Aug 8
Problem: you want to collect data with AzureHound but you can't use simple username/password because your user:

❌ - Requires MFA
❌ - Can't auth due to a CAP
❌ - Is a guest/federated user in the target tenant

Solution: refresh tokens! Sounds scary and new? They're EASY: 🧵
There are MANY ways to get your hands on a refresh token, but I think by far the simplest is by using the OAuth 2.0 device code flow.

Sounds complicated but it's a very easy three-step process:
Step 1: initialize a device code authentication flow with this very simple POST request.

Note the "user_code" and "verification_url" we get back:
Read 6 tweets
Aug 6
From initial access to Global Admin with #BloodHound and BARK.

In this thread let's walk, step by step, through an example attack path based on real configurations we've seen in real environments:
There are MANY ways to achieve initial access into AzureAD. For this example we will go with something simple: we were able to phish a user and get their username and clear text password.

This user has no MFA/CAP restrictions - we'll discuss how to deal with these later.
We now want to collect data with AzureHound. We'll clone the repo, inspect the source code, then build the binary ourselves:

$ git clone github.com/BloodHoundAD/A…
$ cd AzureHound
$ go build .
Read 22 tweets
Jun 24
If you're like me, you are angry and disappointed at SCOTUS striking down Roe v Wade. You might also be exhausted and feel defeated.

Here are three things you can do RIGHT NOW to help defend women's rights in the United States. This will take you THREE minutes. Do these NOW: 🧵
First and most importantly, contact your congressional rep and tell them you support the Women's Health Protection Act, which will protect abortion access for every person in every state.

THIS FORM TAKES 30 SECONDS TO COMPLETE: actforwomen.org/take-action/
Second, contact your healthcare provider and ask them to do the same thing. Lawmakers need to hear from healthcare professionals that abortion is safe, abortion is normal, and that abortion is health care.

EMAIL THIS LINK TO YOUR DOCTOR: secure.everyaction.com/p/QCHf7o5do0Sn…
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(