Skip to contentSkip to conversation

some ideas for recovery?

dm-crypt Ralf 4 participants 5 messages Aug 25, 2011

lore
Share & tools
lore

Ralf

author
#0 lore raw

Hi,

I have a problem accessing my data, I have backups but I try to understand what happened so it does not happen again. So maybe you can help me to understand the problem I am faced with.

I run a mdadm-software-raid6 across 4x 1TB sata disks resulting in a ~2TB /dev/md0. This md0 is consistent and never had issues.

Unfortunately I can't remember anymore what I did above md0. I used it for years and the cryped volume just did appear in my ubuntu gnome panel and I just had to click on it, enter the luks passwort, then got another sudo request for mounting the fs and the data was mounted. I will better document the createion this time so I remember it later.

Now my initial problem was that the icon for the crypted volume did not appear in gnome panel anymore. I don't think I lvm'ed md0 - this is because I looked into /etc/lvm/archive+backup and found no reference to a volume group or logical volume. I am unsure if I did put a partition table ontop md0, I assume not.

So assuming I did just run the cryptsetup create against /dev/md0 and ubuntu re- recognized it after each boot based on the luks header - the luks header should have been at offset 0 - right?

I inspected the md0 device and found:

- no partition table but random data
- no lvm metadata
- intact luks header at offset 65536 (0x10000)

I cant get any clue out of the first 64 byte of md0 - it just looks like random data when I "hexdump -C" it. At least I found no ASCII data I would recognize as something like partition table of lvm metadata.

So I created a loopback device for md0 starting at offset 0x10000 and luksDump is able to analyze the header:

# losetup -v -o 65536 -r /dev/loop0 /dev/md0
# cryptsetup luksDump /dev/loop0

LUKS header information for /dev/loop0

Version:       	1
Cipher name:   	aes
Cipher mode:   	xts-plain
Hash spec:     	sha1
Payload offset:	4040
MK bits:       	512
MK digest:     	4b 00 fa c4 2b af 2e 0d 66 8f 42 34 c0 de 76 b4 31 4b a4 2f 
MK salt:       	4e 08 49 1d 66 11 f2 a2 d3 0b 8a 73 50 cf 8f 35 
               	58 38 e1 1d ea a4 23 1a bc 72 50 4b e0 49 25 2c 
MK iterations: 	10
UUID:          	2f8f3b39-6b74-4c0d-85fe-522e7850674d

Key Slot 0: ENABLED

	Iterations:         	299227
	Salt:               	69 fe 1c 07 3b 90 40 70 a7 55 85 45 9a 14 07 aa 
	                      	fd d9 6d a1 14 fb aa 74 9f 3f 0b 43 17 2e b8 ee 
	Key material offset:	8
	AF stripes:            	4000

Key Slot 1: DISABLED
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED

However, if I use luksOpen it does not accept my password. I am 100% sure that the password I enter is the one I used in advance to the problem to decrypt the disk.

The md0 looks like this:

# fdisk -l /dev/md0 

Disk /dev/md0: 2000.4 GB, 2000409591808 bytes 2 heads, 4 sectors/track, 488381248 cylinders Units = cylinders of 8 * 512 = 4096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 65536 bytes / 131072 bytes Disk identifier: 0x8539aa5e

Disk /dev/md0 doesn't contain a valid partition table

Depending on the fact that the first 64k look random and the 2nd 64k are the luks header - I just tried to swapt block1 and block2:

# dd if=/dev/md0 of=/tmp/b1 bs=65536 count=1
# dd if=/dev/md0 of=/tmp/b2 bs=65536 skip=1 count=1
# dd if=/dev/md0 of=/tmp/b3-100 bs=65536 skip=2 count=98
# cat /tmp/b2 /tmp/b1 /tmp/b3-100 >>/tmp/b1-100_reordered
# losetup -v /dev/loop1 /tmp/b1-100_reordered
# cryptsetup luksopen /dev/loop1 data

However, this still does not work.

Would it even be enough to have 99*64k behind the luks header to decrypt the FS? Or what exact blocks would it need to for the IV calculations or decryption? Is there a way to randomly try to decrypt specific blocks using the luksheader + my well known password to check if it works or not?

Can you explain why my luks header is at offset 64k and why it may reject my password on the offsetted loopback device?

Do you have any idea what might have happened?

thanks in advance
Ralf

#1 lore raw
Quoted 2 lines · Ralf

