In: Computer Science
. Compare and contrast the Windows password hashing algorithm and the Linux password hashing algorithm demonstrated in the book
You really need to know only the following three basic concepts before extracting Windows hashes:
LM hash
LAN Manager (LM) hash is an old and weak Windows technique for creating hashed passwords, which has been disabled by default in current Windows environments. But this can still be enabled manually on current systems — See Microsoft documentation on how to protect your systems from using it:
Network security Do not store LAN Manager hash value on next password change (Windows 10)
Describes the best practices, location, values, policy management and security considerations for the Network security…
docs.microsoft.com
The reason why LM hash is easier to break is because passwords are not case sensitive, password length is maximum 14 characters and more importantly because it breaks the text in two halves of seven characters before hashing them separately and concatenating. So if your password is less than seven characters, it should be a breeze for a hacker to guess the password. [1]
NT hash or NTLM hash
New Technology (NT) LAN Manager hash is the new and more secure way of hashing passwords used by current Windows operating systems. It first encodes the password using UTF-16-LE and then hashes with MD-4 hashing algorithm.
If you need to know more about Windows hashes, the following article makes it easy to understand [2]
SAM database file
Security Account Manager (SAM) is the database file that stores the user’s password in the hashed format. You would need access to this file in order to retrieve hashes from your local or remote Windows machine [3]
Extracting local hashes from Windows Server 2016
In this section, I will show you how to extract hashed passwords from your Windows desktops using a very popular and powerful tool — mimikatz. The screenshots are from Windows Server 2016.
Step 1: Download mimikatz
Binaries are available at — https://github.com/gentilkiwi/mimikatz/releases
Step 2: Run (regedit)
Step 3: Navigate to HKEY_LOCAL_MACHINE and export SAM registry file and SYSTEM registry file to the same directory as the mimikatz installation. Save the files as “Registry hive files”
Your mimikatz directory should look as below:
Step 4: Run mimikatz.exe and type “lasdump::sam” command followed by the file paths of sam and system file:
lsadump::sam sam3.hiv system.hiv
If you get an error as below, you will need to elevate permissions of mimkatz
Step 5: Type “token::elevate” to elevate the permissions
Step 6: Type the lsadump command again and you should now see the hash values of local users
Confirm if you got the right hash
Use Windows commands to create local users and extract the generated NTLM hash using the above process. Once you have the hash, use the below online utility to generate hashes by yourself and confirm if it matches.
https://www.browserling.com/tools/ntlm-hash [4]
Windows commands for user and password modifications:
List of all users → net user
Add user → net user /add username -key=”password”
Update password of user → net user username newpassword
Other tools that can be used in place of mimikatz:
HashSuite, fqdump, pwdump2
Password cracking/guessing tools:
L0phtCrack, Cain and Abel, John the Ripper
In Linux distributions login passwords are commonly hashed and
stored in the /etc/shadow
file using the MD5
algorithm. The security of the MD5 hash function has been severely
compromised by collision vulnerabilities. This does not mean MD5 is
insecure for password hashing but in the interest of decreasing
vulnerabilities a more secure and robust algorithm that has no
known weaknesses (e.g. SHA-512) is recommended.
The following tutorial uses the SHA-512 hash function, which has been recommended by the United States' National Security Agency (NSA) for Red Hat Enterprise Linux 5. Alternatively, SHA-2 consists of four additional hash functions with digests that are 224, 256, 384, and 512 bits.
If your current password was created with shadow version prior to 4.1.4.3-3 (2011-11-26) you are using MD5. To start using a SHA-512 hash you just need to change your password with passwd.
The rounds=N
option helps to improve key
strengthening. The number of rounds has a larger impact on security
than the selection of a hash function. For example,
rounds=65536
means that an attacker has to compute
65536 hashes for each password he tests against the hash in your
/etc/shadow
. Therefore the attacker will be delayed by
a factor of 65536. This also means that your computer must compute
65536 hashes every time you log in, but even on slow computers that
takes less than 1 second. If you do not use the rounds
option, then glibc will default to
5000 rounds for SHA-512. Additionally, the default
value for the rounds
option can be found in
sha512-crypt.c
.
Open /etc/pam.d/passwd
with a text editor and add
the rounds
option at the end of of the uncommented
line. After applying this change the line should look like
this:
password required pam_unix.so sha512 shadow nullok rounds=65536
Note: For a more detailed explanation of the
/etc/pam.d/passwd
password options check the
pam_unix(8) man page.
Re-hash the passwords
Even though you have changed the encryption settings, your passwords are not automatically re-hashed. To fix this, you must reset all user passwords so that they can be re-hashed.
As root issue the following command,
# passwd username
where username
is the name of the user
whose password you are changing. Then re-enter their current
password, and it will be re-hashed using the SHA-2 function.
To verify that your passwords have been re-hashed, check the
/etc/shadow
file as root. Passwords hashed with
SHA-256 should begin with a $5
and passwords hashed
with SHA-512 will begin with $6
.