NCKUCTF XY Active Directory Note

kazma 成大資安社 創辦人/社長

Resources

Introduction

forest

  • Forest
    • Domain(ex: corp.local)
      • Domain Controller
        • AD DS
        • 各種服務:LDAP、SMB、Kerberos、DNS、NTP
      • 第一個 domain -> forest root domain
    • Domain(ex: tw.corp.local)

Authentication

Kerberos

  • AS-REQ(請求 TGT)
    • 用 client’s secret key(從密碼衍伸) 加密 timestamp (pre-quthentication)
  • AS-REP(頒發 TGT)
    • DC 用 client’s secret key 解開 timestamp 驗證
    • 頒發的 TGT 以 krbtgt’s secret key 加密
  • TGS-REQ(請求 ST, service ticket)
    • 包含取得的 TGT 和目標 SPN
  • TGS-REP(頒發 ST)
    • DC 用 krbtgt’s secret key 解開 TGT 驗證資訊
    • 頒發 ST 以 Server’s secret key 加密
  • AP-REQ(存取服務)
    • 包含 ST
    • Server 解密 ST 驗證資訊
  • AP-REP(Optional)
    • 雙向驗證時需要
  • 常見登入方式
    • console
    • SMB
      • 445 port
      • 檔案存取
      • 預設 share
        • ADMIN$
        • C$
        • IPC$
    • RDP
      • 3389 port
    • WinRM
      • 5985, 5986 port
      • 類似 ssh
      • PSRemoting 預設 transport
  • Logon Types
    • Interactive logon (console)
    • Network logon (SMB, WinRM)
    • Batch logon
    • Service logon
    • NetworkCleartext logon
    • RemoteInteractive (RDP)
    • 參考資料
  • 常見工具
    • BloodHound: AD 圖形化工具
      • 可以進到 neo4j 下 MATCH (n:User) RETURN n.description 來查看所有使用者的描述
    • BloodHound.py: python collector
      • 遠端搜集,不需落地
      • bloodhound-python -c All -d corp.local -v -u [email protected] -ns 10.10.10.10 -dc dc1.corp.local --zip
    • PowerShell
    • netexec: 內網滲透神器
    • impacket: Python library 實作很多 network protocols
      • 強大的 example scripts

Recon

  • 蒐集 domain、domain controller 等資訊
    • echo $env:USERDNSDOMAIN
    • PowerView
      • Get-Domain
      • Get-DomainController
  • 蒐集 forest 資訊
    • PowerView
      • Get-Forest
  • Trust
    • 可存取的 domain
    • 防禦強度
    • 價值
    • nltest.exe /domain_trusts
    • PowerView
      • Get-DomainTrust
    • Trust Type
      • 方向
        • 單向、雙向
      • 遞移性 (Transitivity)
        • 預設同 forest 有遞移性
      • 類型
        • Parent-child、tree-root、external
  • User
    • 權限
      • Local admin、Group、ACL
    • 高權限使用者
    • 登入的機器
    • UserAccountControl
    • Description
    • 本機帳戶
    • 指令
      • net.exe user /domain
      • Find computers where a specified user has session
        • Invoke-UserHunter
      • Find computers where the current user has local admin access
        • Find-LocalAdminAccess
      • PowerView
        • Get-DomainUser
        • Get-DomainUser -Identity <USERNAME> -Properties *
  • Group
    • 群組中有哪些使用者
    • 擁有的權限
    • 一些高權限群組
      • Enterprise Admins
        • forest 的管理者,只存在 root domain
      • Schema Admins
        • 修改 AD 中的 schema
      • Print Operators
        • 可登入 DC
      • Domain Admins
        • domain 管理者
      • Account Operators
        • 可修改 AD 中的 schema
      • Server Operators
        • 可管理 DC
      • DNSAdmins
        • 可用 SYSTEM 權限在 DC 執行任意 DLL
      • Backup Operators
        • 備份 & 還原 DC 檔案
      • Remote Desktop Users
        • 可 RDP 登入 DC
    • 指令
      • net.exe group /domain
      • PowerView
        • Get-DomainGroup
        • Get-DomainGroupMember -Identity <GROUP_NAME>
  • Computer
    • 功能 ex: database
    • delegation
    • 連線方式
    • Domain Controller
      • DCSync
    • 指令
      • Get-DomainComputer
      • Get-DomainController
  • Service
    • Service Principal Name (SPN)
      • 唯一的識別碼
      • 格式:service/computer[:port][/path]
        • e.g., host/DC01
    • 跑了什麼服務
      • 高價值服務 or 潛在目標
    • SPN 設定在 user -> Kerberoasting
  • ACL
    • Access Control List (ACL)
      • 一連串 Access Control Entries (ACE)
    • 種類
      • DACL: 定義誰可存取資源及可執行的操作
      • SACL: 定義系統記錄哪些對資源的存取嘗試 (audit 用)
    • Security Descriptors
      • SID (security identifier)
      • DACL
      • SACL
    • 物件擁有的權限
    • 指令
      • (Get-Acl -Path 'AD:<DISTINGUISHED_NAME>').Access
      • PowerView
        • Get-DomainObjectAcl -Identity <OBJECT> -ResolveGUIDs
  • NTLM Info
    • 取得主機名稱、網域等資訊
    • 掃多台容易觸發告警
    • 指令
      • DumpNTLMInfo.py 10.10.10.10
      • netexec smb 192.168.56.0/24
      • netexec smb --shares
        • 不帶帳密 -> anonymous shares
  • Active Directory Integrated DNS (ADIDNS)
    • 預設一般使用者可讀取 DNS records
    • 有機會拉到一堆域名