Depending on the fact that the first 64k look random and the 2nd 64k are the luks header - I just tried to swapt block1 and block2:

64k is not enough, you need to copy the whole luks header including keyslots,

Quoted 1 line

Payload offset: 4040

so you need at least 512 * 4040 bytes of header, do not skip any data, just dd the whole area + some more so there is some data and try luksOpen.

Quoted 1 line

Would it even be enough to have 99*64k behind the luks header to decrypt the FS?

to verify that passphrase works it should be, see above

Quoted 3 lines

Or what exact blocks would it need to for the IV calculations or decryption? Is there a way to randomly try to decrypt specific blocks using the luksheader + my well known password to check if it works or not?

passphrase just unlocks keyslot and you need decrypt master key from keyslot, if the keyslot is corrupted, there is no way to recover it.
(or you need binary backup of header or master key dump to recover)

Quoted 2 lines

Can you explain why my luks header is at offset 64k and why it may reject my password on the offsetted loopback device?

LUKS/cryptsetup never writes header to such offset, LUKS always starts at 0 offset. It seems like some mdadm/MD problem (64k is usually MD chunk size).

You should check that keyslot area is not damaged (you have only one keyslot active, starting at sector 8 to sector 512 (iow 0x1000 - 0x40000 - if I am not mistaken). There should be "ranadom data", any non-random sequence in this aread means that it was overwritten.

Milan

p.s.
for more info see
http://code.google.com/p/cryptsetup/wiki/FrequentlyAskedQuestions#6._Backup_and_Data_Recovery

#4 lore raw
In reply to Ralf
Quoted 10 lines · Ralf

Hi,

I have a problem accessing my data, I have backups but I try to understand what happened so it does not happen again. So maybe you can help me to understand the problem I am faced with.

I run a mdadm-software-raid6 across 4x 1TB sata disks resulting in a ~2TB /dev/md0. This md0 is consistent and never had issues.

[...]

Quoted 6 lines

Would it even be enough to have 99*64k behind the luks header to decrypt the FS? Or what exact blocks would it need to for the IV calculations or decryption? Is there a way to randomly try to decrypt specific blocks using the luksheader + my well known password to check if it works or not?

As you can see in the FAQ, item "What does the on-disk structure of LUKS look like?" a LUKS header keyslot with standard parameters is 128kiB long, so no, it is not enough. Incidentally, with XTS as you are using, it is 256kiB and you need to add 4096B offset for the header. All in the FAQ.

You should realy have a look at the FAQ before you fumble in the dark like that.

You should also have a look a the "PASSPHRASES" warning at the start of the FAQ.

And no, wihout an intact keyslot, you password is worthless.

On the other hand, if header and keyslot werw intact, you would be abnle to luksOpen. cryptsetup does not care where the header is or what device it is on, as long as it gets told the offset of its start.

Quoted 2 lines

Can you explain why my luks header is at offset 64k and why it may reject my password on the offsetted loopback device?

Keyslot damage? There is a reason the FAQ strongly recommends having a header backup.

Quoted 1 line

Do you have any idea what might have happened?

No idea. A possible next step (after you have read up on the LUKS on disk structure) is to look at keyslot 0 and the other keyslots. Keyslot 1-7 should be zeroed. Keyslot 0 should be all random-looking without any discernable structure at all. If it is not, then something wrote into it and effectively erased it, courtesy of the anti-forensivc properties of LUKS.

As to preventing this happening again: Read the FAQ, have a header backup, understand you on-disk structure and you should be fine.

Arno

Signature · 7 lines
Arno Wagner, Dr. sc. techn., Dipl. Inform., CISSP -- Email: [email protected] 
GnuPG:  ID: 1E25338F  FP: 0C30 5782 9D93 F785 E79C  0296 797F 6B50 1E25 338F
----
Cuddly UI's are the manifestation of wishful thinking. -- Dylan Evans

If it's in the news, don't worry about it.  The very definition of 
"news" is "something that hardly ever happens." -- Bruce Schneier 
#2 lore raw
In reply to Milan Broz
Quoted 2 lines · Milan Broz

You should check that keyslot area is not damaged (you have only one

keyslot active,

Quoted 1 line

starting at sector 8 to sector 512 (iow 0x1000 - 0x40000 - if I am not

mistaken).

Quoted 1 line

There should be "ranadom data", any non-random sequence in this aread

means that

Quoted 1 line

it was overwritten.

Hi Milan, thanks for your fast response. I got your point. I inspected the whole data in a bit more detail and its interesting:

00000000 4c 55 4b 53 ba be 00 01 61 65 73 00 00 00 00 00
|LUKS....aes.....| <-- this is actually offset 64k in regards to md0 (here
0 @ loop1 with offset 64k)
...
<-- LUKS header data
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|................|
*
<-- end of LUKS header
00001000 0b f9 97 1d e4 3e b1 91 6a 96 2e 54 4a 28 50 b9
|.....>..j..TJ(P.| <-- so here we start with keyslot1 0x1000-0x40000
...
0002fff0 21 46 ef b6 31 51 6b d5 c9 9e d2 77 27 53 b3 6e
|!F..1Qk....w'S.n| <-- everything looks normal random up to here, weird
signature afterwards up to 0x40000
00030000 00 00 fd 29 30 00 fd 29 60 00 fd 29 3d e1 00 60

 |...)0..)`..)=..`|
00030010  00 00 0f 00 00 00 00 00  00 00 00 00 00 60 98 6b
 |.............`.k|
00030020  03 00 fd 29 33 00 fd 29  60 06 fd 29 00 9d 00 60
 |...)3..)`..)...`|
00030030  00 00 09 00 00 00 00 00  00 00 00 00 00 60 1f db
 |.............`..|
