文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一个简单的基于字典的解shadow的程序(perl版)

一个简单的基于字典的解shadow的程序(perl版)

时间:2006-03-15  来源:icymoon

#!/usr/bin/perl # $ID: icymoon@NKU
# $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=<SHADOW>;
        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 = <DIC>)
{
        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的并行版本,最终试图实现一个有限位穷举的东东出来?? 是后一个想法未必能实现。
相关阅读 更多 +
排行榜 更多 +
泡龙大闯关安卓版

泡龙大闯关安卓版

冒险解谜 下载
割草派对安卓版

割草派对安卓版

飞行射击 下载
堡垒攻防战安卓版

堡垒攻防战安卓版

飞行射击 下载