升級失敗後如何使用密碼恢復ecryptfs加密資料?

升級失敗後如何使用密碼恢復ecryptfs加密資料?

我最近冒險接受了從 14.04 到 16.04 的升級。我在安裝軟體包時離開了計算機,當我回到計算機時,我看到黑屏,只有一個遊標在閃爍。

重置後我得出的結論是無聊的超出了修復的價值。

如何恢復加密資料?

答案1

我是如何修復它的:

我啟動了 ubuntu 安裝程式並擦除了我的根分割區。新安裝的感覺比舊的健康得多,所以無論如何可能是必要的。

第一次登入時,我收到一條提醒,將我的 ecryptfs 密鑰保存在安全的地方 -我不記得在之前的安裝中這樣做過

當我組裝我的主資料夾數組時,我發現了我認為是我的加密資料的內容:

root@computer:~/mnt/user# ls -la
total 8
dr-x------ 2 user user 4096 jul  2  2011 .
drwxr-xr-x 8 root    root    4096 feb 18  2015 ..
lrwxrwxrwx 1 user user   56 jul  2  2011 Access-Your-Private-Data.desktop -> /usr/share/ecryptfs-utils/ecryptfs-mount-private.desktop
lrwxrwxrwx 1 user user   33 jul  2  2011 .ecryptfs -> /home/.ecryptfs/user/.ecryptfs
lrwxrwxrwx 1 user user   32 jul  2  2011 .Private -> /home/.ecryptfs/user/.Private
lrwxrwxrwx 1 user user   52 jul  2  2011 README.txt -> /usr/share/ecryptfs-utils/ecryptfs-mount-private.txt

但我無法解鎖它。

root@computer:~# ecryptfs-unwrap-passphrase /root/mnt/user/.ecryptfs/wrapped
Passphrase:
ffffffffffffffffffffffffffffffff
root@computer:~# ecryptfs-recover-private /root/mnt/user
INFO: Found [/root/mnt/user].
Try to recover this directory? [Y/n]:
INFO: Could not find your wrapped passphrase file.
INFO: To recover this directory, you MUST have your original MOUNT passphras
INFO: When you first setup your encrypted private directory, you were told t
INFO: your MOUNT passphrase.
INFO: It should be 32 characters long, consisting of [0-9] and [a-f].

Enter your MOUNT passphrase:
INFO: Success!  Private data mounted at [/tmp/ecryptfs.lls9FwPj].
root@computer:~# ls -la /tmp/ecryptfs.lls9FwPj
total 8
dr-x------  2 user user 4096 Jul  2  2011 .
drwxrwxrwt 11 root    root    4096 Sep 11 11:08 ..
lrwxrwxrwx  1 user user   32 Jul  2  2011 .Private -> /home/.ecryptfs/user/.
lrwxrwxrwx  1 user user   33 Jul  2  2011 .ecryptfs -> /home/.ecryptfs/user/
lrwxrwxrwx  1 user user   56 Jul  2  2011 Access-Your-Private-Data.desktop -
lrwxrwxrwx  1 user user   52 Jul  2  2011 README.txt -> /usr/share/ecryptfs-

沒有錯誤,但裝載點僅包含與來源資料夾相同的未加密資料。

使用ecryptfs-unwrap-passphrase /root/mnt/user/.ecryptfs/wrapped-passphrase我確實得到了A密鑰,但不幸的是,如果我不提供文件作為參數,它與我得到的密鑰是一樣的,所以我想我只得到了當前的密鑰,而不是舊數據的密鑰。

似乎新舊wrapped-passphrase文件都相同:

root@computer:~# mount | grep md0
/dev/md0 on /root/mnt type ext4 (rw,relatime,data=ordered)
root@computer:~# md5sum /home/user/.ecryptfs/wrapped-passphrase /root/mnt/user/.ecryptfs/wrapped-passphrase  
52da6f1ea1ffff114795c7613b5c560e  /home/user/.ecryptfs/wrapped-passphrase
52da6f1ea1ffff114795c7613b5c560e  /root/mnt/user/.ecryptfs/wrapped-passphrase

