Practice library / Penetration testing, first steps
Lab · Medium · 2 hoursFree account
Password Cracking Lab
Identify hash types, then crack them with hashcat's attack modes and John the Ripper.
On this page 13 sections
- ·Prerequisites
- ·Lab Setup
- 1Build a test hash set
- 2Match each hash to a hashcat mode
- Locked: Dictionary attack on the fast hashes
- Locked: Crack with John the Ripper
- Locked: Mask attack on the NTLM hash
- Locked: Rule-based attack on the Linux shadow hash
- Locked: Crack the bcrypt hash and read a benchmark
- Locked: Defence and Detection
- Locked: Check Your Work
- Locked: Password Cracking Cheat Sheet
- Locked: Clean-up
Stolen credentials drive most intrusions today, from ransomware to supply-chain breaches. Weak hashes crack on a laptop, and one reused password can give an attacker lateral movement across an entire domain. This lab builds a small set of test hashes, one of each common type, and cracks them with both hashcat and John the Ripper. Every hash here comes from a password you choose yourself. No step in this lab touches a real account.
What You'll Learn
- Match a hash to its type from its format and length
- Choose the right hashcat attack mode for a dictionary, mask and rule-based attack
- Crack hashes with John the Ripper as a versatile alternative to hashcat
- Crack NTLM, SHA-256 and Linux shadow hashes on your own test values
- Read a hashcat benchmark and explain why a slow hash resists cracking
- Explain Pass-the-Hash and password spraying, and where each is detected
Prerequisites
This lab assumes basic command-line comfort. No prior lab is required, but Cryptography Fundamentals covers the theory behind hashing if hashes are new to you.
Lab Setup
Use your own Kali machine (a virtual machine is fine). These tools ship with a default Kali install:
hashcat(GPU or CPU;hashcat -Ilists the backends it finds) andjohn.openssl,md5sum,sha1sum,sha256sum,iconv(packagesopenssl,coreutils).python3with thebcryptmodule (pip3 install bcryptif it is missing).
Every hash in this lab comes from a password you make up yourself. Do not run these commands against a real account's hash, a colleague's password, or any system you do not own or have written permission to test.
Step 1: Build a test hash set
Create one hash of each common type, from the same test password
Using one password for every hash makes the attack steps easy to check: whatever method you use, the plaintext must come back the same. The password hashcat is used here only because it is short to type; use any password you like.
Create the fast, unsalted hashes.
echo -n "hashcat" | md5sum | cut -d' ' -f1 > md5.hash
echo -n "hashcat" | sha1sum | cut -d' ' -f1 > sha1.hash
echo -n "hashcat" | sha256sum | cut -d' ' -f1 > sha256.hashCreate the NTLM hash. NTLM is MD4 of the password in UTF-16LE, which is why Windows hashes need the iconv step and OpenSSL's legacy provider (MD4 is disabled by default in OpenSSL 3).
echo -n "hashcat" | iconv -t UTF-16LE | openssl dgst -md4 -provider legacyExample output:
MD4(stdin)= b4b9b02e6f09a9bd760f388b67351e2becho "b4b9b02e6f09a9bd760f388b67351e2b" > ntlm.hashCreate a Linux shadow-style hash (SHA-512 crypt, $6$, the default on current Kali and Debian) and a bcrypt hash ($2b$, common for web application logins).
openssl passwd -6 -salt testsalt123 "hashcat" > shadow.hash
python3 -c "import bcrypt; print(bcrypt.hashpw(b'hashcat', bcrypt.gensalt()).decode())" > bcrypt.hash
cat shadow.hashExample output:
$6$testsalt123$YYiXl7/zc/fRNmRiNS1iHI2BOVcQr.i/jVC/RdhCl.0k8rogWzqPs/Mndbjf0lCUsXAJPAL9gyjE7b1EUTcrt/You now have five files, five hash types, one known plaintext.
Step 2: Match each hash to a hashcat mode
Read length and prefix, then look up the hashcat mode number
Hashcat needs the mode number (-m) before it can crack anything. Length and prefix are usually enough to tell the types apart.
hashid -m md5.hash ntlm.hash shadow.hash bcrypt.hashExample output:
--Hash: 8743b52063cd84097a65d1633f5c74f5
[+] MD5 [Hashcat Mode: 0]
--Hash: b4b9b02e6f09a9bd760f388b67351e2b
[+] NTLM [Hashcat Mode: 1000]
--Hash: $6$testsalt123$YYiXl7...
[+] sha512crypt [Hashcat Mode: 1800]
--Hash: $2b$12$8kCh3nAC9PHENy3O152NIu...
[+] bcrypt [Hashcat Mode: 3200]| Hash | Length / prefix | Hashcat mode |
|---|---|---|
| MD5 | 32 hex chars | 0 |
| SHA-1 | 40 hex chars | 100 |
| SHA-256 | 64 hex chars | 1400 |
| NTLM | 32 hex chars, no prefix | 1000 |
| sha512crypt | starts $6$ | 1800 |
| bcrypt | starts $2a$ / $2b$ | 3200 |
Sign in to continue
9 more sections are for signed-in members. It is free: sign in with Google.