アップグレードが失敗した後、パスワードを使用して ecryptfs で暗号化されたデータを回復するにはどうすればよいですか?

アップグレードが失敗した後、パスワードを使用して ecryptfs で暗号化されたデータを回復するにはどうすればよいですか?

最近、思い切って 14.04 から 16.04 へのアップグレードを受け入れました。パッケージのインストール中にコンピューターを離れましたが、コンピューターに戻ると、カーソルが 1 つだけ点滅している黒い画面が表示されました。

リセットすると、私はそれが壊れた修正する価値がない。

暗号化されたデータを復元するにはどうすればいいですか?

答え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私は得た1つのキーを取得しましたが、残念ながら、ファイルを引数として指定しなかった場合に取得したキーと同じものだったので、古いデータのキーではなく、現在のキーのみが取得されたようです。

古いファイルと新しい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 経由?) が、私の例ではそれが起こりません。

ライブ 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 プリントアウトは必要ありません。

長い投稿で申し訳ありませんが、ここでの私の「日記」が他の誰かの数時間を節約できれば幸いです。

関連情報