Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Cracking your own hashes with John

After this lesson: I can use John the Ripper's word list, rules and mask modes on hashes I may test.

60 min lesson7 commandsPassword lab: John the Ripper, MFA and passkeys

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

An audit before a thief does it

A college's security team copies its own password table and runs a cracker against it. Every password that falls in an hour is one a thief would find too. Those people are asked to change their password today.

That is the only honest reason to crack hashes: your own, or with written permission.

By the end of this lesson

Note

I can use John the Ripper's word list, rules and mask modes on hashes I may test.

Key words

WordWhat it meansExample
John the Ripperan open source password cracker
Word list modetrying every word in a file
Ruleschanges made to each word before it is tried
Maska pattern of characters to try?d is any digit
Pot filewhere John keeps what it has cracked
Costhow much work one guess takes

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The rule for this lesson

Warning

Crack only the hashes this lab made. Every account and password in it is made up, and your copy has no way out to the internet. Trying passwords against anybody else's accounts without written permission is a crime under the Computer Misuse Act 1990.

A word list cracks the common choices

John hashes each word in the list with the same scheme and compares it with every stored hash. A fast, unsalted hash like raw SHA-256 lets one guess test every account at once.

John prints each password it finds beside the account. It keeps them in its pot file, so --show lists everything cracked so far, and a second run has nothing left to do.

Try the word list on the fast hashes

Command
docker exec john john --format=raw-sha256 --wordlist=words.txt hashes/fast.txt

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Show what is cracked so far

Command
docker exec john john --show --format=raw-sha256 hashes/fast.txt

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Worked example: the word list run

What John printedWhat it means
Loaded 5 password hashes with no different saltsSix accounts, but two shared one hash
dragon (finn), sunshine (amira)Two hashes cracked by plain words
amira, dev and finn in --showdev shared amira's hash, so fell with it
3 password hashes cracked, 3 leftben, chloe and erin held

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Rules and masks follow human habits

Rules change each word the way people do: a capital first, a digit or a year on the end, a letter swapped for a symbol. Masks try a pattern you suspect, character by character.

?d is any digit and [Ss] is S or s. A season and a year is a pattern worth a mask. Neither mode is clever: each just follows the habits people share.

Count the guesses the rules make

Command
docker exec john sh -c "john --wordlist=words.txt --rules --stdout | wc -l"

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Try the word list with rules

Command
docker exec john john --format=raw-sha256 --wordlist=words.txt --rules hashes/fast.txt

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Try a season and a year

Command
docker exec john john --format=raw-sha256 --mask="[Ss]ummer20?d?d" hashes/fast.txt

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

A common mistake

Warning

Many people think a capital letter and a digit on a word make it safe. John's default rules made 274,381 guesses from 97 words and found Liverpool1 among the first five thousand. A pattern is only safe if attackers do not guess it, and they guess the common ones first.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Try it: rules by hand

Code: python
# A rule turns one word into many guesses.
word = "liverpool"
guesses = [word, word.capitalize()]
for digit in range(10):
    guesses.append(word.capitalize() + str(digit))
print(len(guesses), "guesses from one word")
print(guesses[:4])
# Add the year 2026 on the end of the capitalised word too, then press Run.

Make a free account to save your work and track your progress.

A slow, salted hash makes every guess cost

bcrypt.txt holds the same passwords with bcrypt. Each account has its own salt, so a guess must be hashed once per account. The cost, 256 here, is the number of rounds of slow setup in each hash.

The word list still finds the three passwords on it. But 274,381 rule guesses would now mean 1,646,286 slow hashes, six salts each, instead of 274,381 fast ones.

Try the word list on bcrypt

Command
docker exec john john --format=bcrypt --wordlist=words.txt hashes/bcrypt.txt

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Show what bcrypt gave up

Command
docker exec john john --show --format=bcrypt hashes/bcrypt.txt

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

The fix, and how to detect a theft

Fix: store passwords with a slow, salted scheme made for them: Argon2id, scrypt or bcrypt, with a cost tuned to your server. Refuse passwords on a breached list, and ask for MFA so a cracked password is not enough.

Detect: offline cracking is invisible, so watch for the theft. Alert on bulk reads of the users table. Plant a honey account that nobody uses: a sign-in to it means the table has leaked.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Assignment: a cracker with rules

Write a small cracker for unsalted SHA-256 hashes, the lab's fast.txt in miniature. sha(text) returns the SHA-256 of the text as lowercase hex. variants(word) returns 22 guesses in this order: the word, the word with its first letter capitalised, the word followed by each digit 0 to 9, then the capitalised word followed by each digit 0 to 9. crack(table, words) takes a dictionary from a name to a hash and a list of words, tries every variant of every word in order, and returns a dictionary from each cracked name to its password. Keep the first password found for a name.

Code: python
import hashlib


def sha(text):
    return ""


def variants(word):
    return [word]


def crack(table, words):
    return {}

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.