mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-05 19:32:24 -08:00
Translated ['src/pentesting-cloud/azure-security/az-services/az-azuread.
This commit is contained in:
@@ -140,6 +140,34 @@ curl "$IDENTITY_ENDPOINT?resource=https://management.azure.com&api-version=2017-
|
||||
curl "$IDENTITY_ENDPOINT?resource=https://vault.azure.net&api-version=2017-09-01" -H secret:$IDENTITY_HEADER
|
||||
```
|
||||
{{#endtab }}
|
||||
{{#tab name="MS Graph" }}
|
||||
```bash
|
||||
Get-MgTenantRelationshipDelegatedAdminCustomer
|
||||
# Install the Microsoft Graph PowerShell module if not already installed
|
||||
Install-Module Microsoft.Graph -Scope CurrentUser
|
||||
|
||||
# Import the module
|
||||
Import-Module Microsoft.Graph
|
||||
|
||||
# Login to Microsoft Graph
|
||||
Connect-MgGraph -Scopes "User.Read.All", "Group.Read.All", "Directory.Read.All"
|
||||
|
||||
# Enumerate available commands in Microsoft Graph PowerShell
|
||||
Get-Command -Module Microsoft.Graph*
|
||||
|
||||
# Example: List users
|
||||
Get-MgUser -All
|
||||
|
||||
# Example: List groups
|
||||
Get-MgGroup -All
|
||||
|
||||
# Example: Get roles assigned to a user
|
||||
Get-MgUserAppRoleAssignment -UserId <UserId>
|
||||
|
||||
# Disconnect from Microsoft Graph
|
||||
Disconnect-MgGraph
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Azure AD" }}
|
||||
```bash
|
||||
@@ -156,9 +184,9 @@ Connect-AzureAD -AccountId test@corp.onmicrosoft.com -AadAccessToken $token
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
当您通过 **CLI** 登录 Azure 时,您使用的是属于 **Microsoft** 的 **租户** 中的 **Azure 应用程序**。这些应用程序,如您可以在您的帐户中创建的应用程序,**具有客户端 ID**。您 **无法看到所有的应用程序** 在控制台中可见的 **允许的应用程序列表** 中,**但它们默认是被允许的**。
|
||||
当您通过 **CLI** 登录 Azure 时,您使用的是属于 **Microsoft** 的 **租户** 中的 **Azure 应用程序**。这些应用程序,如您可以在您的帐户中创建的应用程序,**具有客户端 ID**。您 **无法看到所有这些应用程序** 在控制台中可见的 **允许的应用程序列表** 中,**但它们默认是被允许的**。
|
||||
|
||||
例如,一个 **powershell 脚本** 通过客户端 ID **`1950a258-227b-4e31-a9cf-717495945fc2`** 进行 **身份验证** 的应用程序。即使该应用程序未出现在控制台中,系统管理员仍然可以 **阻止该应用程序**,以便用户无法使用通过该应用程序连接的工具访问。
|
||||
例如,一个 **powershell 脚本** 通过客户端 ID **`1950a258-227b-4e31-a9cf-717495945fc2`** 使用一个应用程序进行 **身份验证**。即使该应用程序未出现在控制台中,系统管理员仍然可以 **阻止该应用程序**,以便用户无法使用通过该应用程序连接的工具访问。
|
||||
|
||||
然而,还有 **其他客户端 ID** 的应用程序 **将允许您连接到 Azure**:
|
||||
```bash
|
||||
@@ -248,6 +276,34 @@ curl -X GET "https://graph.microsoft.com/beta/roleManagement/directory/roleDefin
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="MS Graph" }}
|
||||
```bash
|
||||
# Enumerate users using Microsoft Graph PowerShell
|
||||
Get-MgUser -All
|
||||
|
||||
# Get user details
|
||||
Get-MgUser -UserId "test@corp.onmicrosoft.com" | Format-List *
|
||||
|
||||
# Search "admin" users
|
||||
Get-MgUser -All | Where-Object { $_.DisplayName -like "*test*" } | Select-Object DisplayName
|
||||
|
||||
# Search attributes containing the word "password"
|
||||
Get-MgUser -All | Where-Object { $_.AdditionalProperties.PSObject.Properties.Name -contains "password" }
|
||||
|
||||
# All users from Entra ID
|
||||
Get-MgUser -Filter "startswith(userPrincipalName, 't')" -All | Select-Object DisplayName, UserPrincipalName
|
||||
|
||||
# Get groups where the user is a member
|
||||
Get-MgUserMemberOf -UserId <UserId>
|
||||
|
||||
# Get roles assigned to the user in Entra ID
|
||||
Get-MgUserAppRoleAssignment -UserId <UserId>
|
||||
|
||||
# List available commands in Microsoft Graph PowerShell
|
||||
Get-Command -Module Microsoft.Graph.Users
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Azure AD" }}
|
||||
```bash
|
||||
# Enumerate Users
|
||||
@@ -309,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
|
||||
@@ -368,7 +424,33 @@ Get-AzADGroupMember -GroupDisplayName <resource_group_name>
|
||||
Get-AzRoleAssignment -ResourceGroupName <resource_group_name>
|
||||
```
|
||||
{{#endtab }}
|
||||
{{#tab name="MS Graph" }}
|
||||
```bash
|
||||
# Enumerate groups using Microsoft Graph PowerShell
|
||||
Get-MgGroup -All
|
||||
|
||||
# Get group details
|
||||
Get-MgGroup -GroupId <GroupId> | Format-List *
|
||||
|
||||
# Search "admin" groups
|
||||
Get-MgGroup -All | Where-Object { $_.DisplayName -like "*admin*" } | Select-Object DisplayName
|
||||
|
||||
# Get members of a group
|
||||
Get-MgGroupMember -GroupId <GroupId> -All
|
||||
|
||||
# Get groups a group is member of
|
||||
Get-MgGroupMemberOf -GroupId <GroupId>
|
||||
|
||||
# Get roles assigned to the group in Entra ID
|
||||
Get-MgGroupAppRoleAssignment -GroupId <GroupId>
|
||||
|
||||
# Get group owner
|
||||
Get-MgGroupOwner -GroupId <GroupId>
|
||||
|
||||
# List available commands in Microsoft Graph PowerShell
|
||||
Get-Command -Module Microsoft.Graph.Groups
|
||||
```
|
||||
{{#endtab }}
|
||||
{{#tab name="Azure AD" }}
|
||||
```bash
|
||||
# Enumerate Groups
|
||||
@@ -400,7 +482,7 @@ Get-AzureADGroup -ObjectId <id> | Get-AzureADGroupAppRoleAssignment | fl *
|
||||
|
||||
#### 将用户添加到组
|
||||
|
||||
组的所有者可以将新用户添加到组中
|
||||
组的拥有者可以将新用户添加到组中
|
||||
```bash
|
||||
Add-AzureADGroupMember -ObjectId <group_id> -RefObjectId <user_id> -Verbose
|
||||
```
|
||||
@@ -467,6 +549,30 @@ Headers = @{
|
||||
(Invoke-RestMethod @RequestParams).value
|
||||
```
|
||||
{{#endtab }}
|
||||
{{#tab name="MS Graph" }}
|
||||
```bash
|
||||
# Get Service Principals using Microsoft Graph PowerShell
|
||||
Get-MgServicePrincipal -All
|
||||
|
||||
# Get details of one Service Principal
|
||||
Get-MgServicePrincipal -ServicePrincipalId <ServicePrincipalId> | Format-List *
|
||||
|
||||
# Search SP by display name
|
||||
Get-MgServicePrincipal -All | Where-Object { $_.DisplayName -like "*app*" } | Select-Object DisplayName
|
||||
|
||||
# Get owner of Service Principal
|
||||
Get-MgServicePrincipalOwner -ServicePrincipalId <ServicePrincipalId>
|
||||
|
||||
# Get objects owned by a Service Principal
|
||||
Get-MgServicePrincipalOwnedObject -ServicePrincipalId <ServicePrincipalId>
|
||||
|
||||
# Get groups where the SP is a member
|
||||
Get-MgServicePrincipalMemberOf -ServicePrincipalId <ServicePrincipalId>
|
||||
|
||||
# List available commands in Microsoft Graph PowerShell
|
||||
Get-Command -Module Microsoft.Graph.ServicePrincipals
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Azure AD" }}
|
||||
```bash
|
||||
@@ -490,7 +596,12 @@ Get-AzureADServicePrincipal -ObjectId <id> | Get-AzureADServicePrincipalMembersh
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
> [!WARNING
|
||||
> [!WARNING]
|
||||
> 服务主体的所有者可以更改其密码。
|
||||
|
||||
<details>
|
||||
|
||||
<summary>列出并尝试在每个企业应用上添加客户端密钥</summary>
|
||||
```bash
|
||||
# Just call Add-AzADAppSecret
|
||||
Function Add-AzADAppSecret
|
||||
@@ -606,7 +717,7 @@ Write-Output "Failed to Enumerate the Applications."
|
||||
当应用程序生成时,会授予两种类型的权限:
|
||||
|
||||
- **权限** 授予 **服务主体**
|
||||
- **权限** 应用程序可以在 **用户** 的 **名义** 下拥有和使用。
|
||||
- **权限** 应用程序可以在 **用户的代表** 下拥有和使用。
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="az cli" }}
|
||||
@@ -640,6 +751,25 @@ Get-AzADAppCredential
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="MS Graph" }}
|
||||
```bash
|
||||
# List Applications using Microsoft Graph PowerShell
|
||||
Get-MgApplication -All
|
||||
|
||||
# Get application details
|
||||
Get-MgApplication -ApplicationId 7861f72f-ad49-4f8c-96a9-19e6950cffe1 | Format-List *
|
||||
|
||||
# Search App by display name
|
||||
Get-MgApplication -Filter "startswith(displayName, 'app')" | Select-Object DisplayName
|
||||
|
||||
# Get owner of an application
|
||||
Get-MgApplicationOwner -ApplicationId <ApplicationId>
|
||||
|
||||
# List available commands in Microsoft Graph PowerShell
|
||||
Get-Command -Module Microsoft.Graph.Applications
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Azure AD" }}
|
||||
```bash
|
||||
# List all registered applications
|
||||
@@ -714,7 +844,27 @@ az role assignment list --all --query "[].{principalName:principalName,principal
|
||||
# Get all the roles assigned to a user
|
||||
az role assignment list --assignee "<email>" --all --output table
|
||||
# Get all the roles assigned to a user by filtering
|
||||
az role assignment list --all --query "[?principalName=='carlos@carloshacktricks.onmicrosoft.com']" --output table
|
||||
az role assignment list --all --query "[?principalName=='admin@organizationadmin.onmicrosoft.com']" --output table
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="MS Graph" }}
|
||||
```bash
|
||||
|
||||
# List all available role templates using Microsoft Graph PowerShell
|
||||
Get-MgDirectoryRoleTemplate -All
|
||||
|
||||
# List enabled built-in Entra ID roles
|
||||
Get-MgDirectoryRole -All
|
||||
|
||||
# List all Entra ID roles with their permissions (including custom roles)
|
||||
Get-MgDirectoryRoleDefinition -All
|
||||
|
||||
# List members of a Entra ID role
|
||||
Get-MgDirectoryRoleMember -DirectoryRoleId <RoleId> -All
|
||||
|
||||
# List available commands in Microsoft Graph PowerShell
|
||||
Get-Command -Module Microsoft.Graph.Identity.DirectoryManagement
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
@@ -828,6 +978,24 @@ Get-AzureADMSScopedRoleMembership -Id <id> | fl *
|
||||
# If you know how to do this send a PR!
|
||||
```
|
||||
{{#endtab }}
|
||||
{{#tab name="MS Graph" }}
|
||||
```bash
|
||||
# Enumerate devices using Microsoft Graph PowerShell
|
||||
Get-MgDevice -All
|
||||
|
||||
# Get device details
|
||||
Get-MgDevice -DeviceId <DeviceId> | Format-List *
|
||||
|
||||
# Get devices managed using 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
|
||||
Get-Command -Module Microsoft.Graph.Identity.DirectoryManagement
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Azure AD" }}
|
||||
```bash
|
||||
@@ -908,9 +1076,9 @@ Get-AzureADMSScopedRoleMembership -Id <id> | fl #Get role ID and role members
|
||||
|
||||
### 特权身份管理 (PIM)
|
||||
|
||||
Azure 中的特权身份管理 (PIM) 有助于 **防止不必要地将过多的权限** 分配给用户。
|
||||
Azure 中的特权身份管理 (PIM) 有助于 **防止不必要地将过多特权** 分配给用户。
|
||||
|
||||
PIM 提供的主要功能之一是,它允许不将角色分配给持续活跃的主体,而是使其 **在一段时间内有资格(例如 6 个月)**。然后,每当用户想要激活该角色时,他需要请求并指明他需要该权限的时间(例如 3 小时)。然后 **管理员需要批准** 该请求。\
|
||||
PIM 提供的主要功能之一是,它允许不将角色分配给持续活跃的主体,而是使其在 **一段时间内(例如 6 个月)** 具备资格。然后,每当用户想要激活该角色时,他需要请求并指明他需要特权的时间(例如 3 小时)。然后 **管理员需要批准** 该请求。\
|
||||
请注意,用户还可以请求 **延长** 时间。
|
||||
|
||||
此外,**PIM 会在特权角色被分配给某人时发送电子邮件**。
|
||||
@@ -926,7 +1094,7 @@ PIM 提供的主要功能之一是,它允许不将角色分配给持续活跃
|
||||
- 激活时需要票据信息
|
||||
- 激活时需要批准
|
||||
- 过期的合格分配的最大时间
|
||||
- 还有更多关于何时以及向谁发送通知的配置,当该角色发生某些操作时
|
||||
- 还有更多关于何时以及谁在某些操作发生时发送通知的配置
|
||||
|
||||
### 条件访问策略
|
||||
|
||||
|
||||
Reference in New Issue
Block a user