00030040  06 00 fd 29 36 00 fd 29  60 0c fd 29 00 9d 00 60
 |...)6..)`..)...`|
00030050  00 00 09 00 00 00 00 00  00 00 00 00 00 60 ad 25
 |.............`.%|
00030060  05 00 fd 29 35 00 fd 29  60 0a fd 29 00 9d 00 60
 |...)5..)`..)...`|
00030070  00 00 09 00 00 00 00 00  00 00 00 00 00 60 dd d8
 |.............`..|
00030080  0c 00 fd 29 3c 00 fd 29  60 18 fd 29 00 9d 00 60
 |...)<..)`..)...`|
00030090  00 00 09 00 00 00 00 00  00 00 00 00 00 60 d1 23
 |.............`.#|
000300a0  0f 00 fd 29 3f 00 fd 29  60 1e fd 29 00 9d 00 60
 |...)?..)`..)...`|
000300b0  00 00 09 00 00 00 00 00  00 00 00 00 00 60 a1 de
 |.............`..|
000300c0  0a 00 fd 29 3a 00 fd 29  60 14 fd 29 00 9d 00 60
 |...):..)`..)...`|
000300d0  00 00 09 00 00 00 00 00  00 00 00 00 00 60 13 20  |.............`.
|
000300e0  09 00 fd 29 39 00 fd 29  60 12 fd 29 00 9d 00 60
 |...)9..)`..)...`|
000300f0  00 00 09 00 00 00 00 00  00 00 00 00 00 60 63 dd
 |.............`c.|
00030100  18 00 fd 29 28 00 fd 29  60 30 fd 29 00 9d 00 60
 |...)(..)`0.)...`|
00030110  00 00 09 00 00 00 00 00  00 00 00 00 00 60 0e 2c
 |.............`.,|
00030120  1b 00 fd 29 2b 00 fd 29  60 36 fd 29 00 9d 00 60
 |...)+..)`6.)...`|
00030130  00 00 09 00 00 00 00 00  00 00 00 00 00 60 7e d1
 |.............`~.|
00030140  1e 00 fd 29 2e 00 fd 29  60 3c fd 29 00 9d 00 60
 |...)...)`<.)...`|
00030150  00 00 09 00 00 00 00 00  00 00 00 00 00 60 cc 2f
 |.............`./|
00030160  1d 00 fd 29 2d 00 fd 29  60 3a fd 29 00 9d 00 60
 |...)-..)`:.)...`|
00030170  00 00 09 00 00 00 00 00  00 00 00 00 00 60 bc d2
 |.............`..|
00030180  14 00 fd 29 24 00 fd 29  60 28 fd 29 00 9d 00 60
 |...)$..)`(.)...`|
...
   <-- similar signature as above
0003ffe0  11 00 b5 3d 21 00 b5 3d  60 22 b5 3d 00 9d 00 60
 |...=!..=`".=...`| <-- end of weird signature
