[File] [PATCH] of Magdir/luks,linux for LUKS encrypted file; duplicates + version 2 wrong
Jörg Jenderek
joerg.jen.der.ek at gmx.net
Mon Sep 5 19:15:35 UTC 2022
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
some days ago i installed a new Linux system on my PC.
For security reasons i tried variants with encrypted partitions.
When running file command (version 5.42) on such encrypted partitions
and related images (taken from cryptsetup sources) with -k option i
get an output like:
compatimage.img: LUKS encrypted file, ver 1
[aes, cbc-essiv:sha256, sha256] UUID:
28632274-8c8a-493f-835b-da802e1c576b
LUKS encrypted file, ver 1
[aes, cbc-essiv:sha256, sha256] UUID:
28632274-8c8a-493f-835b-da802e1c576b
compatimage2.img: LUKS encrypted file, ver 2
[, , sha256] UUID:
28632274-8c8a-493f-835b-da802e1c576b
LUKS encrypted file, ver 2
[, , sha256] UUID:
28632274-8c8a-493f-835b-da802e1c576b
compatv10image.img: LUKS encrypted file, ver 1
[aes, cbc-plain, sha1] UUID:
e0d6124b-f9b7-4592-8c27-5adaddb7f1a4
LUKS encrypted file, ver 1
[aes, cbc-plain, sha1] UUID:
e0d6124b-f9b7-4592-8c27-5adaddb7f1a4
luks2_keyslot_unassigned.img: LUKS encrypted file, ver 2
[, , sha256] UUID:
7c8493c0-4f6e-40ab-848e-f96b3b995a66
LUKS encrypted file, ver 2
[, , sha256] UUID:
7c8493c0-4f6e-40ab-848e-f96b3b995a66
luks2_valid_hdr.img: LUKS encrypted file, ver 2
[, , sha256] UUID:
12a3a118-7039-4575-a649-3f559d8d87ee
LUKS encrypted file, ver 2
[, , sha256] UUID:
12a3a118-7039-4575-a649-3f559d8d87ee
sda3-kingston240.luks: LUKS encrypted file, ver 1
[aes, xts-plain64, sha256] UUID:
95abe2fe-953f-487e-9aa4-882993350a36
LUKS encrypted file, ver 1
[aes, xts-plain64, sha256] UUID:
95abe2fe-953f-487e-9aa4-882993350a36
sda3.luksVolumeHeaderBackUp: LUKS encrypted file, ver 2
[, PI4, sha256] UUID:
242256c6-396e-4a35-af5f-5b70cb7af9a7
LUKS encrypted file, ver 2
[, PI4, sha256] UUID:
242256c6-396e-4a35-af5f-5b70cb7af9a7
With --extension option only ??? is displayed. Furthermore with -i
option for my samples only generic application/octet-stream is shown.
For comparison reason i run the file format identification utility
TrID ( See https://mark0.net/soft-trid-e.html). The version 2
variants ( like compatimage2.img luks2_keyslot_unassigned.img
luks2_valid_hdr.img) are described as "LUKS2 encrypted" by
luks2.trid.xml. All examples are described with lower rate as
"LUKS encrypted" by luks.trid.xml (See appended trid-v-luks.txt.gz).
With -v option display reference URL.
I get duplicated messages because Magdir/linux and Magdir/luks
contain the same magic lines starting with line like:
0 string LUKS\xba\xbe LUKS encrypted file,
So first i delete inside Magdir/linux the corresponding lines to
remove duplicates message texts.
The mentioned URL with web page luks.endorphin.org inside Magdir/luks
does not exist any more. So with the help of TrID i replace it by
comment lines like:
# URL: https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup
# http://fileformats.archiveteam.org/wiki/LUKS
# Reference: https://mirrors.edge.kernel.org/pub/linux/utils/
# cryptsetup/LUKS_docs/on-disk-format.pdf
# https://gitlab.com/cryptsetup/LUKS2-docs/-/raw/master
# luks2_doc_wip.pdf
# http://mark0.net/download/triddefs_xml.7z
# defs/l/luks.trid.xml
# defs/l/luks2.trid.xml
The information for version one ( shown by phrase ", ver 1") are
correct, whereas for version two ( shown by phrase ", ver 2") the
additional informations are garbage. This can be verified by
running a command like:
cryptsetup luksDump /dev/sda3
Now inside Magdir/luks the description start with lines like:
0 string LUKS\xba\xbe LUKS encrypted file,
!:mime application/x-raw-disk-image
!:ext /luks/img/luksVolumeHeaderBackUp
>6 beshort x ver %d
I myself would prefer a user defined mime type like
application/x-luks-volume but according to FreeDesktop.org shared
MIME database for LUKS encrypted there exist already one. That
information can be found for example on web site reposcope.com. The
file name extension is there listed but not exactly explained. The
obviously "natural" file name suffix is luks for such encrypted
files. These files are often handled by image writer or mounters like
gnome-disk. Such utility can also handle other disk images. So
apparently these use as generic suffix for disc image 3 byte suffix
img. When handling partitions like /dev/sda3 then of course we have
no file name extension. The header of such encrypted files can be
saved for backup reasons separately. These headers of course look at
first glance like the whole file or partition. This work for example
can be done by tool like zuluCrypt. This use an own file name suffix
for that reason. That is luksVolumeHeaderBackUp.
The next lines showing cipher-name (like: aes twofish),
cipher-mode (like: xts-plain64 cbc-essiv), hash type ( like: sha256
sha1 ripemd160) and UID are only correct for version 1:
>8 string x [%s,
>40 string x %s,
>72 string x %s]
>168 string x UUID: %s
So i put these lines in sub routine luks-v1 and test for version 1 or
2 and call correct sub routine. This is be done by inserted lines lik
e:
>6 beshort 1
>>0 use luks-v1
>6 beshort >1
>>0 use luks-v2
0 name luks-v1
According to cryptsetup output and the mentioned PDF documents i
show in that sub routine more information ( like payload-offset, MK
key-bytes, mk-digest, salt parameter and iterations parameter) by
additional lines like:
>104 ubelong x \b, at %#x data
>108 ubelong x \b, %u key bytes
>112 ubequad x \b, MK digest %#16.16llx
>>120 ubequad x \b%16.16llx
>>128 ubelong x \b%8.8x
>132 ubequad x \b, MK salt %#16.16llx
>>140 ubequad x \b%16.16llx
>>148 ubequad x \b%16.16llx
>>156 ubequad x \b%16.16llx
>164 ubelong x \b, %u MK iterations
You can use up to 8 different keys to decrypt such LUKS files. This
information is stored in a key slot. So i display information (like
in-active status, material offset, number of anti-forensic stripes)
about LUKS slot by sub routine with lines like:
0 name luks-slot
> 0 ubelong =0x00AC71F3 activ 0 ubelong =0x0000DEAD inactiv
# iteration parameter for PBKDF2
#>4 ubelong x \b, %u iterations
# salt parameter for PBKDF2
#>8 ubequad x \b, salt %#16.16llx
#>16 ubequad x \b%16.16llx
#>24 ubequad x \b%16.16llx
#>32 ubequad x \b%16.16llx
> 40 ubelong x \b, %#x material offset 44 ubelong !4000 \b, %u
> stripes
So show inside sub routine information about active key slots
(maximal eight) by lines like:
>208 ubelong =0x00AC71F3 \b; slot #1
>>208 use luks-slot
>256 ubelong =0x00AC71F3 \b; slot #2
>>256 use luks-slot
...
>544 ubelong =0x00AC71F3 \b; slot #8
>>544 use luks-slot
For LUKS version 2 the header format is quite different from version
one. Part of the information is stored in text form as JSON at offset
0x1000. This informations (like label, sub label,UIID, JSON text) is
displayed by second sub routine, which looks like:
0 name luks-v2
>8 ubequad x \b, header size %llu
>16 ubequad x \b, ID %llu
>24 string >\0 \b, label %s
>72 string x \b, algo %s
>104 ubequad x \b, salt %#llx...
>168 string x \b, UUID: %-.40s
>208 string >\0 \b, sub label %-.48s
>256 ubequad !0 \b, offset %llx
>448 ubequad x \b, crc %#llx...
>0x1000 string x \b, at 0x1000 %s
After applying the above mentioned modifications by patches
file-5.42-linux-luks.diff and file-5.42-luks-img.diff
then duplicated messages vanish and version 2 variants are now
described correctly like:
compatimage.img: LUKS encrypted file, ver 1
[aes, cbc-essiv:sha256, sha256] UUID:
28632274-8c8a-493f-835b-da802e1c576b
, at 0x408 data, 16 key bytes
, MK digest
0x81344f00b1b5bc7f296
3401e92ef373d869b1a8f
, MK salt
0xf71b26130622d934f79823771f354b6
04b5d1d6e089fd01cc4a9f5584e9f526f
, 1000 MK iterations
; slot #0 active, 0x8 material offset
compatimage2.img: LUKS encrypted file, ver 2
, header size 16384, ID 4, algo sha256
, salt 0x62fea1336a455f46..., UUID:
28632274-8c8a-493f-835b-da802e1c576b,
crc 0x66390aa542676a25..., at 0x1000
{"keyslots":{"0":{"type":"luks2"
compatv10image.img: LUKS encrypted file, ver 1
[aes, cbc-plain, sha1] UUID:
e0d6124b-f9b7-4592-8c27-5adaddb7f1a4
, at 0x3f2 data, 16 key bytes
, MK digest
0x5b4fd481c1dc0f3c275c
116e48bd2b6f6b55fff9
, MK salt
0x32f93e8c57963010afebc8bd3eaa1d9
9fc34db83a46193d8bb98fa9fc5ce9600
, 10 MK iterations
; slot #0 active, 0x2 material offset
luks2_keyslot_unassigned.img: LUKS encrypted file, ver 2
, header size 16384, ID 8, algo sha256
, salt 0xc838d9771c1bde34..., UUID:
7c8493c0-4f6e-40ab-848e-f96b3b995a66,
crc 0x8ba6e895289cb92c..., at 0x1000
{"keyslots":{"0":{"type":"luks2",
luks2_valid_hdr.img: LUKS encrypted file, ver 2
, header size 16384, ID 10, algo sha256
, salt 0x3904096481765b4..., UUID:
12a3a118-7039-4575-a649-3f559d8d87ee,
crc 0xc474c736ae9ef3fa..., at 0x1000
{"keyslots":{"0":{"type":"luks2",
sda3-kingston240.luks: LUKS encrypted file, ver 1
[aes, xts-plain64, sha256] UUID:
95abe2fe-953f-487e-9aa4-882993350a36
, at 0x1000 data, 64 key bytes
, MK digest
0xafa27b048a3d51528f5f
91aa23a4e8f006ba64a5
, MK salt
0x3d2e514c4dc98c64bb5b05d37807ca4b
be907e6a9d236043214f7f7b8f90ddfc
, 35656 MK iterations
; slot #0 active, 0x8 material offset
sda3.luksVolumeHeaderBackUp: LUKS encrypted file, ver 2
, header size 16384, ID 9
, label LUKS2_EXT4_ROOT_PI4
, algo sha256
, salt 0x14a40dac2737a873..., UUID:
242256c6-396e-4a35-af5f-5b70cb7af9a7
, sub label MY_SUBSYSTEM,
crc 0x44af19d85fa620ac..., at 0x1000
{"keyslots":{"0":{"type":"luks2",
I hope my diff files can be applied in future version of file utility
.
With best wishes
Jörg Jenderek
- --
Jörg Jenderek
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
iF0EARECAB0WIQS5/qNWKD4ASGOJGL+v8rHJQhrU1gUCYxZK1wAKCRCv8rHJQhrU
1oN+AKCdueT/0zDQvcmBGemKAXtnheQ9tgCeIe/S6szqOK6XdTc+1BgVHlwYUCw=
=Y/3N
-----END PGP SIGNATURE-----
-------------- next part --------------
--- file-5.42/magic/Magdir/linux.old 2022-04-11 15:07:12.000000000 +0200
+++ file-5.42/magic/Magdir/linux 2022-09-01 21:56:25.456658400 +0200
@@ -364,16 +364,6 @@
>24 lelong x %d symbols
>28 lelong x %d ocons
-# LUKS: Linux Unified Key Setup, On-Disk Format, http://luks.endorphin.org/spec
-# Anthon van der Neut (anthon at mnt.org)
-0 string LUKS\xba\xbe LUKS encrypted file,
->6 beshort x ver %d
->8 string x [%s,
->40 string x %s,
->72 string x %s]
->168 string x UUID: %s
-
-
# Summary: Xen saved domain file
# Created by: Radek Vokal <rvokal at redhat.com>
0 string LinuxGuestRecord Xen saved domain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file-5.42-linux-luks.diff.sig
Type: application/octet-stream
Size: 552 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20220905/621fabe4/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trid-v-luks.txt.gz
Type: application/x-gzip
Size: 503 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20220905/621fabe4/attachment-0001.bin>
-------------- next part --------------
--- file-5.42/magic/Magdir/luks.old 2019-02-22 13:06:34.000000000 +0100
+++ file-5.42/magic/Magdir/luks 2022-09-05 20:58:45.577394900 +0200
@@ -4,10 +4,123 @@
# luks: file(1) magic for Linux Unified Key Setup
-# URL: http://luks.endorphin.org/spec
+# URL: https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup
+# http://fileformats.archiveteam.org/wiki/LUKS
# From: Anthon van der Neut <anthon at mnt.org>
+# Update: Joerg Jenderek
+# Note: verfied by command like `cryptsetup luksDump /dev/sda3`
0 string LUKS\xba\xbe LUKS encrypted file,
+# https://reposcope.com/mimetype/application/x-raw-disk-image
+!:mime application/x-raw-disk-image
+#!:mime application/x-luks-volume
+# img is the generic extension; no suffix for partitions; luksVolumeHeaderBackUp via zuluCrypt
+!:ext /luks/img/luksVolumeHeaderBackUp
+# version like: 1 2
>6 beshort x ver %d
+# test for version 1 variant
+>6 beshort 1
+>>0 use luks-v1
+# test for version 2 variant
+>6 beshort >1
+>>0 use luks-v2
+# Reference: https://mirrors.edge.kernel.org/pub/linux/utils/cryptsetup/LUKS_docs/on-disk-format.pdf
+# http://mark0.net/download/triddefs_xml.7z/defs/l/luks.trid.xml
+# display information about LUKS version 1
+0 name luks-v1
+# cipher-name like: aes twofish
>8 string x [%s,
+# cipher-mode like: xts-plain64 cbc-essiv
>40 string x %s,
+# hash specification like: sha256 sha1 ripemd160
>72 string x %s]
>168 string x UUID: %s
+# NEW PART!
+# payload-offset; start offset of the bulk data
+>104 ubelong x \b, at %#x data
+# key-bytes; number of key bytes; key-bytes*8=MK-bits
+>108 ubelong x \b, %u key bytes
+# mk-digest[20]; master key checksum from PBKDF2
+>112 ubequad x \b, MK digest %#16.16llx
+>>120 ubequad x \b%16.16llx
+>>128 ubelong x \b%8.8x
+# mk-digest-salt[32]; salt parameter for master key PBKDF2
+>132 ubequad x \b, MK salt %#16.16llx
+>>140 ubequad x \b%16.16llx
+>>148 ubequad x \b%16.16llx
+>>156 ubequad x \b%16.16llx
+# mk-digest-iter; iterations parameter for master key PBKDF2
+>164 ubelong x \b, %u MK iterations
+# key slot 1
+>208 ubelong =0x00AC71F3 \b; slot #0
+>>208 use luks-slot
+# key slot 2
+>256 ubelong =0x00AC71F3 \b; slot #1
+>>256 use luks-slot
+# key slot 3
+>304 ubelong =0x00AC71F3 \b; slot #2
+>>304 use luks-slot
+# key slot 4
+>352 ubelong =0x00AC71F3 \b; slot #3
+>>352 use luks-slot
+# key slot 5
+>400 ubelong =0x00AC71F3 \b; slot #4
+>>400 use luks-slot
+# key slot 6
+>448 ubelong =0x00AC71F3 \b; slot #5
+>>448 use luks-slot
+# key slot 7
+>496 ubelong =0x00AC71F3 \b; slot #6
+>>496 use luks-slot
+# key slot 8
+>544 ubelong =0x00AC71F3 \b; slot #7
+>>544 use luks-slot
+# Reference: https://gitlab.com/cryptsetup/LUKS2-docs/-/raw/master/luks2_doc_wip.pdf
+# http://mark0.net/download/triddefs_xml.7z/defs/l/luks2.trid.xml
+# display information about LUKS version 2
+0 name luks-v2
+# hdr_size; size including JSON area called Metadata area by cryptsetup with value like: 16384
+>8 ubequad x \b, header size %llu
+# possible check for MAGIC_2ND after header
+#>(8.Q) string SKUL\xba\xbe \b, 2nd_HEADER_OK
+# seqid; sequence ID, increased on update; called Epoch by cryptsetup with value like: 3 4 8 10
+>16 ubequad x \b, ID %llu
+# label[48]; optional ASCII label or empty; called Label by cryptsetup with value like: "LUKS2_EXT4_ROOT"
+>24 string >\0 \b, label %s
+# csum_alg[32]; checksum algorithm like: sha256 sha1 sha512 wirlpool ripemd160
+>72 string x \b, algo %s
+# salt[64]; salt , unique for every header
+>104 ubequad x \b, salt %#llx...
+# uuid[40]; UID of device as string like: 242256c6-396e-4a35-af5f-5b70cb7af9a7
+>168 string x \b, UUID: %-.40s
+# subsystem[48]; optional owner subsystem label or empty
+>208 string >\0 \b, sub label %-.48s
+# hdr_offset; offset from device start [ bytes ] like: 0
+>256 ubequad !0 \b, offset %llx
+# char _padding [184]; must be zeroed
+#>264 ubequad x \b, padding %#16.16llx
+#>440 ubequad x \b...%16.16llx
+# csum[64]; header checksum
+>448 ubequad x \b, crc %#llx...
+# char _padding4096 [7*512]; Padding , must be zeroed
+#>512 ubequad x \b, more padding %#16.16llx
+#>4088 ubequad x \b...%16.16llx
+# JSON text data terminated by the zero character; unused remainder empty and filled with zeroes like:
+# {"keyslots":{"0":{"type":"luks2","key_size":64,"af":{"type":"luks1","stripes":4000,"hash":"sha256"},"area":{"type":"raw","offse"
+>0x1000 string x \b, at 0x1000 %s
+#>0x1000 indirect x
+# display information (like active) about LUKS1 slot
+0 name luks-slot
+# state of keyslot; 0x00AC71F3~active 0x0000DEAD~inactive
+#>0 ubelong x \b, status %#8.8x
+>0 ubelong =0x00AC71F3 active
+>0 ubelong =0x0000DEAD inactive
+# iteration parameter for PBKDF2
+#>4 ubelong x \b, %u iterations
+# salt parameter for PBKDF2
+#>8 ubequad x \b, salt %#16.16llx
+#>>16 ubequad x \b%16.16llx
+#>>24 ubequad x \b%16.16llx
+#>>32 ubequad x \b%16.16llx
+# start sector of key material like: 8 0x200 0x3f8 0x5f0 0xdd0
+>40 ubelong x \b, %#x material offset
+# number of anti-forensic stripes like: 4000
+>44 ubelong !4000 \b, %u stripes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file-5.42-luks-img.diff.sig
Type: application/octet-stream
Size: 2281 bytes
Desc: not available
URL: <https://mailman.astron.com/pipermail/file/attachments/20220905/621fabe4/attachment-0003.obj>
More information about the File
mailing list