Back to Articles

Building Rainbow Tables on BigQuery: When Cloud Databases Meet Hash Cracking

[ View on GitHub ]

Building Rainbow Tables on BigQuery: When Cloud Databases Meet Hash Cracking

Hook

What if your password cracking infrastructure cost $0.02 per lookup and scaled to petabytes without managing a single server? That's the promise of cloud-native rainbow tables.

Context

Traditional rainbow tables face a fundamental tradeoff: storage versus computation. Pre-computing hash-to-plaintext mappings saves cracking time but requires enormous disk space—a comprehensive MD5 rainbow table can consume terabytes. Tools like RainbowCrack and hashcat have optimized this locally for decades, but you're still bound by your hardware's storage and I/O capabilities.

Big Rainbow takes a radically different approach by offloading rainbow table storage to Google BigQuery, treating a cloud data warehouse as a distributed hash lookup service. Instead of managing local files or building custom infrastructure, you upload your rainbow table data to BigQuery and query it like any other dataset. This architectural shift transforms the economics: you pay per query rather than maintaining always-on infrastructure, and you inherit BigQuery's massive scale, redundancy, and sub-second query performance. It's a proof-of-concept that demonstrates how cloud services designed for analytics can be repurposed for security research—and raises interesting questions about the future of offensive tooling.

Technical Insight

BigQuery Backend

Query Interfaces

Data Ingestion

Bulk Load

Columnar Scan

Parameterized Query

Parameterized Query

Hash Match

Hash-Plaintext Pairs

Ingestion Pipeline

BigQuery Tables

CLI Interface

AWS Lambda Function

Distributed Query Engine

Plaintext Result

System architecture — auto-generated

At its core, Big Rainbow consists of two components: a data ingestion pipeline that populates BigQuery tables with hash-plaintext pairs, and query interfaces (CLI and AWS Lambda) that perform lookups. The magic lies in exploiting BigQuery's columnar storage and distributed query engine, which can scan billions of rows in seconds.

The schema is deliberately simple—typically just two columns: the hash and its corresponding plaintext. Here's what a basic query might look like when implemented through the CLI:

from google.cloud import bigquery

def lookup_hash(hash_value, table_id='my_project.rainbow.md5_table'):
    client = bigquery.Client()
    query = f"""
        SELECT plaintext 
        FROM `{table_id}` 
        WHERE hash = @hash_value
        LIMIT 1
    """
    job_config = bigquery.QueryJobConfig(
        query_parameters=[
            bigquery.ScalarQueryParameter("hash_value", "STRING", hash_value)
        ]
    )
    results = client.query(query, job_config=job_config)
    for row in results:
        return row.plaintext
    return None

# Usage
cracked = lookup_hash("5f4dcc3b5aa765d61d8327deb882cf99")
print(f"Password: {cracked}")  # Output: password

The parameterized query prevents SQL injection while BigQuery's query optimizer automatically determines the most efficient execution plan. Because BigQuery uses columnar storage, it only scans the hash column until it finds a match—critical for performance when tables contain billions of entries.

The AWS Lambda integration extends this concept to serverless architectures. You can deploy a Lambda function that accepts hash values via API Gateway and returns cracked passwords without maintaining any persistent infrastructure. The Lambda cold start penalty (typically 1-3 seconds) is negligible compared to the cracking time savings:

import json
import os
from google.cloud import bigquery

def lambda_handler(event, context):
    hash_value = event.get('queryStringParameters', {}).get('hash')
    if not hash_value:
        return {'statusCode': 400, 'body': 'Missing hash parameter'}
    
    client = bigquery.Client()
    table_id = os.environ['BIGQUERY_TABLE']
    
    query = f"SELECT plaintext FROM `{table_id}` WHERE hash = '{hash_value}' LIMIT 1"
    results = client.query(query)
    
    for row in results:
        return {
            'statusCode': 200,
            'body': json.dumps({'plaintext': row.plaintext})
        }
    
    return {'statusCode': 404, 'body': 'Hash not found'}

The cost model is where things get interesting. BigQuery charges approximately $5 per TB of data scanned. If your rainbow table is 100GB and you've indexed the hash column properly, a single lookup might scan only a few MB due to query pruning—costing fractions of a cent. Compare this to maintaining a server with sufficient storage and compute, and the economics favor cloud lookups for sporadic use cases.

The ingestion side requires more planning. Generating rainbow tables locally then uploading to BigQuery involves considerable bandwidth and time, but it's a one-time cost. You'd typically generate chains using traditional tools, convert to CSV format, and bulk-load into BigQuery using the bq load command or the Python client library. Partitioning strategies become crucial at scale—you might partition by hash prefix to optimize query performance and cost.

One clever optimization the project enables is collaborative rainbow tables. Multiple researchers could contribute to a shared BigQuery dataset, pooling computational resources. BigQuery's access controls let you manage permissions at the table or even column level, creating possibilities for commercial or academic hash cracking services that were impractical with file-based rainbow tables.

Gotcha

The most significant limitation is cost unpredictability. While individual queries are cheap, BigQuery pricing depends on data scanned, not rows returned. Without proper indexing and partitioning, queries could scan your entire table every time, making costs spiral quickly. A poorly optimized 1TB rainbow table could cost $5 per lookup—far more expensive than local alternatives. You need to deeply understand BigQuery's query execution model and optimization strategies to make this economically viable.

The project's minimal documentation and proof-of-concept status present practical barriers. There's no clear guidance on which hash algorithms are supported, optimal table schemas for different use cases, or performance benchmarks comparing costs versus traditional methods. The code appears to be an experimental demonstration rather than a production tool, meaning you'll spend significant time reverse-engineering implementation details and building your own tooling around the core concept. Additionally, you're locked into Google's ecosystem and pricing—if BigQuery costs increase or service terms change, your entire infrastructure is affected. Finally, this approach requires internet connectivity and introduces latency that local rainbow tables avoid, making it unsuitable for offline scenarios or time-critical applications where every millisecond matters.

Verdict

Use if: You're conducting security research that requires occasional hash lookups without maintaining local infrastructure, you're exploring novel cloud-native approaches to offensive tooling, you need to share rainbow tables collaboratively across teams or organizations, or you want to experiment with repurposing data warehouses for unconventional use cases. The serverless model particularly shines for infrequent lookups where maintaining dedicated cracking hardware isn't justified. Skip if: You need a mature, well-documented production tool with community support, you're cost-sensitive at scale or require predictable pricing, you need offline capabilities or minimal latency, you're cracking hashes frequently enough that local infrastructure becomes more economical, or you require extensive hash algorithm support with proven performance characteristics. For most practical password cracking scenarios, hashcat or John the Ripper remain superior choices—Big Rainbow is best viewed as an architectural thought experiment that demonstrates cloud database flexibility rather than a daily-driver security tool.

// ADD TO YOUR README
[![Featured on Starlog](https://starlog.is/api/badge/developer-tools/moloch-big-rainbow.svg)](https://starlog.is/api/badge-click/developer-tools/moloch-big-rainbow)