Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1834490
  • 博文数量: 283
  • 博客积分: 10141
  • 博客等级: 上将
  • 技术积分: 2931
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-21 14:33
文章分类

全部博文(283)

文章存档

2013年(2)

2012年(2)

2011年(17)

2010年(36)

2009年(17)

2008年(18)

2007年(66)

2006年(105)

2005年(20)

分类:

2006-03-15 16:35:49

#!/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的并行版本,最终试图实现一个有限位穷举的东东出来??
是后一个想法未必能实现。
阅读(1279) | 评论(0) | 转发(0) |
0

上一篇:今天证实了一则消息

下一篇:Crazy...

给主人留下些什么吧!~~