我發現這很奇怪,因為md0在安裝過程中甚至沒有組裝。

然而,我正確閱讀後解決了這個秘密:

root@computer:~# ls -l /root/mnt/user/.Private
lrwxrwxrwx 1 user user 32 Jul  2  2011 /root/mnt/user/.Private -> /home/.ecryptfs/user/.Private

似乎我一直在對新主資料夾的符號連結而不​​是舊資料進行操作。

讀取正確的檔案給了另一個(正確的)密鑰!

root@computer:~/mnt/.ecryptfs/user# ecryptfs-unwrap-passphrase /root/mnt/.ecryptfs/user/.ecryptfs/wrapped-passphrase 
Passphrase:
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

這確實是我最初問題的答案:該wrapped-passphrase文件是使用我的登入密碼加密的,因此只要我擁有該文件並知道我的密碼,我就應該能夠存取我的資料。

不幸的是,使用更明智的路徑/按鍵組合並沒有產生太大的區別:

root@computer:~/mnt/.ecryptfs/user# ls -al
total 52
drwxr-xr-x   4 user user  4096 Jul  2  2011 .
drwxr-xr-x   3 root    root     4096 Jul  2  2011 ..
drwxr-xr-x 121 user user 36864 Sep  8 14:58 .Private
drwx------   2 user user  4096 Mar 15  2015 .ecryptfs
root@computer:~/mnt/.ecryptfs/user# ecryptfs-recover-private /root/mnt/.ecryptfs/user
INFO: Found [/root/mnt/.ecryptfs/user].
Try to recover this directory? [Y/n]:
INFO: Could not find your wrapped passphrase file.
INFO: To recover this directory, you MUST have your original MOUNT passphrase.
INFO: When you first setup your encrypted private directory, you were told to record
INFO: your MOUNT passphrase.
INFO: It should be 32 characters long, consisting of [0-9] and [a-f].

Enter your MOUNT passphrase:
INFO: Success!  Private data mounted at [/tmp/ecryptfs.dKQkSvjC].
root@computer:~/mnt/.ecryptfs/user# ls -al /tmp/ecryptfs.dKQkSvjC
total 52
drwxr-xr-x   4 user user  4096 Jul  2  2011 . 
drwxrwxrwt  12 root    root     4096 Sep 11 12:32 ..
drwxr-xr-x 121 user user 36864 Sep  8 14:58 .Private
drwx------   2 user user  4096 Mar 15  2015 .ecryptfs

由於一些 ecryptfs 工具具有硬編碼路徑,我什至嘗試過:

root@computer:~# mount /dev/md0 /home
root@computer:~# su - user
Signature not found in user keyring
Perhaps try the interactive 'ecryptfs-mount-private'
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

user@computer:~$ ecryptfs-mount-private
Enter your login passphrase:
Inserted auth tok with sig [e403598bcfe01170] into the user session keyring
mount: No such file or directory

但那裡也沒有雪茄。

做同樣的事情沒有然而安裝md0/home不起作用。

user@computer:~$ dash -e -x `which ecryptfs-mount-private`
+ PRIVATE_DIR=Private
+ WRAPPING_PASS=LOGIN
+ PW_ATTEMPTS=3
+ TEXTDOMAIN=ecryptfs-utils
+ gettext Enter your login passphrase:
+ MESSAGE=Enter your login passphrase:
+ [ -f /home/user/.ecryptfs/wrapping-independent ]
+ WRAPPED_PASSPHRASE_FILE=/home/user/.ecryptfs/wrapped-passphrase
+ MOUNT_PASSPHRASE_SIG_FILE=/home/user/.ecryptfs/Private.sig
+ /sbin/mount.ecryptfs_private
+ [ -f /home/user/.ecryptfs/wrapped-passphrase -a -f /home/user/.ecryptfs/Private.sig ] 
+ tries=0
+ stty -g
+ stty_orig=2d00:5:bd:ca1b:3:1c:7f:1f:4:0:1:0:11:13:1a:ff:12:f:17:16:ff:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
+ [ 0 -lt 3 ]
+ echo -n Enter your login passphrase:
Enter your login passphrase:+ stty -echo
+ head -n1
+ LOGINPASS=MyLoginPassword
+ stty 2d00:5:bd:ca1b:3:1c:7f:1f:4:0:1:0:11:13:1a:ff:12:f:17:16:ff:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0
+ echo

