Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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; }

In reply to Re: Double loop? by Dietz
in thread Double loop? by RayQ

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (7)
    As of 2018-04-24 13:04 GMT
    Find Nodes?
      Voting Booth?