Ethical Hacking Lesson 21 – Password Cracking | Dataplexa
System & Network Attacks · Lesson 21

Password Cracking

Passwords protect almost everything. When a hash leaks — from a database breach, a misconfigured service, or a captured authentication exchange — password cracking turns that hash back into plaintext. This lesson covers how it works and how professionals do it legally in an engagement.

Hashes, not passwords

Systems rarely store your actual password. They store a hash — the output of a one-way mathematical function that converts your password into a fixed-length string. When you log in, the system hashes what you typed and compares it to what is stored. If they match, you are in.

The word "one-way" is important. You cannot mathematically reverse a hash to recover the original password. What you can do is compute hashes of candidate passwords and compare them to the target hash until you find a match. That is password cracking — not decryption, not reversing a hash, but educated guessing at enormous speed.

Modern GPUs can compute billions of hashes per second. A 6-character lowercase password in MD5 can be cracked in under a second on consumer hardware. The only thing standing between a leaked hash and a cracked password is the length and complexity of the original password — and whether the system used a strong hashing algorithm to begin with.

Hash types — identifying what you are dealing with

Before cracking a hash, you need to know what algorithm produced it. Different algorithms produce different output lengths and formats. Getting this wrong means your cracking tool spends hours computing the wrong hash type and finds nothing.

COMMON HASH TYPES — identification guide
Algorithm Length Example hash Strength
MD5 32 chars 5f4dcc3b5aa765d61d8327deb882cf99 Weak
SHA-1 40 chars 5baa61e4c9b93f3f0682250b6cf8331b... Weak
SHA-256 64 chars 5e884898da28047151d0e56f8dc62927... Medium
bcrypt 60 chars $2a$12$R9h/cIPz0gi.URNNX3kh2O... Strong
Argon2 Variable $argon2id$v=19$m=65536,t=2... Very strong
NTLM 32 chars 8846f7eaee8fb117ad06bdd830b7586c Weak

bcrypt and Argon2 are deliberately slow algorithms — they are designed to take significantly longer to compute, which multiplies the time needed to crack them. A hash that takes 0.001ms to compute in MD5 takes 100ms in bcrypt. That difference means billions of guesses per second for MD5 becomes ten thousand per second for bcrypt. Password storage algorithm choice matters enormously.

Three cracking approaches — and when each is right

Dictionary attack

Most effective for real passwords

Takes a wordlist of common passwords and hashes each one until a match is found. Works well because people are predictable — most real-world passwords are dictionary words, names, or simple patterns. The rockyou.txt wordlist alone — 14 million entries from a real breach — cracks a surprising proportion of MD5 hashes found in the wild.

Rule-based attack

Best for complex password policies

Applies transformation rules to wordlist entries — capitalise the first letter, append a number, substitute @ for a, add an exclamation mark at the end. People who follow password complexity rules tend to apply them predictably. "Password1!" is a rule-based mutation of "password" that millions of people actually use.

Brute force

Last resort — time consuming

Tries every possible character combination up to a specified length. Guaranteed to find the password eventually but the time required grows exponentially with length. 8 characters of lowercase letters: manageable. 12 characters mixing upper, lower, digits, symbols: years on consumer hardware. Use for short PINs and known short passwords only.

Cracking with John the Ripper

John the Ripper — universally called just "John" — is one of the oldest and most versatile password cracking tools. It auto-detects hash types, supports hundreds of formats, and has an intelligent cracking mode that combines dictionary and rule-based attacks automatically. It is the tool most pen testers reach for first because it just works with minimal configuration.

The scenario: You are on an internal engagement. You found the /etc/shadow file on a Linux server through a misconfiguration — it was readable by your low-privilege user. You copied the hashes to your Kali machine and now need to crack them to identify which accounts use weak passwords. The client has authorised credential testing as part of the engagement scope.

# First — identify what hash format we are dealing with
# hash-identifier reads a hash and tells you the most likely algorithm
# Knowing the format lets John use the correct cracking mode
hash-identifier

