Labs / Night Watch / Defending the password store

Lab 1 of 1 · Defending the password store

Salting and stretching: the defender's answer

Rebuild the cracked store with a salt and slow hash so the road's attack fails.

Start this lab 7 steps

The idea

Across the Passwords road you broke Acme's logins four ways — profiling, an online guess, raw digests, a leaked shadow — and every win leaned on the same weakness: a stored secret that was fast to attack, carried no salt, or guarded a password a list already held. Acme has since been breached and rebuilt its user store, and your job now is to run the exact same offline cracking toolchain against the new one and watch it fail. You will rebuild the leaked store two ways over one set of logins — the legacy fast, unsalted dump and the rebuilt per-user-salt bcrypt store — and attack both with john and rockyou. The legacy dump falls in under a second and gives away who reused a password before you crack a thing; the rebuilt store shrugs off the same list in the same time and hides the reuse. Then you turn the cost knob and meet the two ways salting is done wrong. The honest end of the road: a salt and a slow hash defeat precomputation and throughput, but they never save a weak password a tiny aimed list still guesses — which is why hashing and policy only close the road together. One Kali box, no network, nothing leaves the machine.

A salt breaks the reuse leak
A salt breaks the reuse leak
The cost factor is an exponent
The cost factor is an exponent

Steps

  1. The leak you already know how to read

    Start with the store as it leaked before the rebuild: the legacy dump, one user:digest line per account, the digest a plain unsalted md5. Rebuild it from the known logins and look — two of these staff, rtorres and mlowe, happened to pick the same password. With no salt, what does that do to their two digests?

    attacker:~# cat /tmp/legacy.md5; echo ---; echo "rows sharing a hash value: $(cut -d: -f2 /tmp/legacy.md5 | sort | uniq -d | wc -l | tr -d ' ')"
  2. The legacy store falls in a second

    Point the road's own attack at it: john with the generic rockyou list, bounded so it cannot run away. These are fast, unsalted digests — the same kind L3 shredded — so this is not about a clever list. Crack the file, then ask john what it got, and notice what cracking one of the reused pair does to the other.

    attacker:~# john --format=raw-md5 --wordlist=/usr/share/wordlists/rockyou.txt --max-run-time=20 --pot=/tmp/legacy.pot /tmp/legacy.md5
    attacker:~# john --format=raw-md5 --show --pot=/tmp/legacy.pot /tmp/legacy.md5
  3. The rebuild: a salt for every account

    Now the rebuild. Acme re-stores every password as bcrypt with a per-user salt — random bytes mixed into each account's hash and stored in the clear beside it. Rebuild that store and look again at rtorres and mlowe, who still share the same password. With a different salt baked into each row, how do their two hashes compare now?

    attacker:~# cat /tmp/rebuilt.bcrypt; echo ---; echo "rows sharing a hash value: $(cut -d: -f2 /tmp/rebuilt.bcrypt | sort | uniq -d | wc -l | tr -d ' ')"
  4. The same list, now it crawls

    Run the identical attack you ran on the legacy store — john, the same rockyou list, the same few-second cap — against the rebuilt store. The passwords behind it are the very ones rockyou held and md5 gave up in a blink. With a salted, stretched hash in the way, how far does the same list get in the same budget?

    attacker:~# john --format=bcrypt --wordlist=/usr/share/wordlists/rockyou.txt --max-run-time=10 --pot=/tmp/rebuilt.pot /tmp/rebuilt.bcrypt
    attacker:~# john --format=bcrypt --show --pot=/tmp/rebuilt.pot /tmp/rebuilt.bcrypt
  5. The knob: make each guess cost more

    The 12 in $2b$12$ is the cost factor, and bcrypt runs 2^cost rounds — 2^12 = 4096. It is a single number the defender raises as hardware gets faster, while a real login still hashes only once. Rebuild the store at cost 16 and read what the attacker now faces per guess.

    attacker:~# head -1 /tmp/rebuilt.cost16; echo ---; john --format=bcrypt --wordlist=/dev/null /tmp/rebuilt.cost16 2>&1 | grep -i 'iteration count'
  6. Salting done wrong: one salt for everyone

    A salt only earns its keep when it is per account and the hash underneath is slow. A common rebuild mistake is to add a salt but use one global value for every row, often with a fast hash like sha256 underneath. Rebuild the store that way — sha256(global_salt + password), the same salt on every line — and count the shared hashes again.

    attacker:~# cat /tmp/broken.global; echo ---; echo "rows sharing a hash value: $(cut -d: -f2 /tmp/broken.global | sort | uniq -d | wc -l | tr -d ' ')"
  7. The honest limit: a salt is not a password policy

    Back to the properly rebuilt store — per-user salt, bcrypt cost 12 — the one rockyou could not touch. But those season-word passwords were guessable; rockyou's problem was only that it is 14 million words of breadth. Hand john a tiny aimed list of a few season words instead, and point it at that same strong store.

    attacker:~# john --format=bcrypt --wordlist=/tmp/aimed.txt --pot=/tmp/aimed.pot /tmp/rebuilt.bcrypt
    attacker:~# john --format=bcrypt --show --pot=/tmp/aimed.pot /tmp/rebuilt.bcrypt

Run these steps on real machines

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