Back to Articles

Defending Against Cosmic Rays: How bf-lookup Detects Bit-Flip Domain Hijacking

[ View on GitHub ]

Defending Against Cosmic Rays: How bf-lookup Detects Bit-Flip Domain Hijacking

Hook

A cosmic ray flipping a single bit in your browser's memory could redirect you from bank.com to a phishing site—and attackers are already registering these domains.

Context

In 2016, Mozilla researcher Filippo Valsorda demonstrated that bit-flip errors caused by cosmic rays, hardware faults, or Rowhammer-style attacks could redirect DNS queries to attacker-controlled domains. The attack vector is elegant: if a single bit in the string "google.com" flips in memory—say, the 'g' (ASCII 0x67) becomes 'w' (ASCII 0x77) due to a one-bit change—a user might unknowingly visit a malicious domain. While the probability of any single bit flip is astronomically low, attackers can pre-register thousands of single-bit variations of popular domains and wait for hardware errors to deliver victims.

This isn't theoretical paranoia. Research from Project Bitfl1p documented that certain single-bit flips produce valid ASCII domains, and adversaries have indeed registered these variants for major brands. The challenge for defenders is enumeration: given a domain like "amazon.com", which of the thousands of possible single-bit flips are actually registered? Manual checking is impractical. bf-lookup automates this reconnaissance, systematically generating every valid ASCII single-bit flip variation and querying WHOIS to identify registered typosquatting domains that could exploit hardware vulnerabilities.

Technical Insight

Reconnaissance

Core Algorithm

Yes

No

Yes

No

CLI Input: Target Domain

Bit Flip Generator

Valid ASCII?

Domain Variations List

WHOIS Query Engine

Domain Registered?

Output: Registered Variants

System architecture — auto-generated

bf-lookup's architecture is refreshingly straightforward—a single-purpose CLI tool that prioritizes correctness over complexity. The core algorithm iterates through each byte in the target domain string, then for each byte, flips each of its 8 bits individually. The key optimization is filtering: not all bit flips produce valid ASCII characters (printable range 0x20-0x7E), so the tool discards permutations that would create unparseable domain names.

Here's how the bit-flipping logic works conceptually:

func generateBitFlips(domain string) []string {
    var variations []string
    domainBytes := []byte(domain)
    
    for i := 0; i < len(domainBytes); i++ {
        originalByte := domainBytes[i]
        
        for bit := 0; bit < 8; bit++ {
            // Flip the bit at position 'bit'
            flippedByte := originalByte ^ (1 << bit)
            
            // Only keep if it's valid printable ASCII
            if flippedByte >= 0x20 && flippedByte <= 0x7E {
                domainCopy := make([]byte, len(domainBytes))
                copy(domainCopy, domainBytes)
                domainCopy[i] = flippedByte
                variations = append(variations, string(domainCopy))
            }
        }
    }
    
    return variations
}

For a domain like "test.com" (8 characters), this generates at most 64 variations (8 characters × 8 bits), though many are filtered out. The character 't' (0x74 in binary: 01110100) could flip to 'u', 'v', 'p', 'x', '|', 'd', 'l', or 't' with high bit set—but only valid ASCII characters are kept.

The WHOIS checking implementation is where bf-lookup shows its pragmatism. Rather than implementing a full WHOIS protocol parser for every TLD (a maintenance nightmare given varying registry formats), it relies on the system's existing WHOIS client. This is a classic Unix philosophy approach: do one thing well and compose with existing tools. The tool shells out to the whois command and parses stdout to determine if a domain is registered. Domains that return successful WHOIS data are marked with an asterisk in the output, signaling potential security risks.

The performance characteristics are bound by external I/O—specifically, WHOIS server response times and rate limiting. For a typical domain with 10-15 characters, you might generate 80-120 valid permutations. If each WHOIS query takes 500ms, a full scan could take 40-60 seconds. The tool doesn't implement concurrency or caching, which keeps the codebase simple but means scanning multiple domains requires sequential processing. For security researchers auditing a domain portfolio, this is acceptable; for real-time monitoring systems, you'd need to build a wrapper with parallelization.

One subtle design choice worth noting: bf-lookup operates on the full domain string, including the TLD. This means "example.com" and "example.org" would generate different flip sets. A bit flip in the 'm' of ".com" could theoretically produce ".col" or ".con"—though these aren't valid TLDs, the tool still generates them. This exhaustive approach ensures no theoretical variant is missed, even if it's DNS-invalid.

Gotcha

The most significant limitation is WHOIS rate limiting. Many TLD registries throttle queries aggressively—some allow only a handful per minute from a single IP. When scanning domains with 100+ character permutations, you'll frequently hit rate limits that manifest as empty WHOIS responses or temporary blocks. The tool doesn't implement exponential backoff or retry logic, so you'll get incomplete results without manual intervention. For production security workflows, you'd need to wrap bf-lookup with rate-limiting middleware or use commercial WHOIS APIs that offer higher quotas.

The single-bit assumption is both a strength and weakness. Real-world bit flips from cosmic rays or Rowhammer attacks are indeed typically single-bit events, making this threat model accurate. However, other typosquatting techniques—homoglyphs (replacing 'o' with '0'), keyboard adjacency ('google.com' to 'googke.com'), or vowel swaps—are far more common attack vectors. bf-lookup won't catch these. If your goal is comprehensive brand protection, this tool covers maybe 5% of the actual typosquatting threat landscape. Additionally, the WHOIS output is minimal—just a marker if a domain exists. You don't learn when it was registered, who owns it, or whether it's actually malicious versus an innocent coincidence. For triage, you'll need to feed results into secondary tools for analysis.

Verdict

Use bf-lookup if you're conducting security research into hardware-based attack vectors, performing academic studies on bit-flip domain hijacking, or doing boutique security audits for high-value domains where even exotic attack vectors matter (think Fortune 500 brands or critical infrastructure). It's perfect for generating input datasets for broader threat intelligence pipelines or for one-time scans to check if attackers have preemptively registered bit-flip variants of your domains. Skip it if you need general typosquatting protection—tools like dnstwist or URLCrazy cover 20+ permutation types and are better suited for day-to-day brand monitoring. Also skip if you're expecting enterprise-grade features like alerting, historical tracking, or bulk processing; bf-lookup is a focused research utility, not a monitoring platform. Best thought of as a specialized probe for one specific corner of the threat landscape rather than a comprehensive defensive tool.

// ADD TO YOUR README
[![Featured on Starlog](https://starlog.is/api/badge/developer-tools/bored-engineer-bf-lookup.svg)](https://starlog.is/api/badge-click/developer-tools/bored-engineer-bf-lookup)