home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / pass_diff.chk < prev    next >
Text File  |  1992-03-10  |  3KB  |  90 lines

  1. :
  2. #
  3. #  pass_diff.chk
  4. #
  5. #   This shell script is a wrapper for the pass.chk password guessing
  6. # program.  What this does is save the password file from the last time
  7. # passwords were guessed, and then do a "diff" on this file and the
  8. # current password file.  This will prevent accounts being checked over
  9. # and over again for the same passwords, assuming the password has not
  10. # been changed.  If you have a fairly stable passwd environment, this
  11. # can save you quite a bit of CPU time...
  12. #
  13. #   Mechanism:  As explained above, it just diff's the password file
  14. # with the password file used last time you checked passwords, and then
  15. # calls pass.chk with any flags pass_diff.chk was called with on the
  16. # difference of the two files.
  17. #
  18. #  If the variable $YP is set to "YES", then it will use the the
  19. # yppassword file; it is not used automatically, because the idea is
  20. # that this can be, used on any password file, by changing the $etc_passwd
  21. # var.  See the next paragraph:
  22. #
  23. #   Warning!  This only checks for changes in the password file itself --
  24. # if you change the flags to pass.chk, or if you increase the size of
  25. # your dictionary, or whatever, this will not detect the change...
  26. # Also, if you want to use this wrapper with to check alternate pasword
  27. # files, don't use the "-P" flag (which normally specifies an alternate
  28. # password file); instead, change the $etc_passwd variable to whatever
  29. # passwd file you want to check.  Otherwise, this wrapper will force
  30. # /etc/passwd.
  31. #  Yellow Pages/NIS?
  32. YP=NO
  33.  
  34. # Locations of commands
  35. DIFF=/bin/diff
  36. CMP=/bin/cmp
  37. AWK=/bin/awk
  38. TEST=/bin/test
  39. CP=/bin/cp
  40. MV=/bin/mv
  41. RM=/bin/rm
  42. YPCAT=/usr/bin/ypcat
  43. TOUCH=/bin/touch
  44.  
  45. #
  46. # Important files:
  47. etc_passwd=/etc/passwd
  48. old_passwd=./old_passwd
  49. yp_pass=./yp.$$
  50. passwd_diff=passwd.diff
  51.  
  52. # password guessing program:
  53. pass_chk=./pass.chk
  54.  
  55. # make a dummy password file if it doesn't exist; changed touch to
  56. # echo, thanks to the sharp eye of jms@tardis.Tymnet.COM (Joe Smith)
  57. if $TEST ! -f $old_passwd ; then
  58.     $ECHO "dummy password file" > $old_passwd
  59.     fi
  60.  
  61. # if you use YP:
  62. if $TEST "$YP" = "YES" ; then
  63.     $YPCAT passwd > $yp_pass
  64.     etc_passwd=$yp_pass
  65.     fi
  66.  
  67. # has anything changed?  If so, check passwords, if not, leave quietly.
  68. if $TEST -n "`$CMP $etc_passwd $old_passwd`" ; then
  69.     #  If old_passwd file exists, use it, else just use the
  70.     # existing passwd file.
  71.     $DIFF $etc_passwd $old_passwd | $AWK -F: '/^[<]/{
  72.         split($1, user, " "); printf("%s",user[2]); \
  73.         for (i=2;i<=NF;i++){
  74.             printf(":%s", $i)}; print ""}' > $passwd_diff
  75.     $CP $etc_passwd $old_passwd
  76.  
  77.     #  Finally, crack them passwords and get rid of the diff file,
  78.     # but only if the file is !0 length.
  79.     if $TEST -s $passwd_diff ; then    
  80.         $pass_chk $* -P $passwd_diff
  81.     fi
  82.     $RM -f $passwd_diff
  83. fi
  84.  
  85. # kill off the evidence
  86. $RM -f $yp_pass
  87.  
  88. # end
  89.