0003fff0  00 00 09 00 00 00 00 00  00 00 00 00 00 60 88 87
 |.............`..| <-- end of keyslot 1
00040000  00 00 a0 13 10 00 a0 13  20 00 a0 13 e0 5f 00 20  |........ ...._.
|
00040010  00 00 05 00 00 00 00 00  00 00 00 00 00 20 07 09  |.............
..|
00040020  01 00 a0 13 11 00 a0 13  20 02 a0 13 00 80 00 20  |........ ......
|
00040030  00 00 07 00 00 00 00 00  00 00 00 00 00 20 7a 92  |.............
z.|

interestingly keyslot1 looks good up to 0x2FFFF (3x64k from start of LUKS header) which leaves 64k garbage at the end of keyslot1 up to 0x40000 where keyslot2 starts.
However, the garbage signature changes at 0x3fff0 even before the end of keyslot1

So I tried to put the md0 initial 64k random data into the 64k gap area of keyslot1

# dd if=/dev/md0 of=/tmp/01_luksdata1 bs=64k skip=1 count=3
# dd if=/dev/md0 of=/tmp/02_initial_64k bs=64k count=1
# dd if=/dev/md0 of=/tmp/03_luksdata2_data bs=64k skip=5 count=100
# cat 01_luksdata1 02_initial_64k 03_luks_leftover >04_rebuild
# losetup -v /dev/loop1 /tmp/04_rebuild

but if does not accept my password anyways. So I assume keyslot1 is gone forever.
Still totally unclear to me how this could have happened.

#3 lore raw
Quoted 6 lines · Ralf Kaestner
Quoted 2 lines · Milan Broz

You should check that keyslot area is not damaged (you have only one

keyslot active,

Quoted 1 line

starting at sector 8 to sector 512 (iow 0x1000 - 0x40000 - if I am not

mistaken).

0x1000-0x3f800 actually, as it is a bit less than 256kiB. 0x3f800-0x40000 is zero (or whatever was on disk before) and the second keyslot starts at 0x40000. This just means non-random data in 0x3f800-0x40000 is fine.

Quoted 8 lines
Quoted 1 line

There should be "ranadom data", any non-random sequence in this aread

means that

Quoted 1 line

it was overwritten.

Hi Milan, thanks for your fast response. I got your point. I inspected the whole data in a bit more detail and its interesting:

Quoted 15 lines

00000000 4c 55 4b 53 ba be 00 01 61 65 73 00 00 00 00 00
|LUKS....aes.....| <-- this is actually offset 64k in regards to md0 (here
0 @ loop1 with offset 64k)
...
<-- LUKS header data
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|................|
*
<-- end of LUKS header
00001000 0b f9 97 1d e4 3e b1 91 6a 96 2e 54 4a 28 50 b9
|.....>..j..TJ(P.| <-- so here we start with keyslot1 0x1000-0x40000
...
0002fff0 21 46 ef b6 31 51 6b d5 c9 9e d2 77 27 53 b3 6e
|!F..1Qk....w'S.n| <-- everything looks normal random up to here, weird
signature afterwards up to 0x40000

Not good.

Quoted 74 lines

00030000 00 00 fd 29 30 00 fd 29 60 00 fd 29 3d e1 00 60

 |...)0..)`..)=..`|
00030010  00 00 0f 00 00 00 00 00  00 00 00 00 00 60 98 6b
 |.............`.k|
00030020  03 00 fd 29 33 00 fd 29  60 06 fd 29 00 9d 00 60
 |...)3..)`..)...`|
00030030  00 00 09 00 00 00 00 00  00 00 00 00 00 60 1f db
 |.............`..|
00030040  06 00 fd 29 36 00 fd 29  60 0c fd 29 00 9d 00 60
 |...)6..)`..)...`|
00030050  00 00 09 00 00 00 00 00  00 00 00 00 00 60 ad 25
 |.............`.%|
00030060  05 00 fd 29 35 00 fd 29  60 0a fd 29 00 9d 00 60
 |...)5..)`..)...`|
00030070  00 00 09 00 00 00 00 00  00 00 00 00 00 60 dd d8
 |.............`..|
00030080  0c 00 fd 29 3c 00 fd 29  60 18 fd 29 00 9d 00 60
 |...)<..)`..)...`|
00030090  00 00 09 00 00 00 00 00  00 00 00 00 00 60 d1 23
 |.............`.#|
000300a0  0f 00 fd 29 3f 00 fd 29  60 1e fd 29 00 9d 00 60
 |...)?..)`..)...`|
