in reply to Secure delete ie shred a file

This is a tough problem, even if you have low level access to the disk. Perl does not. You could write code to delete the file then fill the entire hard disk by creating junk files, but that doesn't sound very efficient! You could perform a defrag following deleting a file and that may confuse the trail somewhat, or it may not.

How secure do you really need to be? There are techniques that may be used to recover data from disks that have been over written (they may require special hardware and likely effectively destroy the hard disk though) so anything trivial you do is unlikely to be enough to prevent highly motivated people from recovering data from your disk.

A good whack with a hammer is likely to be effective however.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Secure delete ie shred a file
by fluffyvoidwarrior (Monk) on Jan 26, 2006 at 07:55 UTC
    I would like to put deleted files beyond the reach of commercially available "undelete" programs at least. I don't think I have the expertise to confidently start poking with disks at a low level and so was hoping for a module. Maybe I can find a command line tool somewhere . . .

      Norton used to make a utility for doing what you want for FAT drives.


      DWIM is Perl's answer to Gödel
      Here's some untested code for you. The intention is to first figure out how much crap we need to overwrite the file with, then open the file in read/write mode - this avoids clobbering the file and creating a new one which would happen if we just opened the file for writing, and also means that we can get at the beginning of the file unlike if we opened it for appending. Then it just overwrites the file with 'X's. Finally, it closes the file and unlinks it.

      This will certainly protect you from "undelete" on DOS (all it will undelete is a file of 'X's) and DOS-a-likes such as Win95, and probably on WinNT and its successors if using the FAT filesystem. My understanding of ext2 leads me to believe that it should also protect you on most Linux systems. But I can't be sure that it will work anywhere else, including on Linux systems using stuff like Reiserfs, and as other people have pointed out, it certainly won't protect you against The Man. And even that paper is now out of date.

      my $bytes = -s $filename open(FILE, '+<', $filename); seek(FILE, 0, 0); print FILE "X" x $bytes; close(FILE); unlink $filename;
      "commercially available 'undelete'" sounds like you don't mean to consider even marginally clever adversaries. In this case, truncating the file may all you need, with copying something innocent (a random configuration or help file from a windows system directory) or such as a safer second choice. 'undelete' normally only covers *deletion*, right?