「ディスクの完全消去/ヒントとテクニック」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(文字列「http://security.stackexchange.com/」を「https://security.stackexchange.com/」に置換)
(→‎空き領域の消去: 情報を更新)
 
(同じ利用者による、間の6版が非表示)
10行目: 10行目:
 
== 単体ファイルの消去 ==
 
== 単体ファイルの消去 ==
   
{{Warning|パーティションが[[wikipedia:File_system_fragmentation|断片化]]している場合や、パーティションをリサイズあるいは移動したことがある場合、もしくは同一デバイス上にファイルが[[wikipedia:Temporary folder|重複]]している場合、単体ファイルの消去は効率的ではありません。[[セキュリティ#ディスク暗号化|データ暗号化]]コンテナを消去した場合、リカバリするのが難しくなりますが暗号化の[[wikipedia:Disk encryption#Implementations|ディスクパフォーマンス]]は低くなります。[[wikipedia:Disk encryption hardware|ハードウェアによる暗号化]]の場合は性能には影響ありません。[[ディスクの完全消去#データの残留]]を参照してください。}}
+
{{Warning|パーティションが [[wikipedia:File_system_fragmentation|断片化]] している場合や、パーティションをリサイズあるいは移動したことがある場合、もしくは同一デバイス上にファイルが [[wikipedia:Temporary folder|重複]] している場合、単体ファイルの消去は効率的ではありません。[[セキュリティ#ディスク暗号化|データ暗号化]] コンテナを消去した場合、リカバリするのが難しくなりますが暗号化の [[wikipedia:Disk encryption#Implementations|ディスクパフォーマンス]] は低くなります。[[wikipedia:Disk encryption hardware|ハードウェアによる暗号化]] の場合は性能には影響ありません。[[ディスクの完全消去#データの残留]] を参照してください。}}
   
 
{{Note|ファイルのアクセス時刻や変更時刻を残したくない場合、{{man|1|touch}} コマンドを使って時刻を変更したり {{man|1|stat}} コマンドでファイルにアクセスする前に時刻情報を読み込むことができます。サポートされているメタデータとタイムスタンプについては[[wikipedia:Comparison of file systems#Metadata|ファイルシステムの比較]]を見てください。}}
 
{{Note|ファイルのアクセス時刻や変更時刻を残したくない場合、{{man|1|touch}} コマンドを使って時刻を変更したり {{man|1|stat}} コマンドでファイルにアクセスする前に時刻情報を読み込むことができます。サポートされているメタデータとタイムスタンプについては[[wikipedia:Comparison of file systems#Metadata|ファイルシステムの比較]]を見てください。}}
   
  +
単一ファイルのワイプは、2つの基本的な方法と1つの高度なアンチフォレンジック時間がかかる方法で構成されており、専用のツールでのみ可能ですが、最後の1つの方法はこの記事でカバーしません。
Wiping of a single file consists of two basic and one advanced anti-forensic time consumed method that can be done only with specialized tools, the last one method will not be covered in this article.
 
   
 
* 削除する前にランダムなデータで上書きしたり、同じサイズの別のファイルで内容を置き換える。
 
* 削除する前にランダムなデータで上書きしたり、同じサイズの別のファイルで内容を置き換える。
   
 
* 特殊なツールを使ってファイルシステムに保存されているファイルとメタデータを消去する。
 
* 特殊なツールを使ってファイルシステムに保存されているファイルとメタデータを消去する。
  +
** ディスク全体を検索して、削除された残骸の部分を探し、他のファイルやその痕跡に変更を加えることなく、それらも消去することができます。
** Search the whole disk for the deleted left-over parts of the file and wipe them too without making any changes to other files and their traces.
 
   
 
一般的な Linux ユーティリティを使うことでサイズを変更することなくファイルを上書きすることができます:
 
一般的な Linux ユーティリティを使うことでサイズを変更することなくファイルを上書きすることができます:
   
* {{ic|shred -x ''file''}} を実行すると ''file'' ファイルの中身が擬似乱数のデータに置き換わります。ファイルサイズは変わりません ({{ic|-x}}){{ic|-u}} オプションを使うと上書きした後に ''file'' が削除されます。
+
* {{ic|shred -x ''file''}} を実行すると ''file'' ファイルの中身が擬似乱数のデータに置き換わります。ファイルサイズは変わりません ({{ic|-x}}) {{ic|-u}} オプションを使うと上書きした後に ''file'' が削除されます。
   
  +
* {{ic|mkfs}} を使うと、ファイルをファイルシステムに変換して、その中のすべてを変更したり、マウントしたり、他のコンテンツで埋めて上書きしたりすることができます。
* With {{ic|mkfs}} you can convert file into the filesystem that will alter everything in it, mount and fill in with any other content for a better overwriting.
 
   
  +
* {{ic|dd}} は、あらかじめ設定したサイズと内容のファイルを作成し、保存先のファイル名が存在する場合は上書きします。{{ic|dd}} は {{ic|skip}} と {{ic|seek}} オプションを組み合わせて、ファイル全体または一部だけを別の内容に置き換えることができます。ファイルの拡張を避けるために、ファイルのサイズを知る必要がありますが、 {{ic|du -b ''file_name'' <nowiki>|</nowiki> cut -f1}} や {{ic|stat -c "%s" ''file_name''}} で可能です。ファイルに対して正しく動作させるためには、{{ic|1=iflag=fullblock}} オプションを使用することが必須です。
* The {{ic|dd}} will create a file with preset size and content of your chose, if destination file name exist then it will become overwritten. With {{ic|dd}} command you can replace the whole file or only a part in it with another content by combining {{ic|skip}} and {{ic|seek}} options. You need to know size of the file to avoid expand of the file, to do it can use {{ic|du -b ''file_name'' <nowiki>|</nowiki> cut -f1}} or {{ic|stat -c "%s" ''file_name''}}. It is mandatory to use {{ic|1=iflag=fullblock}} option to make it work correct with the file.
 
   
  +
* {{Pkg|perl}} ユーティリティで行えるサイズ変更を避けるため、ファイル内のコンテンツを単一のシンボルに置き換えます。
* Replace content in a file with a single symbol to avoid size changing you can do with {{Pkg|perl}} utility.
 
   
メタデータを消去したい場合、パーティションをファイルで一杯にすることでファイルに関する古いエントリを新しいエントリでファイルシステムに置き換えさせることができます。あるいは特殊なユーティリティを使用する方法もあります。下の[[#空き領域の消去|空き領域の消去]]セクションを見てください。
+
メタデータを消去したい場合、パーティションをファイルで一杯にすることでファイルに関する古いエントリを新しいエントリでファイルシステムに置き換えさせることができます。あるいは特殊なユーティリティを使用する方法もあります。下の [[#空き領域の消去|空き領域の消去]] セクションを見てください。
   
  +
すべての Linux ファイル作成および変換ツールをどのように組み合わせて、ファイルの回復を防止したり、回復ツールと、ランダムに書き換えたり、事前定義されたコンテンツに置き換えたりして回復ツールを使用する人を誤解させたりするかは、あなた次第です。
It is up to you how to combine all of Linux file creation and conversion tools to prevent recovery of files and/or mislead recovery tools and them who uses it by rewriting with random or replace with predefined content.
 
   
 
{{Note|
 
{{Note|
  +
* 単純な上書きでは、空き容量がある場合、ファイルのずれた部分が残ってしまう可能性があります。
* Simple overwriting has a chance to leave dislocated parts of file if free space is available.
 
  +
* ディスク上の位置を変えずに特定のファイルの内容を書き換えるには、まずパーティションを一杯にするファイルを作成し、その後、好みのユーティリティで隠したいファイルの内容を書き換えたり、置き換えたりします。空き容量が大きく、ファイル数が少ない場合は、作業時間が長くなります。}}
* To rewrite content of specific files without changing their location on the disk you can first create a file or files to make partition full and then rewrite or replace content in files you want to hide with preferred utilities. It consumes much useful time if free space is very big and files are very few.}}
 
   
 
例:
 
例:
44行目: 44行目:
 
$ <nowiki>perl -p -i -e 's\[^*]\.\g'</nowiki> ''file_name''
 
$ <nowiki>perl -p -i -e 's\[^*]\.\g'</nowiki> ''file_name''
   
dd:
+
[[dd]]:
 
$ ''source_content'' | dd bs=''size_in_bytes'' count=1 iflag=fullblock of=''destination_file'' seek=0
 
$ ''source_content'' | dd bs=''size_in_bytes'' count=1 iflag=fullblock of=''destination_file'' seek=0
  +
または、''stdout'' リダイレクトを使用すると、作成がわずかに高速になりますが、{{ic|seek}} オプションを使用して宛先の一部をスキップすることはできません。
Or by using ''stdout'' redirection that works a slightly faster for creation but you will not be able to use {{ic|seek}} option for skipping some parts in the destination:
 
 
$ ''source_content'' | dd bs=''size_in_bytes'' count=1 iflag=fullblock > ''destination_file''
 
$ ''source_content'' | dd bs=''size_in_bytes'' count=1 iflag=fullblock > ''destination_file''
   
  +
{{Tip|ソースファイルがデスティネーションより低い場合は、以下のセクションで説明する {{ic|while}} ループと組み合わせる必要があります。}}
{{Tip|If source file is lower than destination then you will need to combine it with the {{ic|while}} loop described in the section below.}}
 
   
 
参照:
 
参照:
* [https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets convert charset in text files]
+
* [https://stackoverflow.com/questions/64860/best-way-to-convert-text-files-between-character-sets テキストファイルの文字セットを変換する]
* [http://tldp.org/LDP/abs/html/here-docs.html Advanced Bash-Scripting Guide] - describes more advanced ways about how to create files from a bash script
+
* [http://tldp.org/LDP/abs/html/here-docs.html Advanced Bash-Scripting Guide] - bash スクリプトからファイルを作成する方法について、より高度な方法について説明します。
* [http://www.computing.net/answers/unix/alternative-for-sed-i/7800.html sed alternatives] - a perl example that works better than sed for replacing content in a file
+
* [http://www.computing.net/answers/unix/alternative-for-sed-i/7800.html sed alternatives] - ファイル内のコンテンツを置き換えるための sed よりもうまく機能する perl の例
   
 
== 対象の上書き ==
 
== 対象の上書き ==
80行目: 80行目:
 
| pv -bartpes <DISK_SIZE> | dd bs=64K of=/dev/sd"X"
 
| pv -bartpes <DISK_SIZE> | dd bs=64K of=/dev/sd"X"
   
  +
(オプションの) バイト単位の合計ディスク サイズ ({{ic|DISK_SIZE}}) は、次の方法で取得できます。
where the (optional) total disk size in bytes ({{ic|DISK_SIZE}}) may be obtained via:
 
 
{{hc|# blockdev --getsize64 /dev/sd"X"|2=
 
{{hc|# blockdev --getsize64 /dev/sd"X"|2=
 
250059350016}}
 
250059350016}}
   
  +
上のコマンドは、{{ic|/dev/urandom}} からシードされた128バイトの暗号鍵を作成します。CTR モードの AES-256 は、urandom キーで {{ic|/dev/zero}} の出力を暗号化するために使用されます。疑似ランダムソースの代わりに暗号を利用することで、非常に高い書き込み速度が得られ、結果としてデバイスがAES暗号文に埋め尽くされます。
The command above creates a 128 byte encryption key seeded from {{ic|/dev/urandom}}. AES-256 in CTR mode is used to encrypt {{ic|/dev/zero}}'s output with the urandom key. Utilizing the cipher instead of a pseudorandom source results in very high write speeds and the result is a device filled with AES ciphertext.
 
   
  +
ブロックサイズは、通常デフォルトの512バイトより高速で、さまざまなハードウェアでほぼ最適な転送速度が得られるため、上記では64Kに設定されています。
The block size is set to 64K above as it is usually faster than the default 512 bytes, and yields nearly optimal transfer rates across a range of hardware:
 
[https://superuser.com/questions/234199/good-block-size-for-disk-cloning-with-diskdump-dd] and the references therein.
+
[https://superuser.com/questions/234199/good-block-size-for-disk-cloning-with-diskdump-dd] こちらも参照。
   
 
[[Dm-crypt/ドライブの準備#dm-crypt で空のディスクまたはパーティションを消去]]に同じような方法が載っています。
 
[[Dm-crypt/ドライブの準備#dm-crypt で空のディスクまたはパーティションを消去]]に同じような方法が載っています。
93行目: 93行目:
 
=== テンプレートファイルを使う ===
 
=== テンプレートファイルを使う ===
   
  +
ゼロの代わりに、見つけて欲しいファイルの束や、{{ic|mkfs}} フォーマットされたファイルで作られたパーティションプリントが使えますが、コンテンツやお好みのユーティリティから繰り返し出力されるものでマウントして埋める必要があります。
Instead of zeros you can use a bunch of files you want to be found or partition prints made by {{ic|mkfs}} formatted files but you should mount and fill it up with content or with any other repeated output from utilities of your choice.
 
   
  +
デバイスが終了するまでワイプするという方法もありますが、デバイス終了に関するエラーが表示されたときに [[wikipedia:ja:シグナル (Unix)|stop keys]] を使って {{ic|while}} ループを中断しなければならないので、この種のリダイレクトは推奨されません。
One way is to wipe until device ends, but this type of redirection is not recommended because you have to use [[wikipedia:Unix signal|stop keys]] to break the {{ic|while}} loop when errors about device end will show up:
 
   
 
$ while [ 1 -lt 2 ];do cat file1-to-use.as-template file2-to-use.as-template /tmp/templatefiles/* ;done > /dev/sd"XY"
 
$ while [ 1 -lt 2 ];do cat file1-to-use.as-template file2-to-use.as-template /tmp/templatefiles/* ;done > /dev/sd"XY"
   
  +
''dd'' を使うと、オプションでワイプするサイズを正しく設定すれば、スペースエラーなしに安全にワイプを繰り返すことができます。''stdout'' の while ループの中で ''dd'' を使うと、{{ic|skip}} と {{ic|seek}} オプションをランダムまたは固定値で組み合わせて、ファイルのどの部分を復元するかを選択することができるようになります。
With ''dd'' you can safely wipe repetitively without out-of-space-errors, if size to be wiped is set up correctly with options. By using ''dd'' inside the while loop for ''stdout'' you will be able to chose which part of the file you want to restore by combining the {{ic|skip}} and {{ic|seek}} options with random or fixed values e.g. restore only partition start or end from a file, related are {{man|1|head}} and {{man|1|tail}} commands for output of the file parts to ''stdout''.
 
   
 
{{bc|1=<nowiki>while [ 2 -gt 1 ]; do
 
{{bc|1=<nowiki>while [ 2 -gt 1 ]; do
108行目: 108行目:
 
done |</nowiki> dd of=/dev/sd"XY" seek=''start_sector'' bs=''sector_size'' count=''sectors_to_wipe''}}
 
done |</nowiki> dd of=/dev/sd"XY" seek=''start_sector'' bs=''sector_size'' count=''sectors_to_wipe''}}
   
  +
{{Tip|同じ箇所を繰り返し書き換える場合。また、{{ic|<nowiki>while ... done | dd ...</nowiki>}} のあたりの2回目のループの変数を使用して、新しいループごとに使用するソーステンプレートファイルの行き先を変更することができます。
{{Tip|For repeatedly rewriting of the same area. You can also use variables from second loop around {{ic|<nowiki>while ... done | dd ...</nowiki>}} to change destination of the source template files to use on each new loop.
 
 
}}
 
}}
{{Note|If you have a real big amount of predefined data to use for overwriting then you can use the ability of [http://tldp.org/HOWTO/SquashFS-HOWTO/creatingandusing.html SquashFS] to compress files and folders. Compressing them into a mounted [http://www.linuxscrew.com/2010/03/24/fastest-way-to-create-ramdisk-in-ubuntulinux/ ramdisk] will minimize the amount of physical reads but will higher CPU usage. Or create the compressed archive, copy into the [http://www.linuxscrew.com/2010/03/24/fastest-way-to-create-ramdisk-in-ubuntulinux/ ramdisk] and use a file extraction utility that can extract to stdout. Downsides are that it is harder to navigate between folders and files, if you do not want to use all and same content for each run. Upsides are that you can use even raw parts of the archive, if it was split into volumes upon creation.}}
+
{{Note|上書きに使用する定義済みデータが本当に大量にある場合は、[http://tldp.org/HOWTO/SquashFS-HOWTO/creatingandusing.html SquashFS] の機能を使用してファイルやフォルダを圧縮することができます。マウントされた [http://www.linuxscrew.com/2010/03/24/fastest-way-to-create-ramdisk-in-ubuntulinux/ ramdisk] に圧縮すれば、物理的な読み込みは少なくなりますが、CPU使用率は高くなります。または、圧縮されたアーカイブを作成し、[http://www.linuxscrew.com/2010/03/24/fastest-way-to-create-ramdisk-in-ubuntulinux/ ramdisk]にコピーして、標準出力に展開できるファイル展開ユーティリティを使用することもできます。欠点は、各実行ですべて同じ内容を使用したくない場合、フォルダとファイルの間を移動するのが難しくなることです。利点は、アーカイブが作成時にボリュームに分割されている場合、アーカイブの生の部分でも使用することができることです。}}
   
 
参照:
 
参照:
* [http://flashdba.com/4k-sector-size/ sector size] - file creation and sector sizes
+
* [http://flashdba.com/4k-sector-size/ sector size] - ファイルの作成とセクターサイズ
   
 
== 空き領域の消去 ==
 
== 空き領域の消去 ==
   
{{Warning|[[ディスクの完全消去#ブロックデバイス暗号化の準備|ブロックデバイス暗号化の準備]]をする前に以下を使うのは適切ではありません。}}
+
{{Warning|[[ディスクの完全消去#ブロックデバイス暗号化の準備|ブロックデバイス暗号化の準備]] をする前に以下を使うのは適切ではありません。}}
   
 
空き領域は複数の方法で消去できます:
 
空き領域は複数の方法で消去できます:
   
* パーティションやデバイスではなくファイルに[[ディスクの完全消去#出力のリダイレクト|出力をリダイレクト]]
+
* パーティションやデバイスではなくファイルに [[ディスクの完全消去#出力のリダイレクト|出力をリダイレクト]]
   
  +
* たとえば {{ic|cp}} コマンドを使用して、空き領域がなくなるまで、ランダムなファイル名または宛先ディレクトリを使用してループで複数のファイルをコピーします。
* Create multiple file copies by using e.g. {{ic|cp}} command in loops with random file names or destination directories until no free space will be left.
 
   
  +
* ランダムなパスワードとファイル名で暗号化されたファイルを作成するユーティリティを使用します。ファイル圧縮ユーティリティの中には、圧縮方法、ファイルタイプのオプションがあり、作成時にファイルをプリセットサイズのボリュームに分割できるものもあります。いくつかのオプションをランダムに使用してループさせることで、空き領域全体を暗号化されたデータで満たし、以前のデータを上書きすることができます。
* Use an utility that creates encrypted files with random password and file names.
 
   
  +
* 次のような空き領域消去専用のプログラムを使用する。
* Use a specialized program for the free space wiping such as {{AUR|wipefreespace}}.
 
  +
{{App|wipefreespace|Wipe Free Space は、ファイルシステムの空き領域を安全に消去して、削除された機密データの回復を防ぎます。|https://sourceforge.net/projects/wipefreespace/|{{AUR|wipefreespace}}}}
  +
{{App|zerofree|ファイルシステム内のゼロ以外の空きブロックをスキャンし、それらをゼロで埋めます|https://frippery.org/uml/|{{AUR|zerofree}}}}
   
  +
=== dd を使う ===
Some of the file compression utilities use to have many types of the compression methods, file types and can even split file into volumes of the preset size upon creation. By using all options at random and into the loop you will be able to fill the whole free space up with a useless encrypted data that will overwrite everything else that was deleted. Just do not forget to remove created files and run it many times to ensure that even forensic specialists will get harder to restore very sensitive data on it.
 
   
  +
[[dd]] を使用して、空のスペースを埋めるファイルを作成できます。
=== 7zip ===
 
  +
dd if=''source'' of=junk
  +
sync
  +
rm junk
  +
  +
{{ic|''source''}} には {{ic|/dev/urandom}} または {{ic|/dev/zero}} ストリームを指定することができます。
  +
データはディスク上で同期されたことを確認した後、ファイルは削除されます。
  +
  +
=== 7zip を使う ===
   
 
{{bc|1=Password="$(dd if=/dev/urandom bs=128 count=1)"
 
{{bc|1=Password="$(dd if=/dev/urandom bs=128 count=1)"
139行目: 149行目:
 
使用しているオプションの説明は {{man|1|7z}} を参照してください。
 
使用しているオプションの説明は {{man|1|7z}} を参照してください。
   
  +
{{ic|source}} には、ランダムなデータを含む定義済みのファイルや、デバイス、例えば {{ic|/dev/urandom}} やその上の別のブロックデバイスやパーティション、例えば {{ic|/dev/sd "XY"}} を指定でき、その上で、見られても大丈夫なデータなら削除したファイルも圧縮先に送られることになります。
The {{ic|source}} can be a predefined file with random data or a device, e.g. {{ic|/dev/urandom}} or another block device or partition on it, e.g. {{ic|/dev/sd"XY"}}, with data you are not afraid to be found then even deleted files on it will be compressed to the destination.
 
   
 
{{Note|
 
{{Note|
  +
* CPU 使用率を抑えるためのデータ保存と、空き容量を早く埋めるための圧縮レベルの設定は必要ありません。
* It is not necessary to set level of compression, enough to store data for minimizing CPU usage and a faster fill free space up.
 
  +
* また、RAM をある程度確保する [[tmpfs]] を使用しているため、読み込みが高速化されます。}}
* If you are using a single file as a source then you can put it into the [http://www.vanemery.com/Linux/Ramdisk/ramdisk.html RAM disk] or the {{ic|/tmp}} folder, because it uses [[tmpfs]] that allocates some amount of RAM because it will speed up reading.}}
 
   
 
=== ''timeout'' コマンドを利用して複数のファイルを作成 ===
 
=== ''timeout'' コマンドを利用して複数のファイルを作成 ===
   
  +
[http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html loop] で使用されるランダムな待ち時間を持つ {{ic|timeout}} コマンドは、ランダムなサイズのファイルを残すため、コマンドを中断します。これは遅い方法ですが、可能な代替案の1つです。また、ランダム部分の前にあらかじめ定義されたファイル名を持つ配列を使うこともできます。
The {{ic|timeout}} command with randomized waiting time used it in a [http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html loop] will break the command that will leave a file with random size. This is a slow method but is one of the possible alternatives. You can also use an array with predefined file names before the random part of it.
 
   
 
{{bc|<nowiki>AA=${RANDOM/0/1};
 
{{bc|<nowiki>AA=${RANDOM/0/1};
154行目: 164行目:
   
 
参照:
 
参照:
* [[wikipedia:Comparison of file systems#Limits|limits]] for the file creation on the different file systems.
+
* [[wikipedia:Comparison of file systems#Limits|limits]] 異なるファイルシステムでのファイル作成用。
* [http://www.r-tt.com/Articles/File_Recovery_Basics/ meta-data] in the filesystem may keep information about file after it was deleted.
+
* [http://www.r-tt.com/Articles/File_Recovery_Basics/ meta-data] ファイルシステム内のファイルは、削除された後もファイルに関する情報を保持する場合があります。
* [https://security.stackexchange.com/questions/58515/how-does-forensic-software-detect-deleted-files forensic software] uses meta-data to recovery and what need to do for wiping of the meta-data.
+
* [https://security.stackexchange.com/questions/58515/how-does-forensic-software-detect-deleted-files forensic software] メタデータを使用して回復し、メタデータを消去するために何をする必要があるか。

2023年2月16日 (木) 05:53時点における最新版

メインの記事はディスクの完全消去を見てください。

この記事では素早く消去することができる特殊なユーティリティを使用する消去方法について説明します。

警告: 予約ブロックはファイルの作成では消去されません。tune2fs ユーティリティを使うことで無効にできます。

単体ファイルの消去

警告: パーティションが 断片化 している場合や、パーティションをリサイズあるいは移動したことがある場合、もしくは同一デバイス上にファイルが 重複 している場合、単体ファイルの消去は効率的ではありません。データ暗号化 コンテナを消去した場合、リカバリするのが難しくなりますが暗号化の ディスクパフォーマンス は低くなります。ハードウェアによる暗号化 の場合は性能には影響ありません。ディスクの完全消去#データの残留 を参照してください。
ノート: ファイルのアクセス時刻や変更時刻を残したくない場合、touch(1) コマンドを使って時刻を変更したり stat(1) コマンドでファイルにアクセスする前に時刻情報を読み込むことができます。サポートされているメタデータとタイムスタンプについてはファイルシステムの比較を見てください。

単一ファイルのワイプは、2つの基本的な方法と1つの高度なアンチフォレンジック時間がかかる方法で構成されており、専用のツールでのみ可能ですが、最後の1つの方法はこの記事でカバーしません。

  • 削除する前にランダムなデータで上書きしたり、同じサイズの別のファイルで内容を置き換える。
  • 特殊なツールを使ってファイルシステムに保存されているファイルとメタデータを消去する。
    • ディスク全体を検索して、削除された残骸の部分を探し、他のファイルやその痕跡に変更を加えることなく、それらも消去することができます。

一般的な Linux ユーティリティを使うことでサイズを変更することなくファイルを上書きすることができます:

  • shred -x file を実行すると file ファイルの中身が擬似乱数のデータに置き換わります。ファイルサイズは変わりません (-x) -u オプションを使うと上書きした後に file が削除されます。
  • mkfs を使うと、ファイルをファイルシステムに変換して、その中のすべてを変更したり、マウントしたり、他のコンテンツで埋めて上書きしたりすることができます。
  • dd は、あらかじめ設定したサイズと内容のファイルを作成し、保存先のファイル名が存在する場合は上書きします。ddskipseek オプションを組み合わせて、ファイル全体または一部だけを別の内容に置き換えることができます。ファイルの拡張を避けるために、ファイルのサイズを知る必要がありますが、 du -b file_name | cut -f1stat -c "%s" file_name で可能です。ファイルに対して正しく動作させるためには、iflag=fullblock オプションを使用することが必須です。
  • perl ユーティリティで行えるサイズ変更を避けるため、ファイル内のコンテンツを単一のシンボルに置き換えます。

メタデータを消去したい場合、パーティションをファイルで一杯にすることでファイルに関する古いエントリを新しいエントリでファイルシステムに置き換えさせることができます。あるいは特殊なユーティリティを使用する方法もあります。下の 空き領域の消去 セクションを見てください。

すべての Linux ファイル作成および変換ツールをどのように組み合わせて、ファイルの回復を防止したり、回復ツールと、ランダムに書き換えたり、事前定義されたコンテンツに置き換えたりして回復ツールを使用する人を誤解させたりするかは、あなた次第です。

ノート:
  • 単純な上書きでは、空き容量がある場合、ファイルのずれた部分が残ってしまう可能性があります。
  • ディスク上の位置を変えずに特定のファイルの内容を書き換えるには、まずパーティションを一杯にするファイルを作成し、その後、好みのユーティリティで隠したいファイルの内容を書き換えたり、置き換えたりします。空き容量が大きく、ファイル数が少ない場合は、作業時間が長くなります。

例:

ファイルの中身を全て . に置き換える Perl コマンド:

$ perl -p -i -e 's\[^*]\.\g' file_name

dd:

$ source_content | dd bs=size_in_bytes count=1 iflag=fullblock of=destination_file seek=0

または、stdout リダイレクトを使用すると、作成がわずかに高速になりますが、seek オプションを使用して宛先の一部をスキップすることはできません。

$ source_content | dd bs=size_in_bytes count=1 iflag=fullblock > destination_file
ヒント: ソースファイルがデスティネーションより低い場合は、以下のセクションで説明する while ループと組み合わせる必要があります。

参照:

対象の上書き

マウントされているパーティションを消去しない

注意して消去するデバイスを選択してください。間違えるとシステムを破損してしまう恐れがあります。危険を避けるために、消去ツールをラッピングするスクリプトを使うことができます。例:

if [[ -e "$1" && -b "$1" ]];then 
NOT_safe="$(lsblk -o "NAME,MOUNTPOINT" ${1//[0-9]/} | grep -e / -e '\]')";
 if [[ -z "$NOT_safe" ]];then
# Here you can use any of your favourite wiping tools 
# to wipe destination passed on command line and stored in variable "$1"
# 
  else
  echo 'Not allowed to destroy if any of the partitions is mounted: '"$NOT_safe"
 fi
fi 

dd - 高度な例

以下のコマンドは OpenSSL によるランダムなシードの AES 暗号を使ってドライブやパーティションをランダム化します (pv で進捗メーターが表示されます):

# openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero \
    | pv -bartpes <DISK_SIZE> | dd bs=64K of=/dev/sd"X"

(オプションの) バイト単位の合計ディスク サイズ (DISK_SIZE) は、次の方法で取得できます。

# blockdev --getsize64 /dev/sd"X"
250059350016

上のコマンドは、/dev/urandom からシードされた128バイトの暗号鍵を作成します。CTR モードの AES-256 は、urandom キーで /dev/zero の出力を暗号化するために使用されます。疑似ランダムソースの代わりに暗号を利用することで、非常に高い書き込み速度が得られ、結果としてデバイスがAES暗号文に埋め尽くされます。

ブロックサイズは、通常デフォルトの512バイトより高速で、さまざまなハードウェアでほぼ最適な転送速度が得られるため、上記では64Kに設定されています。 [1] こちらも参照。

Dm-crypt/ドライブの準備#dm-crypt で空のディスクまたはパーティションを消去に同じような方法が載っています。

テンプレートファイルを使う

ゼロの代わりに、見つけて欲しいファイルの束や、mkfs フォーマットされたファイルで作られたパーティションプリントが使えますが、コンテンツやお好みのユーティリティから繰り返し出力されるものでマウントして埋める必要があります。

デバイスが終了するまでワイプするという方法もありますが、デバイス終了に関するエラーが表示されたときに stop keys を使って while ループを中断しなければならないので、この種のリダイレクトは推奨されません。

$ while [ 1 -lt 2 ];do cat file1-to-use.as-template file2-to-use.as-template /tmp/templatefiles/* ;done > /dev/sd"XY"

dd を使うと、オプションでワイプするサイズを正しく設定すれば、スペースエラーなしに安全にワイプを繰り返すことができます。stdout の while ループの中で dd を使うと、skipseek オプションをランダムまたは固定値で組み合わせて、ファイルのどの部分を復元するかを選択することができるようになります。

while [ 2 -gt 1 ]; do 
 if [ -z "$(pidof dd)"  ];then 
  break ;
 fi;
cat file1-to-use.as-template file2-to-use.as-template /tmp/templatefiles/* ;
done | dd of=/dev/sd"XY" seek=start_sector bs=sector_size count=sectors_to_wipe
ヒント: 同じ箇所を繰り返し書き換える場合。また、while ... done | dd ... のあたりの2回目のループの変数を使用して、新しいループごとに使用するソーステンプレートファイルの行き先を変更することができます。
ノート: 上書きに使用する定義済みデータが本当に大量にある場合は、SquashFS の機能を使用してファイルやフォルダを圧縮することができます。マウントされた ramdisk に圧縮すれば、物理的な読み込みは少なくなりますが、CPU使用率は高くなります。または、圧縮されたアーカイブを作成し、ramdiskにコピーして、標準出力に展開できるファイル展開ユーティリティを使用することもできます。欠点は、各実行ですべて同じ内容を使用したくない場合、フォルダとファイルの間を移動するのが難しくなることです。利点は、アーカイブが作成時にボリュームに分割されている場合、アーカイブの生の部分でも使用することができることです。

参照:

  • sector size - ファイルの作成とセクターサイズ

空き領域の消去

警告: ブロックデバイス暗号化の準備 をする前に以下を使うのは適切ではありません。

空き領域は複数の方法で消去できます:

  • たとえば cp コマンドを使用して、空き領域がなくなるまで、ランダムなファイル名または宛先ディレクトリを使用してループで複数のファイルをコピーします。
  • ランダムなパスワードとファイル名で暗号化されたファイルを作成するユーティリティを使用します。ファイル圧縮ユーティリティの中には、圧縮方法、ファイルタイプのオプションがあり、作成時にファイルをプリセットサイズのボリュームに分割できるものもあります。いくつかのオプションをランダムに使用してループさせることで、空き領域全体を暗号化されたデータで満たし、以前のデータを上書きすることができます。
  • 次のような空き領域消去専用のプログラムを使用する。

wipefreespace — Wipe Free Space は、ファイルシステムの空き領域を安全に消去して、削除された機密データの回復を防ぎます。

https://sourceforge.net/projects/wipefreespace/ || wipefreespaceAUR

zerofree — ファイルシステム内のゼロ以外の空きブロックをスキャンし、それらをゼロで埋めます

https://frippery.org/uml/ || zerofreeAUR

dd を使う

dd を使用して、空のスペースを埋めるファイルを作成できます。

dd if=source of=junk
sync
rm junk

source には /dev/urandom または /dev/zero ストリームを指定することができます。 データはディスク上で同期されたことを確認した後、ファイルは削除されます。

7zip を使う

Password="$(dd if=/dev/urandom bs=128 count=1)"
DestinationFile="$((${RANDOM/0/1}$(date "+%s")/${RANDOM/0/1}))"
7z a -t7z -mhe=on -p"${Password}" -mx=0 -v1m ${DestinationFile} source

使用しているオプションの説明は 7z(1) を参照してください。

source には、ランダムなデータを含む定義済みのファイルや、デバイス、例えば /dev/urandom やその上の別のブロックデバイスやパーティション、例えば /dev/sd "XY" を指定でき、その上で、見られても大丈夫なデータなら削除したファイルも圧縮先に送られることになります。

ノート:
  • CPU 使用率を抑えるためのデータ保存と、空き容量を早く埋めるための圧縮レベルの設定は必要ありません。
  • また、RAM をある程度確保する tmpfs を使用しているため、読み込みが高速化されます。

timeout コマンドを利用して複数のファイルを作成

loop で使用されるランダムな待ち時間を持つ timeout コマンドは、ランダムなサイズのファイルを残すため、コマンドを中断します。これは遅い方法ですが、可能な代替案の1つです。また、ランダム部分の前にあらかじめ定義されたファイル名を持つ配列を使うこともできます。

AA=${RANDOM/0/1};
timeout $((AA/100)) cat /dev/urandom > filename${RANDOM}.tmp;

参照:

  • limits 異なるファイルシステムでのファイル作成用。
  • meta-data ファイルシステム内のファイルは、削除された後もファイルに関する情報を保持する場合があります。
  • forensic software メタデータを使用して回復し、メタデータを消去するために何をする必要があるか。