Labs / Cryptography at Work / Hashes, passwords and obfuscation

Lab 3 of 5 · Hashes, passwords and obfuscation

Password cracking: turning a leaked hash table back into passwords

Identify each hash in a dump by its shape, crack the fast ones with john and rockyou, then meet the bcrypt row that won't fall.

Start this lab 5 steps

The idea

Delphine runs an authorised penetration test for Marsh & Vale, a recruitment firm, and has pulled a copy of the hiring portal's users table. The app kept no plaintext — it stored a hash of each password — so at first glance the accounts look safe.

They are not. The store used raw, fast hashes, so this is offline cracking: you hash guesses from a wordlist and compare, millions a second, with no live server to slow you down. You'll name each hash by its shape, point john and the real rockyou leak at the fast ones, and watch most of the table fall — then meet the one row that does not, and see why.

Delphine only runs these tools against systems Marsh & Vale has authorised her to test in writing. Pointing a cracker at a hash taken from a system whose owner has not authorised you in writing is a crime, not a lab exercise.

Offline cracking: a fast hash falls, a slow one holds
Offline cracking: a fast hash falls, a slow one holds

Steps

  1. The dump you pulled off the portal

    You're on your Kali box, kali, with the captured table saved at /home/kali/loot/users.txt: one username:hash row per account, no salt and no column saying which algorithm made each hash. Read it and look at the hashes, not the names.

    The rows are not all the same length. The portal changed how it hashed passwords over the years and never re-hashed the old accounts, so the table is a museum of its own history — the oldest rows short, the newest long and oddly shaped. That mix is your first piece of information.

    kali:~# cat /home/kali/loot/users.txt
  2. Name each hash by its shape

    Before cracking anything, name the algorithm — because a cracker has to be told the type, and the wrong guess wastes the whole run. hashid reads a hash and lists the formats that match its shape; with -m it also prints the hashcat mode number you would pass as -m. This lab cracks with john (it takes the type as --format), and the very same identification feeds hashcat's -m when you reach for that instead.

    Run it on the two extremes: the 32-character i.admin hash, and the $2y$ row. A 32-hex digest is MD5, 40 is SHA-1, 64 is SHA-256, and a $2y$ prefix is bcrypt — a password hash in a different class, which the last step comes back to.

    kali:~# hashid -m '5f4dcc3b5aa765d61d8327deb882cf99'
    kali:~# hashid -m '$2y$10$VQOFL03vj92nQ6OHy7CLFOTTaEfCtKjeRnyc.POC7JBXO.JPLsfEi'
  3. Point rockyou at the MD5 rows

    john (John the Ripper) hashes every word in a wordlist with the format you name and compares each result to the stored hashes. The wordlist to reach for first is rockyou.txt — the real 14-million-password leak that ships on this box at /usr/share/wordlists/rockyou.txt — because it holds the passwords people actually chose.

    Point it at the two MD5 rows. A fast hash with no stretching — no repeated rounds to slow each guess down — is almost free to compute, so john tears through the common end of rockyou in well under a second.

    kali:~# john --format=raw-md5 --wordlist=/usr/share/wordlists/rockyou.txt --pot=/tmp/md5.pot /home/kali/loot/md5.txt
    kali:~# john --show --format=raw-md5 --pot=/tmp/md5.pot /home/kali/loot/md5.txt
  4. The SHA-1 and SHA-256 rows fall the same way

    SHA-1 and SHA-256 are longer digests, but they are still fast, unsalted hashes, so nothing about the attack changes — only the --format you hand john. Run it twice more: once for the 40-hex rows as raw-sha1, once for the 64-hex rows as raw-sha256.

    This is the whole point of naming the hash first. Give john the right format and the rows fall in a blink; give it the wrong one and it loads nothing and reports failure on hashes that were never in danger.

    kali:~# john --format=raw-sha1 --wordlist=/usr/share/wordlists/rockyou.txt --pot=/tmp/sha1.pot /home/kali/loot/sha1.txt
    kali:~# john --format=raw-sha256 --wordlist=/usr/share/wordlists/rockyou.txt --pot=/tmp/sha256.pot /home/kali/loot/sha256.txt
    kali:~# john --show --format=raw-sha1 --pot=/tmp/sha1.pot /home/kali/loot/sha1.txt; echo ---; john --show --format=raw-sha256 --pot=/tmp/sha256.pot /home/kali/loot/sha256.txt
  5. The bcrypt row that will not fall

    One account is left: t.vale, the $2y$ bcrypt row. Run john against it with rockyou, but cap the run at a few seconds — because bcrypt is built to be slow. Where raw MD5 let john try millions of guesses a second, bcrypt's cost factor — a dial that sets how many rounds each hash runs — drags that down to a few hundred, on purpose.

    So two things defeat you here at once: the hash is slow, and the CEO's passphrase is long and random, in no wordlist on earth. Even left running for weeks against all of rockyou, this would never land.

    kali:~# john --format=bcrypt --wordlist=/usr/share/wordlists/rockyou.txt --max-run-time=8 --pot=/tmp/bc.pot /home/kali/loot/bcrypt.txt
    kali:~# john --show --format=bcrypt --pot=/tmp/bc.pot /home/kali/loot/bcrypt.txt

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab