# Active Directory Attacks - Athentication ###### tags: `OSCP` ## NTLM Authentication NTLM authentication is used when a **client authenticates to a server by IP address** (instead of by hostname),or if the user attempts to authenticate to a hostname that is not registered on the Active Directory integrated DNS server #### Seven Steps below: ![](https://i.imgur.com/Az4Ls4E.png) 1. 電腦從用戶的密碼中計算出 NTLM Hash 2. 客戶端電腦將 user name發送到服務器 3. 服務器返回一個隨機值,稱為 nonce 或 challenge。 4. 客戶端然後使用 NTLM Hash 加密 nonce,作為response,並將其發送到服務器 5. 服務器將 response 連同 username 和 nonce 一起轉發到 domain controller。 6. 然後由域 domain controller 執行驗證,因為它已經知道所有用戶的 NTLM Hash。 Domain controller 使用提供的用戶名的 NTLM Hash 對 challenge 本身進行加密,並將其與從服務器收到的 nonce/response 進行比較。 如果兩者相等,則認證請求成功。 7. 通過認證 ## Kerberos Authentication Windows-based Kerberos authentication uses a ticket system At a high level, Kerberos client authentication to a service in Active Directory involves the use of a domain controller in the role of a key distribution center (KDC) ![](https://i.imgur.com/EHNqZGP.png) 1. 用戶登錄到他們的工作站,一個請求被發送到domain controller,它具有 KDC 的角色並且還維護著 Authentication Server 服務。此Authentication Server Request(或 AS_REQ)包含timestamp,此timestamp使用user的密碼和用戶名推導的hash加密過 2. 當Domain controller收到請求時,它會查找與特定用戶關聯的密碼哈希並嘗試解密timestamp,如果解密過程成功並且timestamp不是重複的(潛在的重放攻擊),則認為身份驗證成功。 Domain controller使用包含session key(因為 Kerberos 是無狀態的)和Ticket Granting Ticket(TGT) 的Authentication Server Reply (AS_REP) 回复客戶端。TGT 包含有關用戶的信息,包括組成員身份、domain、time stamp、客戶端的 IP 地址和 session key。為了避免被篡改,Ticket Granting Ticket 使用只有 KDC 知道的密鑰進行加密,並且不能被客戶端解密。 一旦客戶端收到會話密鑰和 TGT,KDC 就認為客戶端身份驗證完成。 默認情況下,TGT 的有效期為 10 小時,之後會發生續訂。 此續訂不需要用戶重新輸入密碼 3. 當用戶希望訪問 domain 的資源,例如網絡共享、Exchange 郵箱或其他具有註冊服務主體名稱的應用程序時,它必須再次聯繫 KDC,這次,客戶端構造了一個 Ticket Granting Service Request(或 TGS_REQ)數據包,該數據包由當前用戶和時間戳(使用會話密鑰加密)、資源的 SPN 和加密的 TGT 組成。 4. 接下來,KDC 上的 ticket granting service接收 TGS_REQ,如果 domain 中存在 SPN,則使用只有 KDC 知道的密鑰解密 TGT。 ## Cached Credential Storage and Retrieval In current versions of Windows, these hashes are stored in the Local Security Authority Subsystem Service (LSASS) memory space. We need to have system、local admin privillege to gain access to the hashes 例如: 使用Mimikatz ```bash=1 privilege::debug sekurlsa::logonpasswords sekurlsa::tickets ``` ## Service Account Attacks