01-22-2011, 09:39 PM
(This post was last modified: 04-24-2011, 09:47 PM by AceInfinity.)
Here is a little perl script that I coded for simplicity in checking the MD5 sum for a specific file using the checksum method. MD5 is a good way to look for any file modifications if you have the MD5 of the original version of the file, and you see a different string in the file after checking it again.
I use this for checking the MD5 hash of a file that is available for download on a forum. Lots of people submit entries from virustotal or someplace else, which includes an MD5 hash string. If you notice a change in that MD5 you could assume that the original file they have scanned with virustotal has been replaced or modified which should raise some awareness to the downloader, since it may be an attempt to give you a virus of some sort
MD5 is a 128 bit value as well, just for some extra information.
Code:
#!/usr/bin/env perl
# This perl script generates MD5 Checksums
use strict;
use IO::File;
use Getopt::Long;
use Digest::MD5;
print "\n";
print "##########################################################\n";
print "# #\n";
print "# Coded by Infinity ~ MD5 Checker #\n";
print "# [MD5 Checksum] #\n";
print "#--------------------------------------------------------#\n";
print "##########################################################\n";
print "# #\n";
print "# Usage: md5_check.pl filename.extention #\n";
print "# Example: md5_check.pl image.jpg #\n";
print "# #\n";
print "# Note - Use in same directory of the file #\n";
print "# You want to check #\n";
print "# #\n";
print "##########################################################\n";
print "\n";
my $File = $ARGV[0];
my $md5 = Digest::MD5->new;
my $check = 1;
open(FILE, $File) or die "Error: Could not open $File for MD5 checksum, please refer to the usage...";
binmode(FILE);
my $md5sum = $md5->addfile(*FILE)->hexdigest;
close FILE;
print "\n";
print "Finished MD5 Checksum for $File:\n";
print "$md5sum\n";
print "\n";
save as whatever you want, I named mine md5_check.pl just so that I have an idea what the script does just by looking at the filename. I have lots of perl scripts that i've coded overtime so I would suggest you name them with appropriate titles as well so you know which is which
if you name it as something say md5.pl then ignore the usage that i've put in the "print" that gets displayed that says you have to use md5_check.pl. Should be common sense.
Put the perl file in the same directory as the file you want to find the MD5 hash of, and run in cmd prompt.
Enjoy