# Alternatively, use the hashid tool for more detailed format analysis
# -m flag tells hashid to also output the hashcat mode number (useful later)
hashid -m '$6$rounds=5000$example$hashedvalue...'

# Run John with a dictionary attack using the rockyou wordlist
# --wordlist points to our dictionary file — rockyou.txt has 14 million entries
# --format=sha512crypt tells John the exact hash format to use
#   (sha512crypt is the format used in modern /etc/shadow files)
# hashes.txt contains the hashes we extracted from the target system
john --wordlist=/usr/share/wordlists/rockyou.txt \
     --format=sha512crypt \
     hashes.txt

# Show cracked passwords after the run completes
# --show displays all passwords John has cracked so far
# John stores cracked results in ~/.john/john.pot between sessions
john --show hashes.txt

Breaking it down:

msfadmin:msfadmin — password equals username
The account password is identical to the username. This is the weakest possible credential pattern — it would be the first guess in any manual brute-force attempt. On a real engagement this goes into the report as a critical finding: predictable credentials on a privileged account.
3 cracked, 1 left
Three of four hashes cracked from the rockyou.txt wordlist in under ten seconds. The one remaining hash likely belongs to an account with a stronger password — it survived the dictionary attack. The next step for that one would be a rule-based attack layering common transformations on top of the wordlist, then potentially a targeted brute force if the account is high-value enough to justify the time.
john.pot — the results file
John writes all cracked passwords to ~/.john/john.pot between sessions. This means if you stop and restart a cracking session, John picks up where it left off rather than starting again from scratch. Always check john.pot before re-running a crack — your results may already be there from a previous session.

Cracking with hashcat — GPU power

John runs on the CPU. Hashcat runs on the GPU — and the difference in speed is dramatic. A modern gaming GPU can compute hundreds of billions of MD5 hashes per second. For hash types that are computationally cheap like MD5 and NTLM, hashcat is the tool of choice. For slow hashes like bcrypt, the speed advantage shrinks considerably because the algorithm itself is the bottleneck.

Hashcat identifies hash types by number rather than name — a hashcat mode. MD5 is mode 0. NTLM is mode 1000. SHA-256 is mode 1400. The hashid tool with the -m flag tells you the right mode number to use.

# Hashcat dictionary attack against an MD5 hash
# All operations run on GPU for maximum speed

# -m 0  specifies hash mode — 0 is MD5
#        other common modes: 1000 = NTLM, 1800 = sha512crypt, 3200 = bcrypt
# -a 0  specifies attack mode — 0 is dictionary (wordlist) attack
#        other attack modes: 1 = combination, 3 = brute force mask, 6 = hybrid
# hashes.txt  contains the MD5 hashes to crack, one per line
# rockyou.txt  the wordlist — tried against each hash in sequence
hashcat -m 0 -a 0 hashes.txt /usr/share/wordlists/rockyou.txt

# Rule-based attack — applies transformation rules to each wordlist entry
# -r points to a rules file — best64.rule applies 64 common password mutations
#    (capitalise, append numbers, substitute letters, add symbols etc.)
# Catches passwords like Password1, p@ssword, password! that plain wordlists miss
hashcat -m 0 -a 0 hashes.txt /usr/share/wordlists/rockyou.txt \
  -r /usr/share/hashcat/rules/best64.rule

# Show cracked results after the run
# --show reads from hashcat's potfile (~/.hashcat/hashcat.potfile)
hashcat -m 0 hashes.txt --show

Breaking it down:

14 billion hashes per second
An RTX 3070 computing 14 billion MD5 hashes every second. The entire rockyou.txt wordlist of 14 million entries runs in about one millisecond. This is why MD5 password storage is considered categorically broken — any MD5-hashed password that appears in a common wordlist is cracked before the tool has fully started. This speed is also why length matters far more than complexity for passwords stored in MD5.
hash:plaintext format in output
Hashcat displays results as hash:plaintext pairs. This is the format the potfile stores them in. When you need to match a cracked password back to an account, you cross-reference the hash in the output against the hash you extracted from the system. The hash is the unique identifier that connects the cracked password to the account it belongs to.

