Password Hashes with Python (NETLAB)


Generate and crack Windows password hashes with Python.

The same techniques work for Linux and Mac hashes, but thousands of times slower, because Windows uses especially weak hashes.

Starting your Machine

Open the Kali32 virtual machine. Log in as root with the password toor

A Test Hash

Here's a simple test case. A password of
has this hash on Windows machines:
Windows does not use any salt, so every user with the same password has the same password hash.

This is the "modern" NTLM hash, not the even weaker LM hashes which Windows stopped using after Windows XP.

Calculating Windows NT Password Hashes with Python

In Kali Linux, in a Terminal window, execute this command:
In nano, enter the code shown below:

Save the file with Ctrl+X, Y, Enter.

Running the Program

In a Terminal window, execute this command:
Enter a password of password.

You should see a result like that shown below (the memory location may be different):

This is a hash, but it's a binary object and all you see is its memory location. To see the normal result in hexadecimal, add the hexdigest() method like this:

Run the program again. This time you should get the exact hash shown below:

This looks more like a hexadecimal hash, but it's incorrect for Windows passwords. As shown above, the correct NT hash starts with 8846.

That's because the Windows algorithm uses Unicode, not ASCII, to encode the characters.

Modify your program to use Unicode, as shown below. (NOTE: the code for Unicode is "UTF-16LE" with the letters in lowercase, NOT "utf-161e".)

Run the program again. This time you should get the exact hash shown below:

Making a Hash Dictionary

Create a program that calculates the NTLM hashes for all two-digit passwords from 00 to 99.

The last several hashes should look like the figure below.



Last revised: 8-17-15

Revised for NETLAB 6-13-16