diff --git a/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-cloud-sync.md b/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-cloud-sync.md index 77cb0207d..e6b8b3a82 100644 --- a/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-cloud-sync.md +++ b/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-cloud-sync.md @@ -5,30 +5,30 @@ ## 基本信息 -**Cloud Sync** 基本上是 Azure 将 **用户从 AD 同步到 Entra ID** 的新方式。 +**Cloud Sync** 基本上是 Azure 将 AD 的用户 **synchronize the users from AD into Entra ID** 的新方式。 -[From the docs:](https://learn.microsoft.com/en-us/entra/identity/hybrid/cloud-sync/what-is-cloud-sync) Microsoft Entra Cloud Sync 是 Microsoft 提供的一项新服务,旨在实现用于将用户、组和联系人同步到 Microsoft Entra ID 的混合身份目标。它通过使用 Microsoft Entra cloud provisioning agent 而不是 Microsoft Entra Connect 应用来实现这一点。不过,它可以与 Microsoft Entra Connect Sync 一起使用。 +[From the docs:](https://learn.microsoft.com/en-us/entra/identity/hybrid/cloud-sync/what-is-cloud-sync) 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 和本地目录中创建一些主体: - 在 Entra ID 中会创建用户 `On-Premises Directory Synchronization Service Account` (`ADToAADSyncServiceAccount@carloshacktricks.onmicrosoft.com`),并赋予角色 **`Directory Synchronization Accounts`** (`d29b2b05-8046-44ba-8758-1e26182fcf32`)。 > [!WARNING] -> 该角色曾拥有很多特权权限,且可能被用于 [**escalate privileges even to global admin**](https://medium.com/tenable-techblog/stealthy-persistence-with-directory-synchronization-accounts-role-in-entra-id-63e56ce5871b)。但 Microsoft 后来决定移除该角色的所有特权,并仅分配一个新的 **`microsoft.directory/onPremisesSynchronization/standard/read`**,该权限并不真正允许执行任何特权操作(例如修改用户密码或属性,或向 SP 添加新凭据)。 +> This role used to have a lot of privileged permissions and it could be used to [**escalate privileges even to global admin**](https://medium.com/tenable-techblog/stealthy-persistence-with-directory-synchronization-accounts-role-in-entra-id-63e56ce5871b). However, Microsoft decided to remove all the privileges of this role and assign it just a new one **`microsoft.directory/onPremisesSynchronization/standard/read`** which 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`](./az-domain-services.md),该组会很有用。 -- 在 AD 中,要么创建 Service Account **`provAgentgMSA`**,其 SamAccountName 类似 **`pGMSA_$@domain.com`**(`Get-ADServiceAccount -Filter * | Select Name,SamAccountName`),要么创建一个自定义账号,需具备 [**these permissions is needed**](https://learn.microsoft.com/en-us/entra/identity/hybrid/cloud-sync/how-to-prerequisites?tabs=public-cloud#custom-gmsa-account)。通常会创建默认的那个。 +- 在 AD 中,通常会创建 Service Account **`provAgentgMSA`**,其 SamAcountName 类似 **`pGMSA_$@domain.com`**(`Get-ADServiceAccount -Filter * | Select Name,SamAccountName`),或者使用自定义账号(需要 [**these permissions is needed**](https://learn.microsoft.com/en-us/entra/identity/hybrid/cloud-sync/how-to-prerequisites?tabs=public-cloud#custom-gmsa-account))。通常会创建默认账号。 > [!WARNING] -> 除其他权限外,Service Account **`provAgentgMSA`** 拥有 DCSync 权限,这允许 **任何攻破该账号的人控制整个域**。有关 DCSync 的更多信息,请参见 [DCSync check this](https://book.hacktricks.wiki/en/windows-hardening/active-directory-methodology/dcsync.html). +> Among other permissions the Service Account **`provAgentgMSA`** has DCSync permissions, allowing **anyone that compromises it to compromise the whole directory**. For more information about [DCSync check this](https://book.hacktricks.wiki/en/windows-hardening/active-directory-methodology/dcsync.html). > [!NOTE] -> 出于安全原因,默认情况下,已知的特权组(例如 Domain Admins)中具有属性 **`adminCount` to 1 are not synchronized** 的用户不会与 Entra ID 同步。然而,属于特权组但没有此属性的其他用户,或直接被授予高权限的用户 **can be synchronized**。 +> 默认情况下,已知特权组(如 Domain Admins)中 adminCount 属性为 1 的用户出于安全原因不会被同步到 Entra ID。然而,其他属于特权组但没有此属性的用户,或直接被分配高特权的用户,**可能会被同步**。 -## 密码同步 +## Password Sychronization The section is very similar to the one from: @@ -36,22 +36,22 @@ The section is very similar to the one from: az-connect-sync.md {{#endref}} -- **Password hash synchronization** 可以启用,这样用户就可以使用 AD 的密码 **登录到 Entra ID**。此外,只要 AD 中的密码被修改,它也会在 Entra ID 中得到更新。 -- **Password writeback** 也可以启用,允许用户在 Entra ID 中修改密码并自动将密码同步到本地域。但根据 [current docs](https://learn.microsoft.com/en-us/entra/identity/authentication/tutorial-enable-sspr-writeback#configure-password-writeback),这需要使用 Connect Agent,因此请参阅 [Az Connect Sync section](./az-connect-sync.md) 以获取更多信息。 -- **Groups writeback**:该功能允许将来自 Entra ID 的组成员关系同步回本地 AD。也就是说,如果用户被添加到 Entra ID 中的某个组,他们也会被添加到 AD 中对应的组。 +- **Password hash synchronization** 可以被启用,从而让用户使用 AD 的密码登录 Entra ID。此外,每当 AD 中的密码被修改时,它也会在 Entra ID 中更新。 +- **Password writeback** 也可以启用,允许用户在 Entra ID 中修改密码并自动同步回本地域。但根据 [current docs](https://learn.microsoft.com/en-us/entra/identity/authentication/tutorial-enable-sspr-writeback#configure-password-writeback),这需要使用 Connect Agent,请参见 [Az Connect Sync section](./az-connect-sync.md) 以获取更多信息。 +- **Groups writeback**:此功能允许将 Entra ID 的组成员关系同步回本地 AD。这意味着如果用户被添加到 Entra ID 中的某个组,他们也将被添加到 AD 中对应的组。 ## Pivoting ### AD --> Entra ID -- If the AD users are being synced from the AD to Entra ID, pivoting from AD to Entra ID is straightforward, just **compromise some user's password or change some user's password or create a new user and wait until it's synced into the Entra ID directory (usually only a few mins)**. +- 如果 AD 用户正在从 AD 同步到 Entra ID,则从 AD 横向移动到 Entra ID 十分直接,只需 **泄露某个用户的密码或更改某个用户的密码,或创建一个新用户并等待其同步到 Entra ID(通常仅需几分钟)**。 -例如,你可以: -- 攻破 **`provAgentgMSA`** 帐户,执行 DCSync 攻击,破解某个用户的密码,然后使用该密码登录 Entra ID。 -- 只需在 AD 中创建一个新用户,等待其同步到 Entra ID,然后使用它登录 Entra ID。 +因此例如你可以: +- 攻破 **`provAgentgMSA`** 账户,执行 DCSync 攻击,破解某个用户的密码,然后使用该密码登录 Entra ID。 +- 在 AD 中创建一个新用户,等待其同步到 Entra ID,然后使用该用户登录 Entra ID。 - 修改 AD 中某个用户的密码,等待其同步到 Entra ID,然后使用该密码登录 Entra ID。 -要攻破 **`provAgentgMSA`** 的凭证: +要攻破 **`provAgentgMSA`** 凭据: ```powershell # Enumerate provAgentgMSA account Get-ADServiceAccount -Filter * -Server domain.local @@ -73,7 +73,7 @@ $Passwordblob = (Get-ADServiceAccount -Identity pGMSA_$ -Properties msDS-Man $decodedpwd = ConvertFrom-ADManagedPasswordBlob $Passwordblob ConvertTo-NTHash -Password $decodedpwd.SecureCurrentPassword ``` -现在你可以使用 gMSA 的哈希,使用 `provAgentgMSA` 帐户对 Entra ID 执行 Pass-the-Hash 攻击,并维持持久性,从而能够对 AD 执行 DCSync 攻击。 +现在你可以使用 gMSA 的哈希,通过使用 `provAgentgMSA` 账户对 Entra ID 执行 Pass-the-Hash 攻击,并保持持久性,从而能够对 AD 执行 DCSync 攻击。 For more information about how to compromise an Active Directory check: @@ -82,13 +82,13 @@ https://book.hacktricks.wiki/en/windows-hardening/active-directory-methodology/i {{#endref}} > [!NOTE] -> 注意,目前无法根据属性(例如在 Cloud Sync 配置中)向已同步用户授予 Azure 或 EntraID 角色。但是,为了自动授予已同步用户权限,可能会将某些 **Entra ID groups from AD** 授予权限,这样这些组内的已同步用户也会获得这些权限,或者可能使用 **dynamic groups**,因此务必检查动态规则及潜在的滥用方式: -> -> {{#ref}} +> 注意:在 Cloud Sync 配置中无法基于属性为已同步用户分配 Azure 或 EntraID 的角色。不过,为了自动授予已同步用户权限,某些来自 AD 的 **Entra ID groups** 可能被赋予权限,使这些组内的已同步用户也获得这些权限,或者可能使用 **dynamic groups**,因此应始终检查动态规则和潜在的滥用方式: + +{{#ref}} ../az-privilege-escalation/az-entraid-privesc/dynamic-groups.md {{#endref}} -Regarding persistence [this blog post](https://tierzerosecurity.co.nz/2024/05/21/ms-entra-connect-sync-mothods.html) suggest that it's possible to use [**dnSpy**](https://github.com/dnSpy/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` 用于外泄密码哈希): +Regarding persistence [this blog post](https://tierzerosecurity.co.nz/2024/05/21/ms-entra-connect-sync-mothods.html) suggest that it's possible to use [**dnSpy**](https://github.com/dnSpy/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 密码哈希): ```csharp using System; using System.Net; @@ -124,17 +124,16 @@ RawHash = passwordHashData.RawHash ``` ### Entra ID --> AD -- 如果启用了 **Password Writeback**,你可以在 Entra ID 中修改某些用户的密码;如果你能访问目标 AD 网络,就可以使用这些凭据进行连接。更多信息请查看 [Az Connect Sync section](./az-connect-sync.md) 部分,因为 password writeback 是使用该 agent 配置的。 +- 如果启用了 **Password Writeback**,你可以修改部分来自 Entra ID 的用户密码;如果你有对 AD 网络的访问,就可以使用这些凭据进行连接。更多信息请查看 [Az Connect Sync section](./az-connect-sync.md) ,因为 password writeback 是通过该 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](https://learn.microsoft.com/en-us/entra/identity/hybrid/group-writeback-cloud-sync#supported-groups-and-scale-limits): +- 目前 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](https://learn.microsoft.com/en-us/entra/identity/hybrid/group-writeback-cloud-sync#supported-groups-and-scale-limits): -> - 这些组只能包含本地(on-premises)已同步的用户和/或额外由云创建的安全组。 -> - 被同步并且是此云创建安全组成员的本地用户帐户,可以来自同一域或跨域,但它们必须都来自同一林。 +> - 这些组只能包含本地同步的用户和 / 或额外的云创建的安全组。 +> - 已同步并且是此云创建安全组成员的本地用户帐户可以来自同一域或跨域,但它们都必须来自同一域林。 -所以该服务的攻击面(和可利用性)大大降低,因为攻击者需要先攻破用于同步这些用户的初始 AD,才能在另一个域中攻破用户(显然两个域必须位于同一林)。 +因此,该服务的攻击面(和实用性)大大降低,因为攻击者需要入侵最初用于同步用户的 AD,才能在另一个域中攻陷用户(而且显然两者必须位于同一域林)。 - -### Enumeration +### 枚举 ```bash # Check for the gMSA SA Get-ADServiceAccount -Filter "ObjectClass -like 'msDS-GroupManagedServiceAccount'"