#!/usr/bin/perl -w
#
#
#
# Shred.pl 0.5 by L. Wells
# Secure file deletion utility
# Licensed under the GPL (http://www.opensource.org/licenses/gpl-licen
+se.html)
# December 28, 2001
#
#
#
#
# TODO:
# Finish support for other encryption algorithms.
# Add annoying little progress bar type things.
#
#
#
use IO::File;
use Crypt::Blowfish;
use Getopt::Std;
use strict;
my $filename;
my $verbose = 0;
my %opts;
getopts("vVha:f:i:", \%opts);
if ($opts{f}) {
$filename=$opts{f} or die "No file specified $!";
}
if ($opts{v}) {
do_version();
}
if ($opts{h} || !$opts{f}) {
do_help();
}
if ($opts{V}) {
$verbose = 1;
}
my $keysize=56;
my $blocksize=8;
my $random=1;
my $iterations=7;
my $entropyfile="/dev/urandom";
my $null=chr(0);
my $one=chr(255);
my $the_key = gather_entropy($keysize);
my $cipher = new Crypt::Blowfish $the_key;
my $b;
my $i;
my $size = (stat($filename))[7] or die "no $filename: $!";
sub nuke_file($);
sub do_version;
sub do_help;
if ($opts{i}) {
$iterations=$opts{i};
}
for ($b=1;$b <=$iterations;$b++) {
if ($verbose) {
print "Wipe iteration $b\n";
}
nuke_file($null);
if ($verbose) {
print "Null wipe $b\n";
}
nuke_file($one);
if ($verbose) {
print "One wipe $b\n";
}
nuke_file($random);
if ($verbose) {
print "Crypt wipe $b\n";
}
}
unlink ($filename);
if ($verbose) {
print "Wipe finished. Completed $iterations iterations\n";
}
sub do_cipherstring {
my $outchar = gather_entropy($blocksize);
my $cipherout = $cipher->encrypt($outchar);
return $cipherout;
}
sub gather_entropy {
my $bytes=$_[0];
my $entropy_bytes;
sysopen (ENTROPY, $entropyfile, O_RDONLY);
sysread(ENTROPY, $entropy_bytes, $bytes);
close(ENTROPY);
return $entropy_bytes;
}
sub nuke_file ($){
my $o_w = $_[0];
sysopen(BYEBYE, $filename, O_WRONLY) or die $!;
for ($i=0;$i<($size/$blocksize);$i++) {
if ($o_w ne $null && $o_w ne $one) {
$o_w=do_cipherstring;
}
my $err = syswrite(BYEBYE, $o_w, $blocksize, 0) or die $!;
my $bytes += $err;
}
close(BYEBYE);
}
sub do_version {
print "Shred.pl 0.5 by L. Wells\n\n";
exit(1);
}
sub do_help {
print "Shred.pl 0.5 by L. Wells\n";
print "Usage: Shred.pl -f filename [-i iterations] [-a algorit
+hm] [-vVh]\n";
print "\t-f filename\tWhere filename is the file to be nuked.\
+n";
print "\t-i iterations\tWhere iterations are the number of pas
+ses for overwriting.\n";
print "\t-v\t\tPrint version information and exit.\n";
print "\t-a algorithm\tSpecify which algorithm to use for cryp
+to pass. (NOT IMPLEMENTED)\n";
print "\t-V\t\tVerbose mode. Shows more detailed information (
+Default is no output).\n";
print "\t-h\t\tHelp. Prints this help information.\n\n";
exit(1);
}
In reply to Shred
by descartes
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|