#!/usr/bin/perl
# $ID:
# $Date: 2005.03.14.
# Just a practice
use Getopt::Std;
use POSIX;
my $shadow_file, $dic_file;
my $line;
my %usr_pass;
my @tmp_info;
sub error_exit($)
{
print "$_[0]\n";
exit 1;
}
sub show_usage()
{
print "Usage: $0 -s shadow_file -d dictionary_file\n";
exit 2;
}
sub get_opts()
{
my %opts;
getopts('hs:d:', \%opts);
my $count_opt = keys %opts;
if($count_opt == 0 || defined($opts{'h'}))
{
show_usage();
}
if(not defined($opts{'s'}))
{
print "You must give me a file like shadow with -s\n";
show_usage();
}
else
{
$shdow_file=$opts{'s'};
}
if(not defined($opts{'d'}))
{
print "You should give me a dictionary file with -p\n";
show_usage();
}
else
{
$dic_file=$opts{'d'};
}
}
get_opts();
#get information of username and crypted passwd.
open SHADOW,"< $shdow_file" or die("Can not open the shadow_file!");
while(1)
{
$line=;
chomp($line);
if(not defined($line))
{
last;
}
if($line =~ /^[0-9a-zA-Z_]+:\$.*:.*/)
{
@tmp_info = split(/:/, $line);
$usr_pass{$tmp_info[0]} = $tmp_info[1];
print "$tmp_info[0], $usr_pass{$tmp_info[0]}\n";
}
}
close(SHADOW);
open DIC,"< $dic_file" or die("Can not open the shadow_file!");
while($line = )
{
if(not defined($line))
{
last;
}
chomp($line);
foreach my $cur_usr(sort keys %usr_pass)
{
my @salt_tmp = split(/\$/,$usr_pass{$cur_usr});
my $salt = "\$1\$$salt_tmp[2]\$";
if("$usr_pass{$cur_usr}" eq crypt("$line","$salt"))
{
print "$cur_usr $line\n";
}
}
}
下一步的计划是写个C的相同功能的,然后再改成MPI的并行版本,最终试图实现一个有限位穷举的东东出来??
是后一个想法未必能实现。
阅读(1307) | 评论(0) | 转发(0) |