in reply to
Double loop?
Please don't delete code from your original question or change it otherwise without stating so.
When you have problems formatting content for PM please see Writeup Formatting Tips as frodo72 already stated.
Referring to offsite code (on your own server) isn't a good idea either, you would probably not keep it there forever, and other monks will get a different picture of this thread when you're changing the OP afterwards.
In fact, you changed even your code on your server, taking snippets from my last reply and now it looks like I just took out a few spaces and posted a neater version of yours.
I thought in posting a refactored, tidier and more compact version you could compare your efforts with someone elses try.
In your current version of your offsite code (http://as.switch2hosting.com/perl.txt) you took snippets and ideas from our replies and included following statement now:
You are free to customize this script as you wish, but do not
redistribute without written permission from TipoNaSoft.
Huh?
Is it really so special that one needs a written permission from you?
I'm adding your original code now below just that I don't stand here as a fool.
Original posting (OP) from
RayQ:
#!/usr/bin/perl -T
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 $dictionary = $opt_d;
my $hash = $opt_h;
my $mode = $opt_m;
my $help = $opt_a;
my $passfile = $opt_f;
if($mode == ""){$mode = "md5";}
my $algo = $mode;
my %length;
$length{'md5'} = 32;
$length{'sha1'} = 40;
$length{'sha224'} = 56;
$length{'sha256'} = 64;
$length{'sha384'} = 96;
$length{'sha512'} = 128;
if($help && (!$hash && !$passfile) || (!$hash && !$passfile)){help();e
+xit(1);}
&main;
sub main
{
if($dictionary eq "")
{
$dictionary = "/usr/share/dict/words";
}
if($hash)
{
if(length($hash) != $length{$algo})
{
print STDERR "Invalid hash length!\nLength for an $algo ha
+sh should be $length{$algo}!\nSee $0 -a for details.\n";
exit(1);
}
print "Cracking....\n";
}
if($passfile eq "")
{
open DICT, $dictionary or die("
Could not open dictionary file : $dictionary.
Please make sure the file exists and you have read access
+to it.
Error occured");
while(<DICT>)
{
chomp($_);
if(hash($algo, $_) eq $hash)
{
print "\nMatch found!\nPlainText : " . $_ . "\n\n";
exit(0);
}
}
}
else
{
open PASS, $passfile or die("
Could not open password file : $passfile.
Please make sure the file exists and you have read access
+to it.
Error occured");
print "Cracking....\n";
while(<PASS>)
{
open DICT, $dictionary or die("
Could not open dictionary file : $dictionary.
Please make sure the file exists and you have read acc
+ess to it.
Error occured");
my $curpass = $_;
chomp($curpass);
chop($curpass);
while(<DICT>)
{
my $word = $_;
chomp($word);
chop($word);
#print $number."\n";
if(hash($algo, $word) eq $curpass)
{
print "$curpass :: $word\n";
close(DICT);
}
}
}
close(PASS);
}
exit(1);
}
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";
}
sub hash # hash($algo, $_)
{
if($_[0] eq "md5")
{
return md5_hex($_[1]);
}
elsif($_[0] eq "sha1")
{
return sha1_hex($_[1]);
}
elsif($_[0] eq "sha224")
{
return sha224_hex($_[1]);
}
elsif($_[0] eq "sha256")
{
return sha256_hex($_[1]);
}
elsif($_[0] eq "sha384")
{
return sha384_hex($_[1]);
}
elsif($_[0] eq "sha512")
{
return sha512_hex($_[1]);
}
}