Credentials Harvesting
Credentials Harvesting
Introduction
Overview
The room covers the fundamental techniques used by red teamers to extract and utilize credentials
within Active Directory (AD) environments. By leveraging harvested credentials, red teamers can
perform lateral movement, impersonate users, and access critical resources.
Key Concepts
1. Credential Harvesting:
Involves techniques for obtaining login credentials such as usernames and passwords.
Clear-text files
Windows registry
Memory dumps
Learning Objectives
1. Extracting Credentials from Local Systems:
Learn methods to extract credentials from the Security Account Manager (SAM) database.
Clear-text passwords.
Credentials Harvesting 1
3. Windows Credentials Manager:
Techniques range from extracting stored credentials to network sniffing, where credentials are
captured during transmission.
Types of Credentials
Credentials can appear in multiple forms:
1. Account Details:
2. Hashes:
3. Authentication Tickets:
Ticket Granting Ticket (TGT): Used in Kerberos authentication for session tickets.
Credentials Harvesting 2
Phishing: Deceiving users via fake login pages or malicious emails to provide credentials.
The attacker has already compromised a system within the internal network.
Lab Setup
To practice the concepts in this room, a preconfigured environment is provided:
Credentials:
Username: thm
Password: Passw0rd!
Credential Access
Credential access is a critical tactic where adversaries obtain legitimate user credentials to facilitate
lateral movement, impersonation, or access to additional systems. Using legitimate credentials is often
preferred over exploiting vulnerabilities. This aligns with the MITRE ATT&CK framework under
TA0006.
1. Clear-text Files
Attackers may search compromised systems for credentials stored in plaintext within local or remote
file systems.
Examples of Clear-text Files:
Credentials Harvesting 3
Commands history: E.g., PowerShell history located
at C:\Users\USER\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
2. Database Files
Applications store settings, configurations, and credentials in database files, often found locally.
Example: Extracting credentials from McAfee Endpoint database files (Refer to THM room:
Breaching AD).
3. Password Managers
Password managers store user credentials for various services and must be secured.
Examples:
Potential Exploits: Misconfigurations or flaws in these applications may allow attackers to access
stored credentials.
4. Memory Dump
Sensitive information often resides in memory, accessible only by users with administrator privileges.
Examples of Extractable Data:
Clear-text credentials.
Cached passwords.
Credentials Harvesting 4
5. Active Directory
Active Directory (AD) contains vital information on users, groups, and computers. Misconfigurations
by administrators can expose this data.
Key Misconfigurations:
Group Policy SYSVOL: Vulnerable versions may leak encryption keys, allowing admin access
(e.g., Task 8 discussion).
General AD Misconfigurations: These lead to attacks like Kerberoasting and Golden Tickets
(Task 9 discussion).
6. Network Sniffing
Attackers use techniques like Man-In-the-Middle (MITM) to intercept network traffic and steal
authentication data.
Targets:
Local computers.
AD environments.
NTLM hashes.
Additional Resources
Refer to MITRE ATT&CK framework for detailed tactics and techniques: TA0006.
Task-specific examples and demonstrations are available in relevant THM rooms, such as
Breaching AD.
Credentials Harvesting 5
1. Keystrokes via Keyloggers
A keylogger monitors and logs keyboard activities.
Example:
Use wmic to create a shadow copy of the volume containing the SAM database.
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows
\system32\config\sam C:\Users\Administrator\Desktop\sam
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows
\system32\config\system C:\Users\Administrator\Desktop\syste
m
3. Registry Hives
Credentials Harvesting 6
Windows Registry stores a copy of the SAM database. Use reg.exe to save the SAM and
SYSTEM files:
Note: Active Directory account hashes require additional files (e.g., SECURITY) for decryption.
This methodology provides several avenues for accessing local account credentials, critical for lateral
movement in penetration testing and red team assessments. Let me know if you need further
elaboration on any section!
Local Security Authority Subsystem Service (LSASS).
This detailed explanation of LSASS (Local Security Authority Subsystem Service) and its role in
credential handling is essential for understanding Windows security mechanisms and attack techniques.
Here’s a concise overview of the key points:
What is LSASS?
LSASS is a core Windows process responsible for enforcing the system's security policy.
Credentials Harvesting 7
It handles authentication, password storage, and Kerberos tickets, enabling seamless access to
network resources without repeated credential entry.
Credentials stored in LSASS make it a high-value target for attackers aiming to steal sensitive data.
2. ProcDump:
Example:
3. Mimikatz:
A powerful tool for dumping and extracting credentials from LSASS memory.
Commands:
privilege::debug
Dump credentials:
sekurlsa::logonpasswords
Introduced by Microsoft in 2012 to restrict memory access and prevent credential dumping.
Bypassing Protection:
Use the mimidrv.sys driver included with Mimikatz to modify kernel-level protections.
Credentials Harvesting 8
Commands:
!+
Important Notes:
Cached credentials are only available if a user has logged in to the system.
Dumping LSASS is a known red-team technique but often flagged by AV solutions. Techniques to
bypass detection, such as encryption or obfuscation, may be necessary.
Once NTLM hashes or clear-text credentials are obtained, attackers can use techniques like Pass-
the-Hash or Pass-the-Ticket for lateral movement or privilege escalation.
Would you like assistance in summarizing this further, or should we explore specific parts in more
depth?
Windows Credential Manager
What is Windows Credential Manager?
Credential Manager is a Windows feature that securely stores credentials for:
2. Windows Credentials: NTLM and Kerberos authentication details for Windows services.
3. Generic Credentials: Custom application credentials (e.g., clear-text usernames and passwords).
Credentials are stored per user and are not shared across accounts but are cached in memory, making
them exploitable.
Command-Line Methods:
Credentials Harvesting 9
vaultcmd /list
Shows the number of credentials and the protection method (e.g., DPAPI).
Dumping Credentials
Example:
Import-Module C:\Tools\Get-WebCredentials.ps1
Get-WebCredentials
function Get-WebCredentials
{
<#
.SYNOPSIS
Nishang script to retrieve web credentials from Windows vault (re
.DESCRIPTION
This script can be used to retreive web credentiaks stored in Win
also needs PowerShell v3 onwards and must be run from an elevated
.EXAMPLE
PS > Get-WebCredentials
.LINK
https://github.com/samratashok/nishang
#>
Credentials Harvesting 10
[CmdletBinding()] Param ()
#http://stackoverflow.com/questions/9221245/how-do-i-store-and-re
$ClassHolder = [Windows.Security.Credentials.PasswordVault,Window
$VaultObj = new-object Windows.Security.Credentials.PasswordVault
$VaultObj.RetrieveAll() | foreach { $_.RetrievePassword(); $_ }
}
2. RunAs Command:
The /savecred argument stores credentials in Credential Manager.
Example:
This saves the credentials, allowing future executions without re-entering the password.
3. CmdKey Command:
Lists stored credentials or details of specific credentials.
cmdkey /list
4. Mimikatz:
Extracts stored credentials from memory.
Commands:
privilege::debug
sekurlsa::credman
Credentials Harvesting 11
Windows uses DPAPI (Data Protection API) to encrypt stored credentials. However, tools like
Mimikatz can bypass these protections by dumping memory.
Use of PowerShell logging and monitoring can detect attempts to run scripts like Get-
WebCredentials .
By dumping clear-text passwords or hashes from Credential Manager, they can authenticate against
systems and services without cracking passwords.
Would you like assistance with any specific tool or technique mentioned here?
Domain Controller
What is the NTDS File?
NTDS.DIT: A database used by the Active Directory (AD) Domain Controller. It contains all
critical AD data such as:
3. Data Table: Contains actual data (e.g., user and group information).
Requirements
To extract hashes from the NTDS database, you need:
Credentials Harvesting 12
3. SECURITY File: Stores LSA secrets.
Using Ntdsutil
1. Dump NTDS Content Locally:
The ntdsutil utility is a Windows tool used for Active Directory maintenance.
2. Transfer Files:
Requirements
Administrative Access: Credentials for a domain user with administrative or replication
permissions.
DC Sync Attack
The DC Sync attack exploits permissions to replicate directory information from a Domain Controller,
effectively retrieving user credentials.
1. Prerequisites:
Credentials Harvesting 13
An account with the following permissions:
Command:
Example Output:
python3 /usr/share/doc/python3-impacket/examples/secretsd
ump.py -just-dc thm@10.10.170.137
Impacket v0.12.0 - Copyright Fortra, LLC and its affiliat
ed companies
Password:
[*] Dumping Domain Credentials (domain\uid:rid:lmhash:nth
ash)
[*] Using the DRSUAPI method to get NTDS.DIT secrets
Administrator:500:aad3b435b51404eeaad3b435b51404ee:fc9b72
f354f0371219168bdb1460af32:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae9
31b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:ec44ddf5ae100
b898e9edab74811430d:::
thm.red\thm:1114:aad3b435b51404eeaad3b435b51404ee:fc525c9
683e8fe067095ba2ddc971889:::
thm.red\victim:1115:aad3b435b51404eeaad3b435b51404ee:6c3d
8f78c69ff2ebc377e19e96a10207:::
thm.red\thm-local:1116:aad3b435b51404eeaad3b435b51404ee:0
77cccc23f8ab7031726a3b70c694a49:::
thm.red\admin:1118:aad3b435b51404eeaad3b435b51404ee:077cc
Credentials Harvesting 14
cc23f8ab7031726a3b70c694a49:::
thm.red\svc-thm:1119:aad3b435b51404eeaad3b435b51404ee:585
8d47a41e40b40f294b3100bea611f:::
thm.red\bk-admin:1120:aad3b435b51404eeaad3b435b51404ee:07
7cccc23f8ab7031726a3b70c694a49:::
thm.red\test-user:1127:aad3b435b51404eeaad3b435b51404ee:5
858d47a41e40b40f294b3100bea611f:::
sshd:1128:aad3b435b51404eeaad3b435b51404ee:a78d0aa18c049d
268b742ea360849666:::
CREDS-HARVESTIN$:1008:aad3b435b51404eeaad3b435b51404ee:9a
03577be94668fe72b734b34c6c23b5:::
[*] Kerberos keys grabbed
Administrator:aes256-cts-hmac-sha1-96:510e0d5515009dc29df
8e921088e82b2da0955ed41e83d4c211031b99118bf30
Administrator:aes128-cts-hmac-sha1-96:bab514a24ef3df25c18
2f5520bfc54a0
Administrator:des-cbc-md5:6d34e608f8574632
krbtgt:aes256-cts-hmac-sha1-96:24fad271ecff882bfce29d8464
d84087c58e5db4083759e69d099ecb31573ad3
krbtgt:aes128-cts-hmac-sha1-96:2feb0c1629b37163d59d4c0deb
5ce64c
krbtgt:des-cbc-md5:d92ffd4abf02b049
thm.red\thm:aes256-cts-hmac-sha1-96:2a54bb9728201d8250789
f5e793db4097630dcad82c93bcf9342cb8bf20443ca
thm.red\thm:aes128-cts-hmac-sha1-96:70179d57a210f22ad0947
26be50f703c
thm.red\thm:des-cbc-md5:794f3889e646e383
thm.red\victim:aes256-cts-hmac-sha1-96:588635fd39ef8a9a0d
d1590285712cb2899d0ba092a6e4e87133e4c522be24ac
thm.red\victim:aes128-cts-hmac-sha1-96:672064af4dd22ebf2f
0f38d86eaf0529
thm.red\victim:des-cbc-md5:457cdc673d3b0d85
thm.red\thm-local:aes256-cts-hmac-sha1-96:a7e2212b5807960
8beb08542187c9bef1419d60a0daf84052e25e35de1f04a26
thm.red\thm-local:aes128-cts-hmac-sha1-96:7c929b738f49032
8b13fb14a6cfb09cf
thm.red\thm-local:des-cbc-md5:9e3bdc4c2a6b62c4
thm.red\admin:aes256-cts-hmac-sha1-96:7441bc46b3e9c577dae
9b106d4e4dd830ec7a49e7f1df1177ab2f349d2867c6f
Credentials Harvesting 15
thm.red\admin:aes128-cts-hmac-sha1-96:6ffd821580f6ed556aa
51468dc1325e6
thm.red\admin:des-cbc-md5:32a8a201d3080b2f
thm.red\svc-thm:aes256-cts-hmac-sha1-96:8de18b5b63fe4083e
22f09dcbaf7fa62f1d409827b94719fe2b0e12f5e5c798d
thm.red\svc-thm:aes128-cts-hmac-sha1-96:9fa57f1b464153d54
7cca1e72ad6bc8d
thm.red\svc-thm:des-cbc-md5:f8e57c49f7dc671c
thm.red\bk-admin:aes256-cts-hmac-sha1-96:48b7d6de0b3ef302
0b2af33aa43a963494d22ccbea14a0ee13b63edb1295400e
thm.red\bk-admin:aes128-cts-hmac-sha1-96:a6108bf8422e93d4
6c2aef5f3881d546
thm.red\bk-admin:des-cbc-md5:108cc2b0d3100767
thm.red\test-user:aes256-cts-hmac-sha1-96:2102b093adef0a9
ddafe0ad5252df78f05340b19dfac8af85a4b4df25f6ab660
thm.red\test-user:aes128-cts-hmac-sha1-96:dba3f53ecee2233
0b5776043cd203b64
thm.red\test-user:des-cbc-md5:aec8e3325b85316b
sshd:aes256-cts-hmac-sha1-96:07046594c869e3e8094de5caa215
39ee557b4d3249443e1f8b528c4495725242
sshd:aes128-cts-hmac-sha1-96:e228ee34b8265323725b85c6c3c7
d85f
sshd:des-cbc-md5:b58f850b4c082cc7
CREDS-HARVESTIN$:aes256-cts-hmac-sha1-96:19806fb8d4592e97
f0a6ac08f6d71d562d70d0fca68c5ab30357511df3c267a8
CREDS-HARVESTIN$:aes128-cts-hmac-sha1-96:620d033dd35ad1f3
441c611eb84ee218
CREDS-HARVESTIN$:des-cbc-md5:bf5438d60b8fdae6
[*] Cleaning up...
Credentials Harvesting 16
Once hashes are obtained, they can be used for Pass-the-Hash (PtH) attacks or cracked to retrieve
plaintext passwords.
1. Pass-the-Hash:
Use tools like Mimikatz or Impacket to authenticate as a user without knowing their plaintext
password.
Command:
Summary of Tools
Tool/Command Use Case
ntdsutil Dumps NTDS.DIT locally.
secretsdump.py Extracts hashes from NTDS.DIT remotely.
hashcat Cracks NTLM hashes.
Credentials Harvesting 17
Encryption Method: Initially, passwords were encrypted using AES-256 encryption, which was
secure at the time.
Vulnerability: Microsoft accidentally published the private key required to decrypt these
passwords, making it easy for attackers with domain access to decrypt and retrieve the passwords.
Tools like Get-GPPPassword can be used to exploit this vulnerability by reading the SYSVOL folder
and extracting local administrator passwords stored in GPP XML files.
LAPS Workflow:
1. The LAPS client (admpwd.dll) on each machine automatically changes the local administrator
password and updates the two AD attributes ( ms-mcs-AdmPwd and ms-mcs-AdmPwdExpirationTime ).
2. Authorized users with the correct permissions can query Active Directory to retrieve the password.
Output:
06/06/2022 01:01 PM .
06/06/2022 01:01 PM ..
05/05/2021 07:04 AM 184,232 AdmPwd.dll
Credentials Harvesting 18
2. List Available LAPS Cmdlets
Check for available PowerShell cmdlets related to LAPS:
Output:
Cmdlet Find-AdmPwdExtendedRights
Cmdlet Get-AdmPwdPassword
Cmdlet Reset-AdmPwdPassword
Cmdlet Set-AdmPwdAuditing
Cmdlet Set-AdmPwdComputerSelfPermission
Cmdlet Set-AdmPwdReadPasswordPermission
Cmdlet Set-AdmPwdResetPasswordPermission
Cmdlet Update-AdmPwdADSchema
These cmdlets are used for managing and accessing the LAPS passwords and permissions.
Output:
ObjectDN ExtendedRightHolders
-------- --------------------
OU=THMorg,DC=thm,DC=red {THM\THMGroupReader}
The output shows that THMGroupReader has the extended rights to access the LAPS passwords for
computers in the THMorg OU.
Credentials Harvesting 19
Output:
The bk-admin user is part of the group and has access to the LAPS passwords.
Output:
Output:
ComputerName DistinguishedName
Password ExpirationTimestamp
------------ -----------------
-------- -------------------
Credentials Harvesting 20
CREDS-HARVESTIN CN=CREDS-HARVESTIN,OU=THMorg,DC=thm,DC=red
FakePassword 2/11/2338 11:05:23...
Scripts: PowerShell scripts, such as LAPSToolkit, can help automate the enumeration of LAPS-
enabled machines and users with access rights.
Summary
Group Policy Preferences (GPP): Used to manage local administrator passwords before LAPS,
but was insecure due to the exposed encryption key.
Local Administrator Password Solution (LAPS): A more secure method for managing and
storing local administrator passwords in Active Directory.
Access: To retrieve the LAPS password, you need the correct permissions (e.g., membership in
groups with extended rights to LAPS).
😊
Let me know if you need further details or clarification!
Other Methods
Active Directory Attacks for Credential Harvesting
In Active Directory (AD) environments, attackers use various techniques to obtain user credentials,
particularly when looking to escalate privileges or persist within a network. Some common techniques
for credential harvesting in Windows and AD environments include Kerberoasting, AS-REP
Roasting, SMB Relay Attacks, and LLMNR/NBNS Poisoning.
Let's go through each of these attack methods to understand how they work.
1. Kerberoasting
Kerberoasting is an attack that targets Service Principal Names (SPNs) in Active Directory. SPNs are
associated with services (such as IIS or MSSQL) running under specific user accounts. These SPNs are
accessible by any user in the domain, which makes it possible for attackers to request Ticket Granting
Credentials Harvesting 21
Service (TGS) tickets for SPNs and attempt to crack the ticket offline to retrieve service account
passwords.
2. Request TGS Tickets: After identifying SPN accounts, the attacker can request a TGS ticket for a
specific SPN account.
3. Crack the TGS Ticket: The TGS ticket is encrypted using the service account's password hash,
and attackers can use Hashcat to crack the ticket offline.
Output:
http/creds-harvestin.thm.red svc-user
Once the SPN (like svc-user ) is identified, the attacker can request the TGS ticket for that account:
2. AS-REP Roasting
AS-REP Roasting is an attack that targets user accounts configured with the "Do not require Kerberos
pre-authentication" setting. When this setting is enabled, attackers can request AS-REP (Authentication
Service Response) tickets without needing a password, allowing them to capture and crack these tickets
offline.
Credentials Harvesting 22
1. Identify Accounts with No Pre-Authentication: Use the Impacket tool Get-NPUsers.py to find
users with the UF_DONT_REQUIRE_PREAUTH flag enabled.
2. Request AS-REP Tickets: For accounts with pre-authentication disabled, request the AS-REP
tickets.
3. Crack the AS-REP Tickets: Extract the hashes and use tools like Hashcat to attempt to crack the
password offline.
Output:
$krb5asrep$23$victim@THM.RED:166c95418fb9dc495789fe9[REMOVED]1e8d2
ef27$6a0e13abb5c99c07
Once an AS-REP ticket is obtained for an account like victim, it can be cracked using Hashcat.
Requirements:
SMB Signing Disabled: SMB signing must be disabled for this attack to work.
2. Capture SMB Packets: The attacker captures NTLM authentication packets sent between a victim
and a target machine.
3. Relay Authentication: The attacker relays these packets to authenticate to another machine or
service.
Credentials Harvesting 23
4. LLMNR/NBNS Poisoning
LLMNR (Link-Local Multicast Name Resolution) and NBNS (NetBIOS Name Service) are used by
machines to resolve names when DNS fails. If a machine on the network cannot resolve a name, it will
send an LLMNR or NBNS query to all devices on the local network. LLMNR/NBNS Poisoning
occurs when an attacker spoofs the response to these queries, tricking the victim into sending NTLM
authentication details to the attacker.
2. Capture NTLM Hashes: When a victim attempts to resolve a name and the attacker responds with
a fake IP address, the victim sends an NTLM authentication request containing the NTLM hash.
3. Crack the Hashes: After capturing the NTLM hashes, the attacker can attempt to crack them
offline.
1. Kerberoasting:
Identify SPNs ( GetUserSPNs.py ), request TGS tickets, and crack them using Hashcat.
2. AS-REP Roasting:
3. SMB Relay:
Set up an SMB relay service, capture NTLM hashes, and attempt to authenticate to other
systems in the network.
4. LLMNR/NBNS Poisoning:
These techniques require tools such as Impacket, Hashcat, Responder, and Metasploit. They are
effective for attacking both single systems and large AD environments.
Conclusion
Credentials Harvesting 24
Credential harvesting techniques like Kerberoasting, AS-REP Roasting, SMB Relay, and
LLMNR/NBNS Poisoning are essential for penetration testers and attackers to exploit vulnerabilities
in Windows and Active Directory networks. Understanding these attacks and practicing them in a lab
environment helps enhance both offensive and defensive cybersecurity skills.
Credentials Harvesting 25