Get a Pentest and security assessment of your IT network.

Cyber Security

Rainbow Table Collisions

TL;DR

Yes, a rainbow table can find multiple plaintext passwords that produce the same hash value. This is called a collision and it’s a fundamental limitation of hashing algorithms. While rare with strong hashes, collisions are inevitable and can be exploited.

Understanding Rainbow Tables & Collisions

Rainbow tables pre-calculate hashes for many possible passwords to speed up password cracking. However, different inputs (passwords) can sometimes produce the same hash output. This is because a hash function maps an infinite number of potential inputs to a finite set of outputs.

How Collisions Happen

  1. Hash Function Properties: Hash functions are designed to be one-way (difficult to reverse) and deterministic (same input always produces the same output). They aren’t designed to guarantee unique outputs for every input.
  2. Finite Output Space: A hash function like MD5 creates a 128-bit hash, meaning there are only 2128 possible hash values.
  3. Infinite Input Space: Passwords can be of varying lengths and use many different characters, creating an almost infinite number of possibilities.
  4. The Birthday Paradox: The probability of a collision increases surprisingly quickly as you add more inputs. This is known as the birthday paradox – in a group of only 23 people, there’s a greater than 50% chance two share a birthday!

Finding Multiple Passwords for One Hash

Here’s how you can demonstrate finding multiple passwords that hash to the same value (using Python as an example):

  1. Choose a Hashing Algorithm: For demonstration, we’ll use SHA-256. Note: SHA-256 is much more resistant to collisions than older algorithms like MD5 or SHA-1.
  2. Generate Hashes: Create a list of passwords and calculate their hashes.
  3. Look for Duplicates: Check if any hash values are repeated. If they are, you’ve found a collision!
import hashlib

def generate_hash(password):
    return hashlib.sha256(password.encode('utf-8')).hexdigest()

passwords = ["password", "Password", "pa$$wOrd", "123456", "secret", "PASSWORD"]
hashes = {}

for password in passwords:
    hash_value = generate_hash(password)
    if hash_value in hashes:
        print(f'Collision found! Password: {password}, Hash: {hash_value}')
        print(f'Original password: {hashes[hash_value]}')
    else:
        hashes[hash_value] = password

This script will show you if any of the passwords produce the same SHA-256 hash. In this example, “password” and “Password” (case sensitivity) may or may not collide depending on your system’s implementation.

Rainbow Tables & Collision Exploitation

  1. Table Structure: Rainbow tables store chains of hashes calculated using reduction functions.
  2. Collision Detection: When cracking a password, the table is searched for a matching hash. If multiple chains end at the target hash, it indicates potential collisions.
  3. Verification: All passwords from colliding chains must be tested against the original system to confirm they are valid. This is because you don’t know which one (if any) is correct without verification.

Mitigation Strategies

  • Salting: Add a unique random string (the salt) to each password before hashing. This makes rainbow tables ineffective, as the table needs to be generated for each individual salt.
  • Strong Hashing Algorithms: Use modern, secure hashing algorithms like Argon2, bcrypt, or scrypt. These are designed to be computationally expensive and resistant to collisions.
  • Key Stretching: Repeat the hashing process multiple times (key stretching) to increase the computational cost of cracking.
  • Password Complexity Policies: Enforce strong password requirements (length, character types) to reduce the likelihood of common passwords being used.
Related posts
Cyber Security

Zip Codes & PII: Are They Personal Data?

Cyber Security

Zero-Day Vulnerabilities: User Defence Guide

Cyber Security

Zero Knowledge Voting with Trusted Server

Cyber Security

ZeroNet: 51% Attack Risks & Mitigation