Stealing Windows Credentials
Credentials Mimikatz
Find other things that Mimikatz can do in this page.
Invoke-Mimikatz
Learn about some possible credentials protections here. This protections could prevent Mimikatz from extracting some credentials.
Credentials with Meterpreter
Use the Credentials Plugin that I have created to search for passwords and hashes inside the victim.
Bypassing AV
Procdump + Mimikatz
As Procdump from SysInternals is a legitimate Microsoft tool, it's not detected by Defender. You can use this tool to dump the lsass process, download the dump and extract the credentials locally from the dump.
This process is done automatically with SprayKatz: ./spraykatz.py -u H4x0r -p L0c4L4dm1n -t 192.168.1.0/24
Note: Some AV may detect as malicious the use of procdump.exe to dump lsass.exe, this is because they are detecting the string "procdump.exe" and "lsass.exe". So it is stealthier to pass as an argument the PID of lsass.exe to procdump instead of the name lsass.exe.
Dumping lsass with comsvcs.dll
A DLL named comsvcs.dll found in C:\Windows\System32
is responsible for dumping process memory in the event of a crash. This DLL includes a function named MiniDumpW
, designed to be invoked using rundll32.exe
.
It is irrelevant to use the first two arguments, but the third one is divided into three components. The process ID to be dumped constitutes the first component, the dump file location represents the second, and the third component is strictly the word full. No alternative options exist.
Upon parsing these three components, the DLL is engaged in creating the dump file and transferring the specified process's memory into this file.
Utilization of the comsvcs.dll is feasible for dumping the lsass process, thereby eliminating the need to upload and execute procdump. This method is described in detail at https://en.hackndo.com/remote-lsass-dump-passwords/.
The following command is employed for execution:
You can automate this process with lssasy.
Dumping lsass with Task Manager
Right click on the Task Bar and click on Task Manager
Click on More details
Search for "Local Security Authority Process" process in the Processes tab
Right click on "Local Security Authority Process" process and click on "Create dump file".
Dumping lsass with procdump
Procdump is a Microsoft signed binary which is a part of sysinternals suite.
Dumpin lsass with PPLBlade
PPLBlade is a Protected Process Dumper Tool that support obfuscating memory dump and transferring it on remote workstations without dropping it onto the disk.
Key functionalities:
Bypassing PPL protection
Obfuscating memory dump files to evade Defender signature-based detection mechanisms
Uploading memory dump with RAW and SMB upload methods without dropping it onto the disk (fileless dump)
CrackMapExec
Dump SAM hashes
Dump LSA secrets
Dump the NTDS.dit from target DC
Dump the NTDS.dit password history from target DC
Show the pwdLastSet attribute for each NTDS.dit account
Stealing SAM & SYSTEM
This files should be located in C:\windows\system32\config\SAM and C:\windows\system32\config\SYSTEM. But you cannot just copy them in a regular way because they protected.
From Registry
The easiest way to steal those files is to get a copy from the registry:
Download those files to your Kali machine and extract the hashes using:
Volume Shadow Copy
You can perform copy of protected files using this service. You need to be Administrator.
Using vssadmin
vssadmin binary is only available in Windows Server versions
But you can do the same from Powershell. This is an example of how to copy the SAM file (the hard drive used is "C:" and its saved to C:\users\Public) but you can use this for copying any protected file:
Code from the book: https://0xword.com/es/libros/99-hacking-windows-ataques-a-sistemas-y-redes-microsoft.html
Invoke-NinjaCopy
Finally, you could also use the PS script Invoke-NinjaCopy to make a copy of SAM, SYSTEM and ntds.dit.
Active Directory Credentials - NTDS.dit
The NTDS.dit file is known as the heart of Active Directory, holding crucial data about user objects, groups, and their memberships. It's where the password hashes for domain users are stored. This file is an Extensible Storage Engine (ESE) database and resides at %SystemRoom%/NTDS/ntds.dit.
Within this database, three primary tables are maintained:
Data Table: This table is tasked with storing details about objects like users and groups.
Link Table: It keeps track of relationships, such as group memberships.
SD Table: Security descriptors for each object are held here, ensuring the security and access control for the stored objects.
More information about this: http://blogs.chrisse.se/2012/02/11/how-the-active-directory-data-store-really-works-inside-ntds-dit-part-1/
Windows uses Ntdsa.dll to interact with that file and its used by lsass.exe. Then, part of the NTDS.dit file could be located inside the lsass
memory (you can find the latest accessed data probably because of the performance improve by using a cache).
Decrypting the hashes inside NTDS.dit
The hash is cyphered 3 times:
Decrypt Password Encryption Key (PEK) using the BOOTKEY and RC4.
Decrypt tha hash using PEK and RC4.
Decrypt the hash using DES.
PEK have the same value in every domain controller, but it is cyphered inside the NTDS.dit file using the BOOTKEY of the SYSTEM file of the domain controller (is different between domain controllers). This is why to get the credentials from the NTDS.dit file you need the files NTDS.dit and SYSTEM (C:\Windows\System32\config\SYSTEM).
Copying NTDS.dit using Ntdsutil
Available since Windows Server 2008.
You could also use the volume shadow copy trick to copy the ntds.dit file. Remember that you will also need a copy of the SYSTEM file (again, dump it from the registry or use the volume shadow copy trick).
Extracting hashes from NTDS.dit
Once you have obtained the files NTDS.dit and SYSTEM you can use tools like secretsdump.py to extract the hashes:
You can also extract them automatically using a valid domain admin user:
For big NTDS.dit files it's recommend to extract it using gosecretsdump.
Finally, you can also use the metasploit module: post/windows/gather/credentials/domain_hashdump or mimikatz lsadump::lsa /inject
Extracting domain objects from NTDS.dit to an SQLite database
NTDS objects can be extracted to an SQLite database with ntdsdotsqlite. Not only secrets are extracted but also the entire objects and their attributes for further information extraction when the raw NTDS.dit file is already retrieved.
The SYSTEM
hive is optional but allow for secrets decryption (NT & LM hashes, supplemental credentials such as cleartext passwords, kerberos or trust keys, NT & LM password histories). Along with other information, the following data is extracted : user and machine accounts with their hashes, UAC flags, timestamp for last logon and password change, accounts description, names, UPN, SPN, groups and recursive memberships, organizational units tree and membership, trusted domains with trusts type, direction and attributes...
Lazagne
Download the binary from here. you can use this binary to extract credentials from several software.
Other tools for extracting credentials from SAM and LSASS
Windows credentials Editor (WCE)
This tool can be used to extract credentials from the memory. Download it from: http://www.ampliasecurity.com/research/windows-credentials-editor/
fgdump
Extract credentials from the SAM file
PwDump
Extract credentials from the SAM file
PwDump7
Download it from: http://www.tarasco.org/security/pwdump_7 and just execute it and the passwords will be extracted.
Defenses
Learn about some credentials protections here.
Last updated