+ wc -l
+ [ 2 = 1 ]
+ printf %s\0 MyLoginPassword
+ ecryptfs-insert-wrapped-passphrase-into-keyring /home/user/.ecryptfs/wrapped-passphrase -
Inserted auth tok with sig [93196f7a8af1fdfe] into the user session keyring
+ break
+ [ 0 -ge 3 ]
+ /sbin/mount.ecryptfs_private
mount: No such file or directory
user@computer:~$ ls -l /sbin/mount.ecryptfs*
-rwxr-xr-x 1 root root 25944 jul 13 19:13 /sbin/mount.ecryptfs
-rwsr-xr-x 1 root root 19024 jul 13 19:13 /sbin/mount.ecryptfs_private

因此,在正常登入期間可能會發生一些神奇的事情(透過 PAM?),而我的範例中缺少這些。

啟動 live-cd 我能夠存取資料!

root@ubuntu:~# apt install mdadm
Reading package lists... Done
[...]
root@ubuntu:~# mdadm --assemble /dev/md0 /dev/sd[bc]1
mdadm: /dev/md0 has been started with 2 drives.
root@ubuntu:~# mount /dev/md0 /home
root@ubuntu:/home# ecryptfs-recover-private /home/.ecryptfs/user/.PrivateINFO: Found [/home/.ecryptfs/user/.Private].
Try to recover this directory? [Y/n]:
INFO: Found your wrapped-passphrase
Do you know your LOGIN passphrase? [Y/n] Y
INFO: Enter your LOGIN passphrase...
Passphrase:
Inserted auth tok with sig [f403498bcfd01070] into the user session keyring
INFO: Success!  Private data mounted at [/tmp/ecryptfs.uHQ0z177].
root@ubuntu:/home# ls /tmp/ecryptfs.uHQ0z177/ | grep Doc
Documents

但即便如此,這些工具的工作也不夠完美:

root@ubuntu:/home# ecryptfs-recover-private
INFO: Searching for encrypted private directories (this might take a while)...  
find: ‘/run/user/999/gvfs’: Permission denied
find: File system loop detected; ‘/sys/kernel/debug/pinctrl’ is part of the same file system loop as ‘/sys/kernel/debug’.

所以我開始認為我遇到的大多數問題只是 ecryptfs 在可用性方面可能會得到很大的改善。

重新啟動到我的真實安裝,我現在可以存取資料:

root@computer:~# mount /dev/md0 mnt
root@computer:~/mnt/.ecryptfs/user/.Private# cd /root/mnt/.ecryptfs/user/.Private/
root@computer:~/mnt/.ecryptfs/user/.Private# ecryptfs-recover-private .
INFO: Found [.].
Try to recover this directory? [Y/n]:
INFO: Found your wrapped-passphrase
Do you know your LOGIN passphrase? [Y/n]
INFO: Enter your LOGIN passphrase...
Passphrase:
Inserted auth tok with sig [f4f3498bcfd01070] into the user session keyring
INFO: Success!  Private data mounted at [/tmp/ecryptfs.ZMqBVhRu].
root@computer:~/mnt/.ecryptfs/user/.Private# ls /tmp/ecryptfs.ZMqBVhRu | grep Doc
Documents

編輯 :

似乎「搜尋」工具ecryptfs-recover-private不太擅長定位.Private資料夾。給出正確的絕對路徑可以正常工作。

ecryptfs-recover-private僅在未提供任何參數時進行搜尋。如果提供了路徑,則它必須指向該.Private資料夾。

在這個例子中:

ecryptfs-recover-private /root/mnt/.ecryptfs/user/.Private

並且,是的,wrapped-passphrase使用您的登入密碼進行混淆,如果您知道密碼並擁有該文件,則不需要實際的 KEY 列印輸出。

很抱歉這篇文章很長,但希望我的「日記」可以為其他人節省幾個小時。

相關內容