Lateral Movement

  • Credential Dumping e.g., NT Hash、Kerberos Key/Ticket
    • 獲取其他使用者的機密資訊
    • 通常需要本機提權
    • 常見 dump 技巧
      • Registry hives
        • 又稱為 SAM Dump
        • HKLM\SAM: 儲存本機使用者資訊 e.g. 密碼
        • HKLM\SECURITY: 儲存 LSA policy & secrets
        • HKLM\SYSTEM: 儲存 LSA system key 用於解密
        • 指令
          • reg.exe save hklm\sam sam.save /y
          • secretsdump.py -sam sam.save -security security.save -system system.save LOCAL
        • 遠端操作
          • 避免指令觸發 EDR
            • secretsdump.py DOMAIN/USERNAME:PASSWORD@COMPUTER
              • 對 DC 還會做 DCSync
            • regsecrets.py DOMAIN/USERNAME:PASSWORD@COMPUTER
      • LSASS
        • 可用工作管理員、Sysinternals 的 ProcDump 等方式來 dump memory
        • 透過 Mimikatz 或 pypykatz 等工具從 dump 檔案抽取 hashes & tickets
        • 指令
          • .\prodump.exe -accepteula -ma lsass.exe lsass.dmp
          • pypykatz lsa minidumpp lsass.dmp
      • DPAPI
        • 方便使用的加解密 API
          • Windows 負責儲存金鑰
          • System master keys: 儲存於 LSA Secret
        • 列 credential
          • vaultcmd /listcreds:"Windows Credentials" /all
        • 遠端 RPC 操作
  • Pass the Hash
    • NTLM 認證
    • 攻擊者只需要 NT Hash 便可認證為 client
      • 透過 Credential Dumping 技巧
    • Impacket -hashes 參數
      • 格式:LMHASH:NTHASH
      • smbclient.py corp.local/[email protected] -hashes:161d918d191d98f4019f23
  • 撞 Local Admin 帳密
    • LAPS 有開嗎
    • 同網斷多台 windows 機器是相同管理者
    • 可能共用本機管理者帳密
    • 指令
      • netexec smb 192.168.56.0/24 -u Administrator -H 12990f1j293f8293ff12938f --local-auth
  • Pass the Ticket
    • Kerberos Ticket 通常 cache 在 LSASS 中
      • 由 LSASS dump 取得
    • 利用竊取的 Kerberos Ticket 偽裝成該使用者以存取服務
    • ticketConverter.py 轉換票據格式
      • kirbi -> ccache
  • Overpass the Hash
    • 用 NT Hash 來請求有效 TGT
    • 當環境只允許 Kerveros Authentication 時會有幫助
  • PS Remoting
  • Impacket *exe.py
    • impacket

Privilege Escalation

Persistence

  • Title: NCKUCTF XY Active Directory Note
  • Author: kazma
  • Created at : 2025-05-20 14:56:49
  • Updated at : 2025-05-20 15:09:28
  • Link: https://kazma.tw/2025/05/20/NCKUCTF-XY-Active-Directory-Note/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments