🌈 Rainbow Tables
Precompute a hash→plaintext table once, then crack many unsalted MD5 hashes instantly — and watch salting defeat the whole technique.
Run it
Each step runs the real tool in the lab and streams output below.
1 · Generate a rainbow table (rtgen)
Build an MD5 table for a small lowercase keyspace. The slow, one-time cost.
2 · Sort the table (rtsort)
Sort the generated table so lookups work.
3 · Crack UNSALTED hashes (rcrack)
Look up the leaked unsalted MD5 hashes in the table — near-instant.
4 · Same technique vs SALTED hashes (defense works)
Salted hashes aren't in any precomputed table. Here John must brute each one with its salt — slow, and the lesson.
Module 02 — Rainbow Tables
Goal: understand the time–memory trade-off behind rainbow tables — pay a big one-time cost to precompute, then crack many unsalted hashes almost instantly — and see first-hand why salting destroys the whole technique.
| Time | 45–60 min (table generation is the slow part) |
| Target | the leaked hash files from Module 01 |
| Tools | rainbowcrack (rtgen, rtsort, rcrack), John the Ripper |
| Prereq | toolbox shell (make toolbox) |
Architecture note:
rainbowcrack(rtgen/rtsort/rcrack) is amd64-only — it has no arm64 build. On an ARM host (e.g. some VPSs/Apple Silicon) steps 1–3 are skipped automatically; the salting-defense part (step 4/5, John) still works everywhere and carries the core lesson. For the full rainbowcrack demo, use an x86-64 machine.
The idea
A dictionary attack hashes each guess every time you attack. A rainbow table instead does the hashing once, ahead of time, storing compressed chains that map hashes back to plaintext. After that, cracking any hash in the covered keyspace is a fast lookup.
The catch:
- Tables only cover a fixed keyspace (charset × length). Outside it: no hit.
- Tables are built for one algorithm (here, MD5).
- A salt means the stored value is
hash(salt + password). Every user's salt is different, so a precomputed table for bare passwords never matches — you'd need a separate table per salt, which defeats the point.
This is exactly why every real system salts. This module makes that visible.
Walkthrough
Step 1 — generate a table (the slow, one-time cost)
cd shared/loot
rtgen md5 loweralpha 1 5 0 1000 2000 0
# alg charset min/max idx chainlen chains part
Small keyspace (lowercase, length 1–5) so the lab finishes quickly. Real tables for larger keyspaces are gigabytes and take hours — that's the "memory" half of the time–memory trade-off.
Step 2 — sort for fast lookup
rtsort .
Step 3 — crack unsalted hashes (instant)
cut -d: -f2 ../hashes/leaked_hashes.txt > rt_in.txt
while read h; do rcrack . -h "$h"; done < rt_in.txt
Short lowercase passwords in the leaked set resolve immediately. Longer or
mixed-character ones fall outside this small table's keyspace — grow the table
(rtgen … loweralpha-numeric 1 7 …) and they'd fall too, at the cost of size.
Step 4 — the defense: salted hashes don't match
shared/hashes/leaked_hashes_salted.txt holds the same passwords, salted
(md5(salt+password)). Feed those stored MD5 values to the same table:
sed -E 's/.*\$dynamic_4\$([0-9a-f]{32}).*/\1/' ../hashes/leaked_hashes_salted.txt \
| while read h; do rcrack . -h "$h"; done
Every lookup misses. The precomputation is worthless against salt.
Step 5 — salted passwords can still be brute-forced one salt at a time
Rainbow tables are out, but a weak salted password still falls to a plain wordlist attack — John just has to re-hash each guess with each salt:
john --wordlist=/usr/share/wordlists/rockyou.txt --format=dynamic_4 \
../hashes/leaked_hashes_salted.txt
john --show --format=dynamic_4 ../hashes/leaked_hashes_salted.txt
That's slow compared to a lookup, and a slow hash (bcrypt/Argon2) would make it impractical.
One-shot
bash modules/02-rainbow-tables/demo.sh
dynamic_4is John's name formd5(salt.password). If your John build names it differently, runjohn --list=formats | tr ',' '\n' | grep -i dynamic.
Defenses (discuss after the exercise)
- Salt everything, uniquely per user → precomputation (rainbow tables) dies.
- Use a slow, modern hash (bcrypt, scrypt, Argon2) → even per-salt brute force becomes too expensive.
- Pepper (a secret, app-side key) adds another barrier if the DB alone leaks.
Checks for understanding
- Why does one rainbow table crack many unsalted hashes, but not one salted hash?
- What two knobs decide whether a password is "in" a table, and how do they trade off against table size?
- If every user had a unique salt, how many tables would precomputation need?
- Salting stops rainbow tables but not Module 01's wordlist attack on weak salted passwords. What additional control closes that gap?