#!/usr/bin/perl # # Name: Matthew Reeves # # Program to test simple dictionary attacks against unsalted md5 hashes # use Modern::Perl; use Digest::MD5 qw(md5_hex); #allows use of the md5_hex function #open both files needed for read access open(SHADOW, "<", "shadow"); open(DICTIONARY, "<", "dictionary"); #declares scalars/arrays my @username; my @password; my @dictionary; my $count = 0; #while not at EOF read line by line username/password data from SHADOW while() { $_ =~ /(\w*):([0-9a-fA-F]*)/; push (@username, $1); push (@password, $2); } #while not at EOF read line by line dictionary entries from DICTIONARY while() { $_ =~ /(\w*)/; push (@dictionary, $1); } close SHADOW; close DICTIONARY; #close file handles #Nested for loops hash each dictionary password, #compare to hash from shadow file foreach my $pass (@password) { foreach my $dict (@dictionary) { if (md5_hex($dict) ~~ $pass) { #when hashes match, output plaintext #username:password print "$username[$count]:$dict\n"; } } #increments $count to track position for username array $count++; }