Skip to content
10 lessons
06Cybersecurity hands-on · Lesson 6 of 10 · lab

Password hashes with John the Ripper

Why stored passwords are hashed, why fast hashes fail, and how cracking really works.

Roman Urdu: Password hash kyun hote hein, kamzor hash kaise toot-te hein, John the Ripper se dekho.

Video transcript

A good site never stores your password. It stores a hash: a one-way scramble of it. The same password always gives the same hash, but you cannot run a hash backwards.

At login, the site hashes what you typed, and compares the two hashes. If they match, you are in. So when a database leaks, the attacker gets hashes, not passwords.

But a hash can be guessed. A cracking tool takes a wordlist of common passwords, hashes each guess, and compares it with the leaked hash. A match means the password is found. A tool like John the Ripper does exactly this, millions of times a second.

Two things decide how long a hash holds. Old, fast hashes like MD5 let an attacker try billions of guesses. Modern ones like bcrypt and argon2 are slow on purpose, and add a salt, so the same password never hashes the same way twice. And a long, uncommon password is not in any wordlist.

So: weak passwords fall. Slow, salted hashes hold. In the lab, you will crack a set of weak practice hashes with a wordlist, then see why bcrypt holds up. Only crack hashes you own, or are allowed to test.

Video file (MP4, 1 min 22 s, 3.4 MB) · Captions (WebVTT)

Rules: Only test systems you own or have written permission to test. Everything in this track runs against practice targets inside your own machine. Scanning or attacking anyone else’s system without permission is a crime in most countries.

Goal

Crack the weak MD5, SHA-1 and SHA-256 hashes in your lab folder with a wordlist, then see why bcrypt holds up.

Why it matters

Leaked databases are cracked this way every day. Knowing how tells you why bcrypt and argon2 matter.

Your machine · learn-cyber · lab cyber-06

A terminal on your own cyber machine, right in this page. It keeps your files between lessons.

First time: make your course machine from any terminal (Mac, Linux and Windows 10+ all have ssh). Your ssh key is your login; a new key picks a handle and accepts the terms first.

$ ssh -t -p 2200 m.logicpacks.io new cyber --name learn-cyber

After that, come back to the same machine any time. Your files are still there:

$ ssh -t -p 2200 learn-cyber@m.logicpacks.io

To use the terminal in this page, sign this browser in once: run this and open the link it prints.

$ ssh -p 2200 m.logicpacks.io web

All your machines in the browser: logicpacks.io/m. A guest key gets one machine: if you already use it for something else, rm that one or link a free account (3 machines). How machines work, credits and terms: logicpacks.io/machines

Step by step

  1. Look at the hashes. The length gives the type away: 32 hex characters is MD5, 40 is SHA-1, 64 is SHA-256.

    $ cat ~/lab/hashes.txt
    $ awk '{ print length($0) }' ~/lab/hashes.txt | sort | uniq -c
    Diagram: a cracking tool takes each word from a wordlist, hashes it, and compares the result with a leaked hash. When a guess matches, the password is found.
    Cracking is guessing: hash each word from a list and compare it with the leaked hash.
  2. Crack each type with a list of 10,000 common passwords.

    $ john --format=raw-md5 --wordlist=/usr/share/seclists/Passwords/Common-Credentials/10k-most-common.txt ~/lab/hashes.txt
    $ john --format=raw-sha1 --wordlist=/usr/share/seclists/Passwords/Common-Credentials/10k-most-common.txt ~/lab/hashes.txt
    $ john --format=raw-sha256 --wordlist=/usr/share/seclists/Passwords/Common-Credentials/10k-most-common.txt ~/lab/hashes.txt
  3. Show what you cracked.

    $ john --show --format=raw-md5 ~/lab/hashes.txt
    $ john --show --format=raw-sha256 ~/lab/hashes.txt
  4. Now bcrypt. It is slow on purpose: that slowness is the defence. Stop it with Ctrl+C whenever you have seen enough.

    $ john --format=bcrypt --wordlist=/usr/share/seclists/Passwords/Common-Credentials/10k-most-common.txt ~/lab/bcrypt.txt

Check my work

Run this in your machine. It checks your work and prints PASS, or FAIL with a hint about what is missing.

$ lab check cyber-06

Saved in this browser. Use ← and → to move between lessons.