Wordlists — the quality of your list determines the quality of your results

The wordlist is the most important variable in a dictionary attack. A bad wordlist against a weak password produces nothing. A good wordlist against a strong password also produces nothing. The art is matching the wordlist to the target context — what kind of organisation is this, what are their password policies, what language do they operate in, are there any clues from the OSINT phase?

USEFUL WORDLISTS ON KALI — locations and use cases
File Entries Best used for
/usr/share/wordlists/rockyou.txt 14.3M First pass on any hash — covers the vast majority of common password patterns
/usr/share/wordlists/fasttrack.txt 222 Quick check for the most trivially weak passwords — default creds, company names, seasons
/usr/share/seclists/Passwords/ Varies Specialised lists — leaked databases, service-specific defaults, language-specific wordlists
Custom list (built from OSINT) Custom Target-specific — company name, product names, city, sports team, employee names gathered during recon

The custom list line in that table is worth expanding on. During recon you gathered the company name, location, product names, and sometimes employee names. A surprising number of people use their company name, the city they work in, or the name of their organisation's primary product as the base of their password. Building a short targeted wordlist from OSINT data — 50 to 100 entries — and running it first takes thirty seconds and occasionally cracks something that rockyou.txt would never touch.

Teacher's Note: Password cracking in this course runs against hashes you have legitimately obtained during an authorised engagement — either from the /etc/shadow file via a misconfiguration, a database dump, or a captured network authentication exchange. Cracking hashes you found without authorisation, or attempting to crack hashes of accounts outside your engagement scope, is a criminal offence regardless of the technique used.

Practice questions

Scenario:

A pen tester has obtained a set of MD5 hashes from a compromised database during an authorised engagement. The target is a retail company with around 200 employees — most likely using common English words or simple phrases as passwords based on the organisation's informal IT culture. The tester wants to try the most efficient attack first before committing to more computationally intensive approaches. Which password cracking approach should they start with?


Scenario:

A pen tester recovers hashes from a web application's database. Running hashcat against them, they notice the cracking speed drops from billions of hashes per second to around eight thousand per second — despite using the same GPU and wordlist. They look at the hash format and see each entry starts with "$2a$12$". This significantly slows cracking because the algorithm is deliberately designed to require hundreds of iterations of computation for each guess. Which password hashing algorithm produces hashes in this format?


Scenario:

A pen tester has run a dictionary attack against a set of NTLM hashes using rockyou.txt and cracked 60% of them. The remaining 40% did not match any entry in the wordlist. The tester suspects many of the remaining passwords are mutations of common words — with capital letters, numbers appended, or symbols substituted in — rather than genuinely random strings. They want to run a second pass that automatically applies these kinds of transformations to each wordlist entry. Which hashcat flag and argument achieves this?


Quiz

Scenario:

A developer argues that password hashing algorithm choice does not matter as long as users choose strong passwords — a long random password is equally secure in MD5 or bcrypt. A security engineer disagrees. Who is right and what is the key technical reason that makes one algorithm significantly more resistant to cracking than the other?

Scenario:

A pen tester runs John the Ripper overnight and finds it has cracked several hashes by morning. They then re-run "john --show hashes.txt" and see the cracked passwords listed instantly without running any computation. A colleague is confused — how did John display the results without re-computing anything? What explains this behaviour?

Scenario:

A pen tester is cracking NTLM hashes from a London-based football club. The rockyou.txt attack found some passwords but missed several. The tester knows from the recon phase that the club is called "Riverside FC," is based in Croydon, and their main sponsor is "SkyBet." Many of the remaining accounts belong to non-technical staff. What targeted approach is likely to crack some of the remaining hashes before escalating to a full rule-based attack?

Up Next · Lesson 22

Brute Force Attacks

From offline hash cracking to live service attacks — Hydra, rate limiting, lockout policies, and how to test credentials against real running services.