InBlock.gif   1.  #!/usr/bin/perl  
InBlock.gif   2.  
InBlock.gif   3. # crack.pl
InBlock.gif   4.  
InBlock.gif   5. use English;  
InBlock.gif   6. use FileHandle;  
InBlock.gif   7.  
InBlock.gif   8. #Set ALL USER s pictures  
InBlock.gif   9. #$FORMAT_NAME = "AUSER";  
InBlock.gif  10. #$FORMAT_TOP_NAME = "AUSER_TOP";  
InBlock.gif  11. $~ = "AUSER";  
InBlock.gif  12. $^ = "AUSER_TOP";  
InBlock.gif  13.  
InBlock.gif  14. # Step 1:  
InBlock.gif  15. # Get all account list,and genarate a report.  
InBlock.gif  16. # In the mean time get system users names and  
InBlock.gif  17. # passwords,get ready for cracking.  
InBlock.gif  18.  
InBlock.gif  19. my $allcount = 0;  
InBlock.gif  20. my $syscount = 0;  
InBlock.gif  21. my $lockcount = 0;  
InBlock.gif  22. my $unknown = 0;  
InBlock.gif  23. my @encrypt = ();  
InBlock.gif  24. my @users = ();  
InBlock.gif  25. while (($account,$passwd,$uid,$gid,$quota,$coment,$gcos,$home,$shell) = getpwent())  
InBlock.gif  26. {  
InBlock.gif  27.         write;  
InBlock.gif  28.         $allcount ++;  
InBlock.gif  29.         if ($passwd =~ /\$/){  
InBlock.gif  30.                $users[$syscount] = $account;  
InBlock.gif  31.                $encrypt[$syscount] = $passwd;  
InBlock.gif  32.                $syscount++;  
InBlock.gif  33.         }elsif($passwd =~ /\*/ || $passwd =~ /\!/ || $passwd =~ /x/){  
InBlock.gif  34.                $lockcount++;  
InBlock.gif  35.         }  
InBlock.gif  36. }  
InBlock.gif  37. $unknown = $allcount - $syscount - $lockcount;  
InBlock.gif  38.  
InBlock.gif  39. # Print table Header.  
InBlock.gif  40. format AUSER_TOP =  
InBlock.gif  41. =========================================================================================  
InBlock.gif  42.     Name        Password                          UID    GID  Home                 Shell  
InBlock.gif  43. =========================================================================================  
InBlock.gif  44. .  
InBlock.gif  45. # Print table Body.  
InBlock.gif  46. format AUSER =  
InBlock.gif  47. @<<<@<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<@<<<<<@<<<<<@<<<<<<<<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<  
InBlock.gif  48. $allcount+1,$account,$passwd,$uid,$gid,$home,$shell  
InBlock.gif  49. .  
InBlock.gif  50. # Print some statistics on footer.  
InBlock.gif  51. print "\n=====================================================================================\n";  
InBlock.gif  52. print $allcount. " accounts, ".$syscount. " systems user(s), ".$lockcount. "accounts locked, ".$unknown. " accounts unknown.\n";  
InBlock.gif  53. print "=====================================================================================\n";  
InBlock.gif  54.  
InBlock.gif  55. # Step 1 ends...  
InBlock.gif  56.  
InBlock.gif  57. # Step 2:  
InBlock.gif  58. # Get all system user salt.  
InBlock.gif  59.  
InBlock.gif  60. my $i = 0;  
InBlock.gif  61. my $escstring;  
InBlock.gif  62. my @salt = ();  
InBlock.gif  63. foreach $user(@users){  
InBlock.gif  64.         $escstring = (getpwnam($user))[1];  
InBlock.gif  65.         $salt[$i] = substr($escstring,0,12);  
InBlock.gif  66.         $i++;  
InBlock.gif  67. }  
InBlock.gif  68. # Step 2 ends...  
InBlock.gif  69.  
InBlock.gif  70. # Step 3:  
InBlock.gif  71. # Read password from list,crypt them with  
InBlock.gif  72. # each salt.Compare the crypted password from list  
InBlock.gif  73. # with /etc/shadow  
InBlock.gif  74.  
InBlock.gif  75. my $word_count = 0;  
InBlock.gif  76. my $j = 0;  
InBlock.gif  77. my $n = 0;  
InBlock.gif  78. my @word = ();  
InBlock.gif  79. my $encstring;  
InBlock.gif  80. my @baduser = ();  
InBlock.gif  81. my @badpasswd = ();  
InBlock.gif  82. # Open file to read word list.  
InBlock.gif  83. open (DICT, "password.lst") or die "file error:$!\n";  
InBlock.gif  84. @words = <DICT>;  
InBlock.gif  85. chomp @words;  
InBlock.gif  86. $word_count = @words;  
InBlock.gif  87. # Crack begins....  
InBlock.gif  88. for ($i = 0; $i < $syscount; $i++){ # Crack The $i`th user's password.  
InBlock.gif  89.         print "Testing $users[$i] password\n";  
InBlock.gif  90.         for ($j = 0; $j < $word_count; $j++){  
InBlock.gif  91.                 $encstring = crypt($words[$j],$salt[$i]);  
InBlock.gif  92.                 if ($encstring eq $encrypt[$i]){  
InBlock.gif  93.                         $baduser[$n] = $users[$i];  
InBlock.gif  94.                         $badpasswd[$n] = $words[$j];  
InBlock.gif  95.                         $n++;  
InBlock.gif  96.                         print "Password cracked.\n";  
InBlock.gif  97.                         last;  
InBlock.gif  98.                 }  
InBlock.gif  99.         } # Continue the crack process.  
InBlock.gif 100. }  
InBlock.gif 101. # Crack ends.  
InBlock.gif 102.  
InBlock.gif 103. # Display result.  
InBlock.gif 104. if ($n != 0){  
InBlock.gif 105.         print "$n bad account(s).\n";  
InBlock.gif 106.         print "The following is list:\n";  
InBlock.gif 107.         for ($i = 0; $i < $n; $i++){  
InBlock.gif 108.                 print "$baduser[$i] : $badpasswd[$i]\n";  
InBlock.gif 109.         }  
InBlock.gif 110.         print "The password(s) is(are) based on dictory,please change it immdiately.\n";  
InBlock.gif 111. } else{  
InBlock.gif 112.         print "No password cracked";  
InBlock.gif 113. }