From ad4b8a4f01fd9d85e5969e8fbb8f492da1b73a20 Mon Sep 17 00:00:00 2001 From: Translator Date: Sun, 9 Feb 2025 17:53:30 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/azure-security/az-services/az-azuread. --- .../azure-security/az-services/az-azuread.md | 184 ++++++++++-------- 1 file changed, 105 insertions(+), 79 deletions(-) diff --git a/src/pentesting-cloud/azure-security/az-services/az-azuread.md b/src/pentesting-cloud/azure-security/az-services/az-azuread.md index ceeb5ca2f..1cf1a107a 100644 --- a/src/pentesting-cloud/azure-security/az-services/az-azuread.md +++ b/src/pentesting-cloud/azure-security/az-services/az-azuread.md @@ -4,7 +4,7 @@ ## 基本信息 -Azure Active Directory (Azure AD) 是微软的基于云的身份和访问管理服务。它在使员工能够登录并访问资源方面发挥着重要作用,这些资源包括组织内部和外部的 Microsoft 365、Azure 门户以及众多其他 SaaS 应用程序。Azure AD 的设计重点在于提供基本的身份服务,尤其包括 **身份验证、授权和用户管理**。 +Azure Active Directory (Azure AD) 是微软基于云的身份和访问管理服务。它在使员工能够登录并访问资源方面发挥着重要作用,这些资源包括组织内部和外部的 Microsoft 365、Azure 门户以及众多其他 SaaS 应用程序。Azure AD 的设计重点在于提供基本的身份服务,尤其包括 **身份验证、授权和用户管理**。 Azure AD 的关键特性包括 **多因素身份验证** 和 **条件访问**,以及与其他 Microsoft 安全服务的无缝集成。这些特性显著提升了用户身份的安全性,并使组织能够有效实施和执行其访问政策。作为微软云服务生态系统的基本组成部分,Azure AD 对于基于云的用户身份管理至关重要。 @@ -186,7 +186,7 @@ Connect-AzureAD -AccountId test@corp.onmicrosoft.com -AadAccessToken $token 当您通过 **CLI** 登录 Azure 时,您使用的是属于 **Microsoft** 的 **租户** 中的 **Azure 应用程序**。这些应用程序,如您可以在您的帐户中创建的应用程序,**具有客户端 ID**。您 **无法看到所有这些应用程序** 在控制台中可见的 **允许的应用程序列表** 中,**但它们默认是被允许的**。 -例如,一个 **powershell 脚本** 通过客户端 ID **`1950a258-227b-4e31-a9cf-717495945fc2`** 使用一个应用程序进行 **身份验证**。即使该应用程序未出现在控制台中,系统管理员仍然可以 **阻止该应用程序**,以便用户无法使用通过该应用程序连接的工具访问。 +例如,一个 **powershell 脚本** 通过客户端 ID **`1950a258-227b-4e31-a9cf-717495945fc2`** 进行 **身份验证** 的应用程序。即使该应用程序未出现在控制台中,系统管理员仍然可以 **阻止该应用程序**,以便用户无法使用通过该应用程序连接的工具访问。 然而,还有 **其他客户端 ID** 的应用程序 **将允许您连接到 Azure**: ```bash @@ -365,7 +365,7 @@ $password = "ThisIsTheNewPassword.!123" | ConvertTo- SecureString -AsPlainText ``` ### MFA & Conditional Access Policies -强烈建议为每个用户添加 MFA,然而,一些公司可能不会设置它,或者可能会通过条件访问进行设置:用户在从特定位置、浏览器或 **某些条件** 登录时将 **被要求 MFA**。如果这些策略配置不正确,可能会容易受到 **绕过**。检查: +强烈建议为每个用户添加 MFA,然而,一些公司可能不会设置它,或者可能会通过条件访问进行设置:用户在特定位置、浏览器或 **某些条件** 下登录时将 **需要 MFA**。如果这些策略配置不正确,可能会容易受到 **绕过**。请检查: {{#ref}} ../az-privilege-escalation/az-entraid-privesc/az-conditional-access-policies-mfa-bypass.md @@ -717,7 +717,7 @@ Write-Output "Failed to Enumerate the Applications." 当应用程序生成时,会授予两种类型的权限: - **权限** 授予 **服务主体** -- **权限** 应用程序可以在 **用户的代表** 下拥有和使用。 +- **权限** 应用程序可以在 **用户** 的 **名义** 下拥有和使用。 {{#tabs }} {{#tab name="az cli" }} @@ -840,11 +840,15 @@ az role definition list --resource-group # Get only roles assigned to the indicated scope az role definition list --scope # Get all the principals a role is assigned to -az role assignment list --all --query "[].{principalName:principalName,principalType:principalType,resourceGroup:resourceGroup,roleDefinitionName:roleDefinitionName}[?roleDefinitionName=='']" +az role assignment list --all --query "[].{principalName:principalName,principalType:principalType,scope:scope,roleDefinitionName:roleDefinitionName}[?roleDefinitionName=='']" # Get all the roles assigned to a user az role assignment list --assignee "" --all --output table # Get all the roles assigned to a user by filtering az role assignment list --all --query "[?principalName=='admin@organizationadmin.onmicrosoft.com']" --output table +# Get deny assignments +az rest --method GET --uri "https://management.azure.com/{scope}/providers/Microsoft.Authorization/denyAssignments?api-version=2022-04-01" +## Example scope of subscription +az rest --method GET --uri "https://management.azure.com/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/providers/Microsoft.Authorization/denyAssignments?api-version=2022-04-01" ``` {{#endtab }} @@ -877,12 +881,20 @@ Get-AzRoleDefinition -Name "Virtual Machine Command Executor" # Get roles of a user or resource Get-AzRoleAssignment -SignInName test@corp.onmicrosoft.com Get-AzRoleAssignment -Scope /subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/ +# Get deny assignments +Get-AzDenyAssignment # Get from current subscription +Get-AzDenyAssignment -Scope '/subscriptions/96231a05-34ce-4eb4-aa6a-70759cbb5e83/resourcegroups/testRG/providers/Microsoft.Web/sites/site1' ``` +{{#endtab }} +{{#endtabs }} +``` + {{#endtab }} {{#tab name="Raw" }} + ```bash -# Get permissions over a resource using ARM directly +# 直接通过 ARM 获取资源的权限 $Token = (Get-AzAccessToken).Token $URI = 'https://management.azure.com/subscriptions/b413826f-108d-4049-8c11-d52d5d388768/resourceGroups/Research/providers/Microsoft.Compute/virtualMachines/infradminsrv/providers/Microsoft.Authorization/permissions?api-version=2015-07-01' $RequestParams = @{ @@ -894,12 +906,13 @@ Headers = @{ } (Invoke-RestMethod @RequestParams).value ``` + {{#endtab }} {{#endtabs }} -### Entra ID 角色 +### Entra ID Roles -有关 Azure 角色的更多信息,请查看: +For more information about Azure roles check: {{#ref}} ../az-basic-information/ @@ -907,125 +920,134 @@ Headers = @{ {{#tabs }} {{#tab name="az cli" }} + ```bash -# List template Entra ID roles +# 列出模板 Entra ID 角色 az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/directoryRoleTemplates" -# List enabled built-in Entra ID roles +# 列出启用的内置 Entra ID 角色 az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/directoryRoles" -# List all Entra ID roles with their permissions (including custom roles) +# 列出所有 Entra ID 角色及其权限(包括自定义角色) az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions" -# List only custom Entra ID roles +# 仅列出自定义 Entra ID 角色 az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions" | jq '.value[] | select(.isBuiltIn == false)' -# List all assigned Entra ID roles +# 列出所有分配的 Entra ID 角色 az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments" -# List members of a Entra ID roles +# 列出 Entra ID 角色的成员 az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/directoryRoles//members" -# List Entra ID roles assigned to a user +# 列出分配给用户的 Entra ID 角色 az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/users//memberOf/microsoft.graph.directoryRole" \ --query "value[]" \ --output json -# List Entra ID roles assigned to a group +# 列出分配给组的 Entra ID 角色 az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/groups/$GROUP_ID/memberOf/microsoft.graph.directoryRole" \ --query "value[]" \ --output json -# List Entra ID roles assigned to a service principal +# 列出分配给服务主体的 Entra ID 角色 az rest --method GET \ --uri "https://graph.microsoft.com/v1.0/servicePrincipals/$SP_ID/memberOf/microsoft.graph.directoryRole" \ --query "value[]" \ --output json ``` + {{#endtab }} {{#tab name="Azure AD" }} + ```bash -# Get all available role templates +# 获取所有可用的角色模板 Get-AzureADDirectoryroleTemplate -# Get enabled roles (Assigned roles) +# 获取启用的角色(分配的角色) Get-AzureADDirectoryRole -Get-AzureADDirectoryRole -ObjectId #Get info about the role -# Get custom roles - use AzureAdPreview +Get-AzureADDirectoryRole -ObjectId #获取角色信息 +# 获取自定义角色 - 使用 AzureAdPreview Get-AzureADMSRoleDefinition | ?{$_.IsBuiltin -eq $False} | select DisplayName -# Users assigned a role (Global Administrator) +# 被分配角色的用户(全局管理员) Get-AzureADDirectoryRole -Filter "DisplayName eq 'Global Administrator'" | Get-AzureADDirectoryRoleMember Get-AzureADDirectoryRole -ObjectId | fl -# Roles of the Administrative Unit (who has permissions over the administrative unit and its members) +# 行政单位的角色(谁对行政单位及其成员拥有权限) Get-AzureADMSScopedRoleMembership -Id | fl * ``` + {{#endtab }} {{#endtabs }} -### 设备 +### Devices {{#tabs }} {{#tab name="az cli" }} + ```bash -# If you know how to do this send a PR! +# 如果你知道如何做到这一点,请发送 PR! ``` + {{#endtab }} {{#tab name="MS Graph" }} + ```bash -# Enumerate devices using Microsoft Graph PowerShell +# 使用 Microsoft Graph PowerShell 枚举设备 Get-MgDevice -All -# Get device details +# 获取设备详细信息 Get-MgDevice -DeviceId | Format-List * -# Get devices managed using Intune +# 获取使用 Intune 管理的设备 Get-MgDevice -Filter "isCompliant eq true" -All -# Get devices owned by a user +# 获取用户拥有的设备 Get-MgUserOwnedDevice -UserId test@corp.onmicrosoft.com -# List available commands in Microsoft Graph PowerShell +# 列出 Microsoft Graph PowerShell 中可用的命令 Get-Command -Module Microsoft.Graph.Identity.DirectoryManagement ``` {{#endtab }} {{#tab name="Azure AD" }} + ```bash -# Enumerate Devices +# 枚举设备 Get-AzureADDevice -All $true | fl * -# List all the active devices (and not the stale devices) +# 列出所有活动设备(而不是过时设备) Get-AzureADDevice -All $true | ?{$_.ApproximateLastLogonTimeStamp -ne $null} -# Get owners of all devices +# 获取所有设备的所有者 Get-AzureADDevice -All $true | Get-AzureADDeviceRegisteredOwner Get-AzureADDevice -All $true | %{if($user=Get-AzureADDeviceRegisteredOwner -ObjectId $_.ObjectID){$_;$user.UserPrincipalName;"`n"}} -# Registred users of all the devices +# 所有设备的注册用户 Get-AzureADDevice -All $true | Get-AzureADDeviceRegisteredUser Get-AzureADDevice -All $true | %{if($user=Get-AzureADDeviceRegisteredUser -ObjectId $_.ObjectID){$_;$user.UserPrincipalName;"`n"}} -# Get dives managed using Intune +# 获取使用 Intune 管理的设备 Get-AzureADDevice -All $true | ?{$_.IsCompliant -eq "True"} -# Get devices owned by a user +# 获取用户拥有的设备 Get-AzureADUserOwnedDevice -ObjectId test@corp.onmicrosoft.com -# Get Administrative Units of a device +# 获取设备的管理单位 Get-AzureADMSAdministrativeUnit | where { Get-AzureADMSAdministrativeUnitMember -ObjectId $_.ObjectId | where {$_.ObjectId -eq $deviceObjId} } ``` + {{#endtab }} {{#endtabs }} > [!WARNING] -> 如果设备(虚拟机)是 **AzureAD 加入**,来自 AzureAD 的用户将能够 **登录**。\ -> 此外,如果登录的用户是设备的 **所有者**,他将成为 **本地管理员**。 +> If a device (VM) is **AzureAD joined**, users from AzureAD are going to be **able to login**.\ +> Moreover, if the logged user is **Owner** of the device, he is going to be **local admin**. -### 管理单位 +### Administrative Units -有关管理单位的更多信息,请查看: +For more information about administrative units check: {{#ref}} ../az-basic-information/ @@ -1033,100 +1055,104 @@ Get-AzureADMSAdministrativeUnit | where { Get-AzureADMSAdministrativeUnitMember {{#tabs }} {{#tab name="az cli" }} + ```bash -# List all administrative units +# 列出所有管理单位 az rest --method GET --uri "https://graph.microsoft.com/v1.0/directory/administrativeUnits" -# Get AU info +# 获取 AU 信息 az rest --method GET --uri "https://graph.microsoft.com/v1.0/directory/administrativeUnits/a76fd255-3e5e-405b-811b-da85c715ff53" -# Get members +# 获取成员 az rest --method GET --uri "https://graph.microsoft.com/v1.0/directory/administrativeUnits/a76fd255-3e5e-405b-811b-da85c715ff53/members" -# Get principals with roles over the AU +# 获取 AU 上具有角色的主体 az rest --method GET --uri "https://graph.microsoft.com/v1.0/directory/administrativeUnits/a76fd255-3e5e-405b-811b-da85c715ff53/scopedRoleMembers" ``` + {{#endtab }} {{#tab name="AzureAD" }} + ```bash -# Get Administrative Units +# 获取管理单位 Get-AzureADMSAdministrativeUnit Get-AzureADMSAdministrativeUnit -Id -# Get ID of admin unit by string +# 通过字符串获取管理员单位的ID $adminUnitObj = Get-AzureADMSAdministrativeUnit -Filter "displayname eq 'Test administrative unit 2'" -# List the users, groups, and devices affected by the administrative unit +# 列出受管理单位影响的用户、组和设备 Get-AzureADMSAdministrativeUnitMember -Id -# Get the roles users have over the members of the AU -Get-AzureADMSScopedRoleMembership -Id | fl #Get role ID and role members +# 获取用户对AU成员的角色 +Get-AzureADMSScopedRoleMembership -Id | fl #获取角色ID和角色成员 ``` + {{#endtab }} {{#endtabs }} -## Entra ID 特权升级 +## Entra ID Privilege Escalation {{#ref}} ../az-privilege-escalation/az-entraid-privesc/ {{#endref}} -## Azure 特权升级 +## Azure Privilege Escalation {{#ref}} ../az-privilege-escalation/az-authorization-privesc.md {{#endref}} -## 防御机制 +## Defensive Mechanisms -### 特权身份管理 (PIM) +### Privileged Identity Management (PIM) -Azure 中的特权身份管理 (PIM) 有助于 **防止不必要地将过多特权** 分配给用户。 +Privileged Identity Management (PIM) in Azure helps to **prevent excessive privileges** to being assigned to users unnecessarily. -PIM 提供的主要功能之一是,它允许不将角色分配给持续活跃的主体,而是使其在 **一段时间内(例如 6 个月)** 具备资格。然后,每当用户想要激活该角色时,他需要请求并指明他需要特权的时间(例如 3 小时)。然后 **管理员需要批准** 该请求。\ -请注意,用户还可以请求 **延长** 时间。 +One of the main features provided by PIM is that It allows to not assign roles to principals that are constantly active, but make them **eligible for a period of time (e.g. 6months)**. Then, whenever the user wants to activate that role, he needs to ask for it indicating the time he needs the privilege (e.g. 3 hours). Then an **admin needs to approve** the request.\ +Note that the user will also be able to ask to **extend** the time. -此外,**PIM 会在特权角色被分配给某人时发送电子邮件**。 +Moreover, **PIM send emails** whenever a privileged role is being assigned to someone.
-启用 PIM 后,可以为每个角色配置某些要求,例如: +When PIM is enabled it's possible to configure each role with certain requirements like: -- 激活的最大持续时间(小时) -- 激活时需要 MFA -- 需要条件访问身份验证上下文 -- 激活时需要理由 -- 激活时需要票据信息 -- 激活时需要批准 -- 过期的合格分配的最大时间 -- 还有更多关于何时以及谁在某些操作发生时发送通知的配置 +- Maximum duration (hours) of activation +- Require MFA on activation +- Require Conditional Access acuthenticaiton context +- Require justification on activation +- Require ticket information on activation +- Require approval to activate +- Max time to expire the elegible assignments +- A lot more configuration on when and who to send notifications when certain actions happen with that role -### 条件访问策略 +### Conditional Access Policies -检查: +Check: {{#ref}} ../az-privilege-escalation/az-entraid-privesc/az-conditional-access-policies-mfa-bypass.md {{#endref}} -### Entra 身份保护 +### Entra Identity Protection -Entra 身份保护是一项安全服务,允许 **检测用户或登录尝试的风险过高**,从而 **阻止** 用户或登录尝试。 +Entra Identity Protection is a security service that allows to **detect when a user or a sign-in is too risky** to be accepted, allowing to **block** the user or the sig-in attempt. -它允许管理员配置在风险为“低及以上”、“中等及以上”或“高”时 **阻止** 尝试。尽管默认情况下它是完全 **禁用** 的: +It allows the admin to configure it to **block** attempts when the risk is "Low and above", "Medium and above" or "High". Although, by default it's completely **disabled**:
> [!TIP] -> 目前建议通过条件访问策略添加这些限制,在那里可以配置相同的选项。 +> Nowadays it's recommended to add these restrictions via Conditional Access policies where it's possible to configure the same options. -### Entra 密码保护 +### Entra Password Protection -Entra 密码保护 ([https://portal.azure.com/index.html#view/Microsoft_AAD_ConditionalAccess/PasswordProtectionBlade](https://portal.azure.com/#view/Microsoft_AAD_ConditionalAccess/PasswordProtectionBlade)) 是一项安全功能,**通过在多次登录尝试失败时锁定帐户来帮助防止弱密码的滥用**。\ -它还允许 **禁止自定义密码列表**,该列表需要您提供。 +Entra Password Protection ([https://portal.azure.com/index.html#view/Microsoft_AAD_ConditionalAccess/PasswordProtectionBlade](https://portal.azure.com/#view/Microsoft_AAD_ConditionalAccess/PasswordProtectionBlade)) is a security feature that **helps prevent the abuse of weak passwords in by locking out accounts when several unsuccessful login attempts happen**.\ +It also allows to **ban a custom password list** that you need to provide. -它可以 **同时应用于** 云级别和本地 Active Directory。 +It can be **applied both** at the cloud level and on-premises Active Directory. -默认模式是 **审核**: +The default mode is **Audit**:
-## 参考 +## References - [https://learn.microsoft.com/en-us/azure/active-directory/roles/administrative-units](https://learn.microsoft.com/en-us/azure/active-directory/roles/administrative-units)