Analyzing the SonicWall Custom Grub LUKS Encryption Modifications
SonicWall NSv appliances use a modified GRUB LUKS module that derives the disk encryption passphrase from the LUKS header itself, so anyone with the disk image can decrypt the core partitions. An attacker with local access to the virtual disk image could recover the keys and gain root access to the appliance.
Published on praetorian.com
Recently, we decided to perform some reverse engineering of the SonicWall NSv appliance to identify any potential remote code execution vulnerabilities within the appliance. During our initial analysis of a virtual machine image for the application, we discovered a customized LUKS encryption mechanism meant to hinder…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The custom GRUB LUKS module derives the decryption passphrase from the LUKS header (mk-digest and mk-digest-salt) using a reversible XOR-based algorithm, making the key recoverable from the disk image alone.
Impact
An attacker with access to the virtual disk image could decrypt the core partitions and gain full root access to the appliance, as demonstrated by modifying /etc/passwd and creating a SUID bash binary.
What the attacker needed
Access to the virtual disk image; ability to run Qemu and GDB
The fix
The custom key-derivation algorithm should be replaced with a proper LUKS implementation that uses a secret passphrase not derivable from the disk header.
How it was found
- Boot the appliance in Qemu with GDB debugging enabled.
- Use the GRUB recovery shell to load the luks, crypto, gcry_rijndael, and gcry_sha256 modules.
- Search memory for the LUKS_KEY_ENABLED constant pattern to locate the luks_recover_key function.
- Set a breakpoint on grub_crypto_pbkdf2 and trigger decryption with cryptomount.
- Read the passphrase from the RSI register when the breakpoint is hit.
- Use the recovered key with cryptsetup to decrypt and mount the partitions.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The appliance stores its main files on an encrypted disk, and the password to unlock that disk is generated from public information stored on the disk itself. This means anyone who gets a copy of the disk image can work out the password and read or change the files, including gaining full control of the appliance.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.