Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Double loop?

by Dietz (Curate)
on Apr 30, 2005 at 17:36 UTC ( #452895=note: print w/ replies, xml ) Need Help??


in reply to Double loop?

Well, I gave it a try and refactored your script just a bit ;-).
I also included 'use strict' and 'use warnings'.

Note: passwords.txt should contain the plain password and Wordlist should contain the hash
I confused the files and changed 'crack($_, $curpass_);' to 'crack($curpass, $_);'

#!/usr/bin/perl use strict; use warnings; use Getopt::Std; use Digest::SHA qw(sha1_hex sha224_hex sha256_hex sha384_hex sha512_he +x); use Digest::MD5 qw(md5_hex); getopts('d:h:f:m:a', \my %opts); my $dictionary = $opts{d} || '/usr/share/dict/words'; my $hash = $opts{h}; my $passfile = $opts{f}; my $mode = $opts{m} || 'md5'; my $help = $opts{a}; my %algo = ( md5 => [ 32, \&md5_hex ], sha1 => [ 40, \&sha1_hex ], sha224 => [ 56, \&sha224_hex ], sha256 => [ 64, \&sha256_hex ], sha384 => [ 96, \&sha384_hex ], sha512 => [128, \&sha512_hex ], ); die help() if $hash and $passfile or $help; die help() unless $passfile or $hash; if ($hash) { len_err() unless length($hash) == $algo{$mode}[0]; open DICT, $dictionary or file_err('dictionary', $dictionary); print "Cracking hash ...\n"; while(<DICT>) { crack($hash, $_); } } if ($passfile) { open PASS, $passfile or file_err('password', $passfile); print "Cracking file ...\n"; while(<PASS>) { chomp(my $curpass = $_); open DICT, $dictionary or file_err('dictionary', $dictionary); while(<DICT>) { #crack($_, $curpass); wrong order crack($curpass, $_); } } close PASS; } sub crack { chomp(my $hash = shift); chomp(my $pass = shift); my $crack = $algo{$mode}[1]($pass); if($hash eq $crack) { print "\nMatch found!\nPlainText : $pass\n\n"; exit 0; } } sub len_err { die " Invalid hash length!\n Length for an $mode hash should be $algo{$mode}[0]!\n See $0 -a for details\n"; } sub file_err { my ($type, $file) = @_; die " Could not open $type file : $file. Please make sure the file exists and you have read access to it. Error occured\n"; } sub help { print " Usage: $0 [-d dictionary] [-h hash|-f file] [-m mode]\n Crack [hash] or [file] using [mode] hashing, and [dictionary] +file.\n Currently, supported hashing methods are: MD5 SHA1 SHA224 SHA256 SHA384 SHA512 If no dictionary file is specified, /usr/share/dict/words will + be used.\n If no mode is specified, MD5 will be used. Example: $0 -h a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 -m sha1 $0 -d /usr/local/Wordlist -h 098f6bcd4621d373cade4e832627b4f6 $0 -f /usr/bin/passwords.txt -d /usr/local/Wordlist\n"; exit; }


Comment on Re: Double loop?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://452895]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2014-12-18 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (67 votes), past polls