如何提取 LUKS 设备的哈希值?

stu*_*ent 1 dm-crypt luks

对于 LUKS 设备,我知道哈希以某种方式存储在分区标头中(我真的不知道这意味着什么)。但我不知道在这种情况下如何打印哈希值。

例如,在标准的 unix 系统中,用户密码哈希存储在/etc/shadow. 如果我想查看密码的哈希值,我可以打开这个文件并查看它。

那么,如何提取 LUKS 设备的哈希值?

fro*_*utz 5

如果是关于 LUKS 标头的通用信息,请尝试luksDump.

# cryptsetup luksDump /dev/loop0
LUKS header information for /dev/loop0

Version:        1
Cipher name:    aes
Cipher mode:    xts-plain64
Hash spec:      sha1
Payload offset: 4096
MK bits:        256
MK digest:      67 77 17 e9 43 cf b2 e1 f3 a0 e2 0b 7a a9 fa a1 cf d8 e0 76 
MK salt:        f1 6a 09 51 55 e8 af d2 11 b2 73 1c cc ae b5 15 
                9e e9 dc 84 a5 22 aa b1 b3 0c 7c db 23 59 9a 14 
MK iterations:  77625
UUID:           ec59d9ad-39f1-4d5c-af9e-b35f34847561

Key Slot 0: ENABLED
    Iterations:             311434
    Salt:                   ed 69 d7 9d 7a 39 1a 23 3f 38 64 15 3f 38 dd 5f 
                            90 1e ea 9f 5b 9f c3 59 f3 18 49 2f 9a 3f 4e c6 
    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
Run Code Online (Sandbox Code Playgroud)

如果您正在寻找实际的密钥,当您 luksOpen 时,dmsetup将显示它。

# dmsetup table --showkeys
luksthing: 0 209711104 crypt aes-xts-plain64 c2349e71e00186c784a1d83917778fcaacb87382ea508aa41f6324f1e2f056eb 0 7:0 4096
Run Code Online (Sandbox Code Playgroud)

这与其说是哈希值,不如说是打开设备的实际密钥。如果您有这个,则不再需要 LUKS 密码:

# cryptsetup luksClose luksthing
# echo 0 209711104 crypt aes-xts-plain64 c2349e71e00186c784a1d83917778fcaacb87382ea508aa41f6324f1e2f056eb 0 7:0 4096 \
| dmsetup create luksthing
# file -s -L /dev/mapper/luksthing
/dev/mapper/luksthing: Linux rev 1.0 ext2 filesystem data, UUID=34fadafe-31cf-467d-84c0-c2d50bbcfcde (large files)
Run Code Online (Sandbox Code Playgroud)

这就是为什么如果您的系统受到损害,您必须重新安装/重新加密。无论您的 LUKS 密码是什么,他们都有您的加密密钥。