000300b0  00 00 09 00 00 00 00 00  00 00 00 00 00 60 a1 de
 |.............`..|
000300c0  0a 00 fd 29 3a 00 fd 29  60 14 fd 29 00 9d 00 60
 |...):..)`..)...`|
000300d0  00 00 09 00 00 00 00 00  00 00 00 00 00 60 13 20  |.............`.
|
000300e0  09 00 fd 29 39 00 fd 29  60 12 fd 29 00 9d 00 60
 |...)9..)`..)...`|
000300f0  00 00 09 00 00 00 00 00  00 00 00 00 00 60 63 dd
 |.............`c.|
00030100  18 00 fd 29 28 00 fd 29  60 30 fd 29 00 9d 00 60
 |...)(..)`0.)...`|
00030110  00 00 09 00 00 00 00 00  00 00 00 00 00 60 0e 2c
 |.............`.,|
00030120  1b 00 fd 29 2b 00 fd 29  60 36 fd 29 00 9d 00 60
 |...)+..)`6.)...`|
00030130  00 00 09 00 00 00 00 00  00 00 00 00 00 60 7e d1
 |.............`~.|
00030140  1e 00 fd 29 2e 00 fd 29  60 3c fd 29 00 9d 00 60
 |...)...)`<.)...`|
00030150  00 00 09 00 00 00 00 00  00 00 00 00 00 60 cc 2f
 |.............`./|
00030160  1d 00 fd 29 2d 00 fd 29  60 3a fd 29 00 9d 00 60
 |...)-..)`:.)...`|
00030170  00 00 09 00 00 00 00 00  00 00 00 00 00 60 bc d2
 |.............`..|
00030180  14 00 fd 29 24 00 fd 29  60 28 fd 29 00 9d 00 60
 |...)$..)`(.)...`|
...
   <-- similar signature as above
0003ffe0  11 00 b5 3d 21 00 b5 3d  60 22 b5 3d 00 9d 00 60
 |...=!..=`".=...`| <-- end of weird signature
0003fff0  00 00 09 00 00 00 00 00  00 00 00 00 00 60 88 87
 |.............`..| <-- end of keyslot 1
00040000  00 00 a0 13 10 00 a0 13  20 00 a0 13 e0 5f 00 20  |........ ...._.
|
00040010  00 00 05 00 00 00 00 00  00 00 00 00 00 20 07 09  |.............
..|
00040020  01 00 a0 13 11 00 a0 13  20 02 a0 13 00 80 00 20  |........ ......
|
00040030  00 00 07 00 00 00 00 00  00 00 00 00 00 20 7a 92  |.............
z.|

interestingly keyslot1 looks good up to 0x2FFFF (3x64k from start of LUKS header) which leaves 64k garbage at the end of keyslot1 up to 0x40000 where keyslot2 starts.
However, the garbage signature changes at 0x3fff0 even before the end of keyslot1

So I tried to put the md0 initial 64k random data into the 64k gap area of keyslot1

Quoted 8 lines
# dd if=/dev/md0 of=/tmp/01_luksdata1 bs=64k skip=1 count=3
# dd if=/dev/md0 of=/tmp/02_initial_64k bs=64k count=1
# dd if=/dev/md0 of=/tmp/03_luksdata2_data bs=64k skip=5 count=100
# cat 01_luksdata1 02_initial_64k 03_luks_leftover >04_rebuild
# losetup -v /dev/loop1 /tmp/04_rebuild

but if does not accept my password anyways. So I assume keyslot1 is gone forever.

It is. A signle changes bit makes it unreadable. That is the whole point.

Quoted 1 line

Still totally unclear to me how this could have happened.

I agree.

First, I think the 64k offset are some additional LVM wrapping or the like and have nothing to do with the corruption.

The question then becomes what is in this changed area. It looks a bit like filesystem management data. The offset of 0x30000 = 196kiB seems to indicate something non-random. Could also be 128kiB offset, if the problem was affected by the 64kiB shift.

This does not look like something from an empty FAT32 or ext2 filesystem. Maybe a 32 bit entry color-table? Definietly some kind of table, but I have no idea what type.

Arno

Signature · 7 lines
Arno Wagner, Dr. sc. techn., Dipl. Inform., CISSP -- Email: [email protected] 
GnuPG:  ID: 1E25338F  FP: 0C30 5782 9D93 F785 E79C  0296 797F 6B50 1E25 338F
----
Cuddly UI's are the manifestation of wishful thinking. -- Dylan Evans

If it's in the news, don't worry about it.  The very definition of 
"news" is "something that hardly ever happens." -- Bruce Schneier