Rollan Forensics
Technical Deep Dive

Bitcoin Core wallet.dat Forensic Recovery

By Rollan Abdalov January 20, 2026

The wallet.dat file is the cornerstone of Bitcoin Core. When this file becomes corrupted or the "BerkeleyDB" header is damaged, standard Bitcoin software will refuse to open. This guide covers how to perform a **forensic dump** of the raw keys.

1. Understanding the BerkeleyDB Structure

Most wallet.dat files use BerkeleyDB (BDB). Inside, data is stored in "pages." A corrupted header doesn't mean the keys are gone; it just means the index is broken. We treat the file as a raw data stream.

2. Extracting Keys with PyWallet

The most reliable tool for non-destructive discovery is PyWallet. It bypasses the standard BDB library and reads the byte-stream directly.

git clone https://github.com/jackjack-jj/pywallet
python2 pywallet.py --dumpwallet --datadir=/path/to/backup

This will output your private keys in WIF (Wallet Import Format) if the wallet is unencrypted.

3. Extracting Hashes for Hashcat

If the wallet is encrypted and you have forgotten the password, you must extract the **Master Key Hash**. We use a specialized script from the John the Ripper suite.

python3 bitcoin2john.py wallet.dat > hash.txt

The resulting hash can then be imported into Hashcat using mode 11300. On a modern forensic cluster, we can test hundreds of thousands of password variations per second.

4. Hex-Level Forensic Carving

When the filesystem itself is corrupted (e.g., after a sudden power loss), the wallet.dat might be fragmented across physical sectors. In these cases, we perform **signature-based carving**. We search for the specific BerkeleyDB page magic bytes and the ASN.1 / BER (Basic Encoding Rules) patterns that denote a Bitcoin private key.

Private keys in a wallet.dat file are typically preceded by the hex sequence 04 20 (denoting an Octet String of 32 bytes). By scanning the raw disk image for these markers followed by high-entropy data, we can often recover "ghost" wallets that have been deleted for months.

5. The "Midget" Attack and Key Recovery

For users who remember *most* of their password but have a few characters wrong, we employ what is known in the forensic community as a "Midget" attack (mask-based brute force). This reduces the search space from quintillions of combinations to a manageable few billion, often resulting in a successful recovery within 24-48 hours.