Table of Contents
Concept
In Windows and Active Directory credentials usually reside in specific spaces, depending on the architecture and our permissions we might be able to access it to dump it and try to crack or relay the contents of such databases.
In essence, the importance of each Windows dump is like:
- NTDS.dit - Win button. Hashes for everything.
- lsass.exe - Local host data but in domain’s also domain creds which is great and also can have kerberos tickets.
- SAM Hives - Good but most likely just local host data.
SAM
SAM (Security Account Manager) is a local database that stores credentials of local Windows accounts. SAM can be used inside of domain but it will not store any domain information inside. You usually need Administrator or System level permissions to access it. Inside of SAM you can find NTLM hashes of users’ passwords.
SAM data is also stored in two hives, one is optional:
SAM - Stores local user accounts and their NTLM password hashes
SYSTEM - Contains machine boot data, including the key used to decrypt SAM.
SECURITY - Optional: It stores local security policy and LSA secrets, including cached credentials, service account secrets as well as cached domain logons and auto-logon credentials - so it’s worth to grab it if avaiable.
The basic workflow with SAM:
First, copy the hives where you have rights to do so.
reg.exe save hklm\sam C:\sam.save
reg.exe save hklm\system C:\system.save
reg.exe save hklm\security C:\security.save
Secondly, move them from the target to your attack host.
Lastly, dump them with secretsdump.py -sam sam.save -security security.save -system system.save LOCAL.
You should be also able to dump them remotely from your attack host with netexec using the --sam flag.
crackmapexec smb 10.129.42.198 --local-auth -u bob -p HTB_@cademy_stdnt! --sam - This gives data similar to SAM + SYSTEM
And there is also crackmapexec smb 10.129.42.198 --local-auth -u bob -p HTB_@cademy_stdnt! --lsa - which gives data similar to SECURITY + LSASS
lsass.exe
lsass.exe is a LSA’s process which handles authentication and credential management. LSA (Local Security Authority) is a core concept in Windows. It manages security policies and authentication for the system. In essence LSA is the brain which enforces security policies, manages access control, and processes login requests and lsass.exe enforces security policies, authenticates users, and stores credentials in memory.
lsass.exe is session based to it cleared all data that it held on a PC reset. It can hold domain user data if it’s in a domain architecture. You usually need Admin or System level privileges to read and drop it.
If you have access to Windows GUI (like with RDP) you can simply use task maanger to dump the memory file of lsass.exe. Simply Open Task Manager -> Select the Processes tab -> Find & right click the Local Security Authority Process -> Select Create dump file will make a file called lsass.DMP which will be created and saved in C:\Users\loggedonusersdirectory\AppData\Local\Temp by default.
Second option is to do it with Rundll32.exe.
Firstly you need to find out lsass.exe process id. You can do it with tasklist /svc in cmd or Get-Process lsass in powershell. Then you simply run rundll32 C:\windows\system32\comsvcs.dll, MiniDump <PID> C:\lsass.dmp full in powershell to drop the memory of the file.
Alternatively you can also run mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords" exit to dump it with mimikatz or pypykatz.
NTDS.dit
This is the heart of a Domain. You can get all data you’d even need with it. First you need to copy it, for that you can use the built-in utility robocopy with robocopy /B E:\Windows\NTDS .\ntds ntds.dit. You can also alternatively use Copy-FileSeBackupPrivilege which comes from SeBackupPrivilegeCmdLets.dll cmdlet using Copy-FileSeBackupPrivilege E:\Windows\NTDS\ntds.dit C:\Tools\ntds.dit.
With NTDS.dit copied you can then move it into your attack host and dump it with secretsdump.py -ntds ntds.dit -system SYSTEM -hashes lmhash:nthash LOCAL.
Windows Credential Manager
Windows stores many user secrets under AppData\Roaming\Microsoft\ because this is the per-user data location. The Credentials folder specifically belongs to Windows Credential Manager, and it stores things like saved RDP logins, network share credentials, and other application secrets.
DPAPI is a Windows feature that encrypts user data (like saved passwords) using keys derived from the user’s logon secret.
Windows Credential Manager stores credentials encrypted with DPAPI by default. The raw files in AppData\Roaming\Microsoft\Credentials are always DPAPI-protected, meaning they cannot be read without decrypting them using the user’s DPAPI keys (derived from their password or hash).
To decrypt that data you’d first need:
- The credential blob from
C:\Users\todd.wolfe\AppData\Roaming\Microsoft\Credentials\ - The master key from
C:\Users\todd.wolfe\AppData\Roaming\Microsoft\Protect - User’s password or hash
Now I can run dpapi.py masterkey -file key.dpapi -sid S-1-5-21-3927696377-1337352550-2781715495-1110 -password NightT1meP1dg3on14 to decrypt the master key, and I can run dpapi.py credential -file blob.dpapi -key 0xd2832547d1d5e0a01ef271ede2d299248d1cb0320061fd5355fea2907f9cf879d10c9f329c77c4fd0b9bf83a9e240ce2b8a9dfb92a0d15969ccae6f550650a83 to crack open the file itself.
Autologon
AutoLogon credentials are used during Windows boot/login, before the user ever types a password. You can check for them by simply running reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon".