Recover LUKS partition from deleted partition table
Whilst repartitioning my drive trying to move & enlarge my LUKS partition, I fubar'd the partition table and tried to recreate it from scratch using testdisk. However, testdisk hasn't been able to properly discover the partition; it found the LUKS header and created a logical partition 1 cylinder in size; I can do a luksDump from it, and I can see crypt settings, key slots etc., however the partition's too small to be able to access any data. So I enlarged the discovered logical partition starting at the LUKS header (found using hexdump -C /dev/sda|grep "4c 55 4b 53 ba be") and extending it back to its original 40GB, however when I try to enter the password for it cryptsetup won't accept it (I am doing cryptsetup luksOpen /dev/sda5 root). Help?
--Kyle
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Just posting this so if anyone has the same issue as me, they'll be able to find this solution.
--Kyle Bond
---------- Forwarded message ----------
From: Arno Wagner <[email protected]>
Date: Fri, Oct 2, 2009 at 11:20 PM
Subject: Re: [dm-crypt] Recover LUKS partition from deleted partition table
To: Kyle Bond <[email protected]>
Hi Kyle,
Quoted 2 lines · Kyle Bond
Thanks for commenting the hexdump in such detail; made things a lot easier for me to understand.
Glad to be able to help. Of course if this would go up to multiple hours I would need to find my consulting hat and charge you ;-)
Quoted 2 lines
I had a feeling my data was gone with the wind...at least I have a backup of most of the stuff that was on there.
Very good.
Quoted 4 lines
Now the real
question is how did that data get there? It looks to me like gparted overwrote the key with......"stuff" (looks like a logfile or something to me).
Would be my guess also.
Quoted 1 line
Thanks again for all the help! Now I'm off to utilize my backups...
You are welcome.
Arno
Quoted 33 lines
--Kyle Bond
Quoted 29 lines · Arno Wagner
Hi Kyle,
that does not look good. I found the following block at an offset of 64kB, right in the middle of keyslot 1:
00010000 30 30 30 30 30 30 30 00 6d 73 64 6f 73 00 4c 55 | 0000000.msdos.LU|
00010010 4b 53 ba be 00 65 78 74 65 6e 64 65 64 00 62 74 |KS... extended.bt|
00010020 72 66 73 00 65 78 74 34 64 65 76 00 6c 69 6e 75|rfs.ext4dev.linu| 00010030 78 2d 73 77 61 70 00 6c 69 6e 75 78 2d 73 77 61 |x-swap.linux-swa| 00010040 70 28 76 31 29 00 6c 69 6e 75 78 2d 73 77 61 70 |p(v1).linux-swap| 00010050 28 6e 65 77 29 00 6c 69 6e 75 78 2d 73 77 61 70 |(new).linux-swap| 00010060 28 76 30 29 00 6c 69 6e 75 78 2d 73 77 61 70 28 |(v0).linux-swap(| 00010070 6f 6c 64 29 00 66 61 74 31 36 00 66 61 74 33 32 |old).fat16.fat32| 00010080 00 68 66 73 00 68 66 73 2b 00 75 66 73 00 52 65 |.hfs.hfs+.ufs.Re| 00010090 49 73 45 72 34 00 4c 41 42 45 4c 4f 4e 45 00 4c |IsEr4.LABELONE.L| 000100a0 56 4d 32 00 5f 42 48 52 66 53 5f 4d 00 42 54 52 |VM2._BHRfS_M.BTR| 000100b0 46 53 20 69 73 20 6e 6f 74 20 79 65 74 20 73 75 |FS is not
yet
Quoted 4 lines
Quoted 4 lines
su|
000100c070 70 6f 72 74 65 64 2e 00 0a 2d 00 54 68 65 20|pported...-.The | 000100d0 66 69 6c 65 20 73 79 73 74 65 6d 20 69 73 20 64 |file system
is
Quoted 4 lines
Quoted 4 lines
d|
000100e061 6d 61 67 65 64 00 75 64 65 76 73 65 74 74 6c|amaged.udevsettl| 000100f0 65 00 75 64 65 76 73 65 74 74 6c 65 20 2d 2d 74
|e.udevsettle
Quoted 8 lines
Quoted 8 lines
--t|
00010100 69 6d 65 6f 75 74 3d 00 75 64 65 76 61 64 6d 20|imeout=.udevadm | 00010110 73 65 74 74 6c 65 20 2d 2d 74 69 6d 65 6f 75 74 |settle --timeout| 00010120 3d 00 75 73 69 6e 67 20 6c 69 62 70 61 72 74 65 |=.using libparte| 00010130 64 00 73 68 72 69 6e 6b 20 66 69 6c 65 20 73 79 |d.shrink
file
Quoted 2 lines
Quoted 2 lines
sy|
00010140 73 74 65 6d 00 67 72 6f 77 20 66 69 6c 65 20 73 |stem.grow
file
Quoted 2 lines
Quoted 2 lines
s|
00010150 79 73 74 65 6d 00 72 65 73 69 7a 65 20 66 69 6c
|ystem.resize
Quoted 6 lines
Quoted 6 lines
fil|
00010160 65 20 73 79 73 74 65 6d 00 64 65 6c 65 74 65 20 |e system.delete |
00010170 70 61 72 74 69 74 69 6f 6e 00 73 74 61 74 76 66|partition.statvf| 00010180 73 20 28 00 29 3a 20 00 55 6e 61 62 6c 65 20 74 |s (.):
.Unable
Quoted 2 lines
Quoted 2 lines
t|
00010190 6f 20 66 69 6e 64 20 6d 6f 75 6e 74 20 70 6f 69 |o find
mount
Quoted 25 lines
Quoted 25 lines
poi|
000101a06e 74 00 25 31 20 6f 66 20 25 32 20 72 65 61 64 |nt.%1 of %2 read|000101b020 28 25 33 20 72 65 6d 61 69 6e 69 6e 67 29 00 | (%3 remaining).|000101c025 31 20 6f 66 20 25 32 20 72 65 61 64 00 25 31 |%1 of %2 read.%1|000101d020 6f 66 20 25 32 20 63 6f 70 69 65 64 00 5e 28 | of %2 copied.^(|000101e02f 5b 5e 20 5d 2b 29 00 3d 3d 3d 3d 3d 3d 3d 3d |/[^ ]+).========|000101f03d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 00 6c
|==============.l|The commented hexdumop of your header is attached. It looks like something wrote the 512 bytes above to the partition at offset
0x10000and thereby destroyed the keyslot contents.Arno
Quoted 6 lines
Quoted 6 lines · Kyle Bond
Quoted 1 line
Thanks for clearing that up; I thought simply a hashed copy of the key
was
Quoted 3 lines
stored in the keyslot and the key itself wasn't stored on the drive.
I do believe my key was overwritten as the other LUKS drives that I
have
Quoted 2 lines
Quoted 2 lines
and
Quoted 1 line
the test luks-formatted loop files I created all have zeros from
0x250
to
Quoted 1 line
Quoted 1 line
Quoted 1 line
0x1000, but the drive I'm having problems with has data in this
region.
Quoted 2 lines
Quoted 2 lines
I've
Quoted 1 line
attached the first 200kB of the LUKS partition so you can take a look
at
Quoted 5 lines
Quoted 5 lines
it
Quoted 4 lines
and see what's wrong.
Thanks again for helping!
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
--Kyle Bond
Quoted 4 lines · Arno Wagner
Quoted 3 lines · Kyle Bond
Thank you for the information; very interesting stuff.
I found that my keyslot0 was from
0xd0-0xff(this is according
to
Quoted 5 lines
Quoted 5 lines
pg. 6
Quoted 4 lines
Quoted 4 lines
of
Quoted 1 line
the pdf you linked me to);
Ah, that is the keyslot, not the key istelf. The key is about 128kB
in
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
size.
Quoted 2 lines
when I compared it to another LUKS disk of mine
the LUKS headers and the keyslots all looked very similar (didn't
see
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
0x55Quoted 1 line
0xAA, or any other partition/disk/sector information other than
the
Quoted 3 lines
Quoted 3 lines
UUID
Quoted 2 lines
Quoted 2 lines
in
Quoted 1 line
the header), so my guess is if the keyslot/header did get
overwritten
Quoted 4 lines
Quoted 4 lines
it
Quoted 1 line
Quoted 1 line
Quoted 1 line
must've been where the salt & iterations were in the keyslot, or
possibly
Quoted 1 line
Quoted 1 line
Quoted 1 line
the MK digests in the LUKS header (or something equally
undetectable
Quoted 20 lines
Quoted 20 lines
and
Quoted 19 lines
Quoted 19 lines
Quoted 3 lines
unrecoverable).
Any tips on where to go from here?
Look at the key. Start and end is in the keyslot and was
0x1000-0x20400in my test-LUKS partition (incidentially just a 10MB file of zeros mounted via loop device).If you have trouble, feel free to mail me the first 200kB or so of your LUKS partition.
Arno
Quoted 3 lines
--Kyle Bond
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
On Thu, Oct 1, 2009 at 2:52 PM, Arno Wagner <[email protected]>
Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines · Kyle Bond
Quoted 1 line
I haven't written anything to the 40GB; there were other logic
paritions
Quoted 1 line
Quoted 1 line
Quoted 1 line
within the extended partition, and I have repartitioned the
this
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
general
Quoted 1 line
Quoted 1 line
Quoted 1 line
area of the disk several times to get them to show up again.
What
Quoted 3 lines
Quoted 3 lines
is
Quoted 2 lines
Quoted 2 lines
this
Quoted 1 line
Quoted 1 line
Quoted 1 line
descriptor you are referring to? I was under the impression
that
Quoted 12 lines
Quoted 12 lines
all
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
partition-related information goes into the partition table at
the
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
beginning
Quoted 1 line
of the disk?
Unfortunately no. The way this is organized is that there are 4 parition slots in a partition table sector. The 4 primary partitions go into the secotr ath the beginning. However if you have an extended partition it works like this (details may be wrong, but this is the princuiple):
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
1. The slot at the beginning points to the extended partition sector, which is placed at the beginning of the extended partition.
2. The extended partition sector has the description onf the extended partition in its slot 0 and a pointer to the partition sector of the first logical partition
in slot 1. Slots 2/3 are unused.
3. A partition sector of a logical partition rersides at the beginning of that logical partition, has the description of that logical partition in slot 0 and a pointer to the
next
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
logical partition in slot 1. Slopts 2/3 are unused.
4. Repeat 3. for each logical partition. In the last one Slot 1 is unused (zero)So then that one-cylinder partition as created, It is possible
that
Quoted 11 lines
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
a new partition sector was put right behind its end to keep the
chain
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
of partition sectors intact.
Quoted 1 line
Also, would I be able to recognize (via hexdump of the LUKS
header)
Quoted 4 lines
Quoted 4 lines
if a
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
keyslot got overwritten?
Not the header, the kleyslot. And yes, you should be able to
recognize
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines
it as it has structured data.
The LUKS on disk format is documented here:
http://cryptsetup.googlecode.com/svn-history/r42/wiki/LUKS-standard/on-disk-format.pdf
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
The concrete parameters seem to deviate a bit, for example I
found
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
3850 anti-forensic stripes instead of 4000 as giben in section
5.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
With a short test (cryptsetup 1.0.7) I found that the first
keyslot
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
resides
Quoted 1 line
Quoted 1 line
at
0x1000-0x20400from the partition start (128'000 bytes
long)
Quoted 3 lines
Quoted 3 lines
It
Quoted 2 lines
Quoted 2 lines
seems
Quoted 1 line
Quoted 1 line
the next keyslot is from
0x21000-0x40400and that there is
1536
Quoted 3 lines
Quoted 3 lines
bytes
Quoted 2 lines
Quoted 2 lines
(3
Quoted 1 line
Quoted 1 line
sectors) of padding between keyslots that may contain zeros of
the
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
original
Quoted 9 lines
Quoted 9 lines
disk content. So if you find somethign structured in the space 0x1000-0x20400 from partition start, you have a broken keyslot.
The structure of a partition sector is described here:
http://en.wikipedia.org/wiki/Master_boot_record
The chaining is described here, hiwever I found it by analysing on-disk srtucture on my own. This chaining seems not to be
widely
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
known.:
http://www.boot-us.com/gloss02.htm
Especially the
0x550xAAsignature at the end of a partition
sector
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
is very distinct, but the other data may be too. The 446 boot
code
Quoted 29 lines
Quoted 29 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
bytes are typically zero except in the MBR (the first partition sector) AFAIK.
Good luck. Maybe it is just a minor problem. If there really is a partition sector in your keyslot, there is no chance of
recovering
Quoted 15 lines
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
that keyslot.
Arno
Quoted 3 lines
--Kyle
On Thu, Oct 1, 2009 at 7:51 AM, Arno Wagner <[email protected]>
Quoted 7 lines · wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Have you written anything to the 40GB? The LUKS header is small, but the keyslots are a few MB in size each. If there is a partition after sda5, its descriptor may have been put in the middle of your keyslot, effectively destroying it.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Arno
Quoted 1 line · Kyle Bond
Whilst repartitioning my drive trying to move & enlarge my
LUKS
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
partition, I
Quoted 1 line
fubar'd the partition table and tried to recreate it from
Quoted 8 lines
Quoted 8 lines
scratch
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
using
Quoted 1 line
Quoted 1 line
Quoted 1 line
testdisk. However, testdisk hasn't been able to properly
discover
Quoted 4 lines
Quoted 4 lines
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
partition; it found the LUKS header and created a logical
partition 1
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
cylinder in size; I can do a luksDump from it, and I can
see
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
crypt
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
settings,
Quoted 1 line
key slots etc., however the partition's too small to be
able
Quoted 8 lines
Quoted 8 lines
to
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
access
Quoted 2 lines
Quoted 2 lines
any
Quoted 1 line
data. So I enlarged the discovered logical partition
starting at
Quoted 3 lines
Quoted 3 lines
the
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
LUKS
Quoted 1 line
header (found using hexdump -C /dev/sda|grep "4c 55 4b 53
ba
Quoted 3 lines
Quoted 3 lines
be")
Quoted 2 lines
Quoted 2 lines
and
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
extending it back to its original 40GB, however when I try
to
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
Quoted 3 lines
enter
Quoted 2 lines
Quoted 2 lines
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
password for it cryptsetup won't accept it (I am doing
cryptsetup
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
luksOpen
Quoted 8 lines
/dev/sda5root). Help?--Kyle
_______________________________________________
dm-crypt mailing list
[email protected]
http://www.saout.de/mailman/listinfo/dm-crypt
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
--
Arno Wagner, Dr. sc. techn., Dipl. Inform., CISSP -- Email:
[email protected]
GnuPG: ID: 1E25338F FP: 0C30 5782 9D93 F785 E79C 0296
797F
Quoted 5 lines
Quoted 5 lines
6B50
Quoted 4 lines
Quoted 4 lines
1E25
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
338F
----
Cuddly UI's are the manifestation of wishful thinking. --
Dylan
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Evans
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
If it's in the news, don't worry about it. The very
definition
Quoted 9 lines
Quoted 9 lines
of
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"news" is "something that hardly ever happens." -- Bruce
Schneier
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
--
Arno Wagner, Dr. sc. techn., Dipl. Inform., CISSP -- Email:
[email protected]
GnuPG: ID: 1E25338F FP: 0C30 5782 9D93 F785 E79C 0296 797F
6B50
Quoted 7 lines
Quoted 7 lines
1E25
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
338F
----
Cuddly UI's are the manifestation of wishful thinking. -- DylanEvans
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
If it's in the news, don't worry about it. The very definition
of
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"news" is "something that hardly ever happens." -- Bruce
Schneier
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
--
Arno Wagner, Dr. sc. techn., Dipl. Inform., CISSP -- Email:
[email protected]
GnuPG: ID: 1E25338F FP: 0C30 5782 9D93 F785 E79C 0296 797F 6B50
1E25
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
338F
----
Cuddly UI's are the manifestation of wishful thinking. -- Dylan
Evans
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
If it's in the news, don't worry about it. The very definition of "news" is "something that hardly ever happens." -- Bruce Schneier
--
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
Quoted 3 lines
Quoted 3 lines
If it's in the news, don't worry about it. The very definition of "news" is "something that hardly ever happens." -- Bruce Schneier
--
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