On this page
Rainbow Tables
Rainbow tables are a clever strategy to discover the plain text string from a hash generated by a Cryptographic Hash Algorithm. These hashes are “one-way” and can not be decrypted. However, they operate on the principle that the same inputs return the same outputs, and rainbow tables make use of that fact. They primarily affect the security of password hashing.
It takes a long time and a lot of computer processing effort to guess the correct password using a Brute Force Attack, and then an attacker would need to start over for the next password. Instead, attackers spend time and effort up front hashing millions of strings so the results can be reused. The simplest form of this is a lookup table: a database table saving each string with its resulting hash. A rainbow table, invented by Philippe Oechslin, is a refinement of that idea: rather than storing every string-hash pair, it stores long chains of alternating hash and “reduction” operations and keeps only each chain’s starting and ending value. This is a time-memory trade-off — searching a rainbow table takes more computation than searching a lookup table, but the table is dramatically smaller, which makes covering far more candidate passwords practical. Once constructed, either kind of table lets an attacker recover the original input for a matching hash.
The “pre-computing” process still requires a lot of work, but the work can be shared between many computers and the resulting rainbow table is re-usable. It provides a very fast future reference for cracking passwords. Attackers can also improve their results by hashing and storing dictionary words and common passwords first before moving on to hashing random strings.
For rainbow tables to be useful, the hashed string must be known. They are not helpful in blindly guessing a password. Attackers often gain access to thousands of hashed passwords in a stolen database. If those hashes are unsalted and a pre-computed table covers them, each lookup takes seconds instead of the full search a brute force attack would need. In the paper that introduced the technique, Oechslin reported that 1.4 GB of rainbow tables could crack 99.9% of all alphanumeric Windows password hashes in 13.6 seconds each. A table only works for the hash algorithm it was built for (an MD5 table cannot crack SHA-1 hashes), and it only finds passwords within the character set and length range used to build it.
Free pre-computed tables for Windows LM and NT hashes can be downloaded from the Ophcrack project, and tools such as RainbowCrack can generate and use tables for LM, NTLM, MD5, SHA-1, and SHA-256 hashes.
Counter-measures
Salts are the best counter-measure against rainbow tables. Adding a random string to the plain text input before hashing changes the output string. The OWASP Password Storage Cheat Sheet describes a salt as “a unique, randomly generated string that is added to each password,” so each user’s password gets its own salt, stored alongside the hash. As long as the same salt is added when the user’s login attempt is hashed, the results will still match for password authentication. However, a pre-computed rainbow table will be ineffective, because an attacker would need a separate table for every salt and so has to crack the hashes one at a time. The output string could still match an entry in the rainbow table, but if an attacker tried to login with the associated string, it would not be the correct password.
Modern password-hashing algorithms also discourage rainbow tables by being deliberately expensive to compute. The current OWASP Password Storage Cheat Sheet recommends Argon2id for new systems; if Argon2id is not available it recommends scrypt, and it reserves bcrypt for legacy systems where neither Argon2 nor scrypt is available. Argon2id and bcrypt both expose a tunable cost parameter, and Argon2id additionally enforces a tunable memory cost — defeating the GPU/ASIC optimizations that make rainbow-table construction cheap for fast hashes like MD5 or SHA-1. Different cost parameters (for bcrypt, typically a number 10-12; for Argon2id, the memory/iteration/parallelism tuple) produce entirely different outputs, so an attacker would need a separate rainbow table per parameter set, with each table much more expensive to pre-compute. For this reason, rainbow tables are uncommon for these algorithms.