6

From: https://code.google.com/p/cryptsetup/wiki/FrequentlyAskedQuestions

CLONING/IMAGING: If you clone or image a LUKS container, you make a copy 
of the LUKS header and the master key will stay the same! That means that if 
you distribute an image to several machines, the same master key will be used 
on all of them, regardless of whether you change the passphrases. Do NOT do this! 
If you do, a root-user on any of the machines with a mapped (decrypted) container 
or a passphrase on that machine can decrypt all other copies, breaking security. 
See also Item 6.15. 

So: I have a notebook "A" (a Linux Desktop installed with LUKS & and I have root access to it) and I clone the whole disk of it to notebook "B", and the notebook "B" had it's LUKS password changed.

My question: How can I mount/decrypt notebook "B" LUKS partition with ONLY the known master key from "A"?* (and I know the cipher type too)

*UPDATE: What are the exact commands to mount the B's HDD on A?

1
  • See also luksHeaderBackup / luksHeaderRestore – frostschutz Mar 15 '14 at 17:48
7

Opening a LUKS volume leads to the creation of a new device mapper object. Let's assume the original (LVM) volume is storage-crypto (from a DM perspective) and the decrypted volume is called crypto. You get the device mapper configuration by this:

dmsetup table --showkeys crypto
0 104853504 crypt aes-cbc-essiv:sha256 b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c 0 253:5 4096

The key part is exactly what you get from

cryptsetup luksDump --dump-master-key /dev/storage/crypto

I.e. if you know the cipher and the key then you can set up such a DM volume yourself.

See the kernel documentation about this device mapper target (dm-crypt).

In order to decrypt a LUKS volume you have to determine the size of the volume in 512-byte blocks:

blockdev --getsz /dev/sda1
104857600

With this value you can create a new DM volume. This should work:

echo "0 104857600 crypt aes-cbc-essiv:sha256 "\
"b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c "\
"0 /dev/sda1 4096" | dmsetup create luks_volume
5
  • dmsetup would work fine, or you could replace the LUKS header and cryptsetup luksOpen – frostschutz Mar 15 '14 at 17:41
  • Can you please describe the opening part in more detail? Thanks! ex.: I have the notebook "B"'s HDD in an USB rack, plugged in tho notebook "A". – evachristine Mar 16 '14 at 9:26
  • @evachristine What exactly do you want explained? – Hauke Laging Mar 16 '14 at 13:50
  • sorry, updated the original questions. Thanks. – evachristine Mar 16 '14 at 20:55
  • @evachristine I added some info to the answer. – Hauke Laging Mar 16 '14 at 22:31
2

Provided you have the master key and are root

cryptsetup --master-key-file pathToMasterKey luksOpen /dev/sdX bHDD
mount /dev/mapper/bHDD /mnt/bHDD

If you need to obtain the master key have A drive decrypted and run the following as root

dmsetup table --showkeys

copy the key and put it into a text file then run

xxd -r -p masterKey.txt masterKey.bin

you would use masterKey.bin in your cryptsetup command as the master key file

1

First off, you should only use the masterkey if you don't know the passphrase anymore. Because if someone knows your passphrase you can change it, but if someone knows your masterkey you have to reformat the whole disk/partition and restore your backup to change it. So only use the masterkey to add a new passphrase.

Assuming the header is intact and you already have the masterkey this are the steps to add a new passphrase:

1. Backup the LUKS header in case something goes wrong

cryptsetup luksHeaderBackup --header-backup-file <file> <device>

2. Create a file with the masterkey in binary form

When you backup the masterkey you will get an output like this:

0 200704 crypt aes-cbc-essiv:sha256
a1704d9715f73a1bb4db581dcacadaf405e700d591e93e2eaade13ba653d0d09
0 7:0 4096

The long hex string is the masterkey, to create the binary file use this command:

Warning: Before you execute the command, make sure the file is stored on an encrypted place, and delete it after the procdure!

echo "masterkey" | xxd -r -p > <master-key-file>

3. Add a new passphrase

cryptsetup luksAddKey --master-key-file=<master-key-file> <luks device>

Now you can mount LUKS from the command line or use a GUI tool like a file explorer or the gnome-disk-utility.

In case this didn't solve the problem you should have a look on the Backup and Data Recovery section of the cryptsetup wiki.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.