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 / cops < prev    next >
Text File  |  1992-03-10  |  10KB  |  331 lines

  1. :
  2. #
  3. #  Usage cops [-a architecture] [-b bit_bucket] [-s secure_dir] \
  4. #             [-m user] [-f filter_file] [-dxvV]
  5. #
  6. #  -a specifies the architecure subdirectory you want to run in; you
  7. #     must run "make install" to install the appropriate binaries there
  8. #
  9. #  -b specifies the "bit bucket", where all the error messages go to.
  10. #
  11. #  -d will mail a report only if there have been changes since the
  12. #     last one.  Only makes sense with the -m flag or by setting the
  13. #     MMAIL var below.
  14. #
  15. #  -f specifies the cops filter file, which is used for filtering out
  16. #     extraneous warning message.
  17. #
  18. #  -m tells cops to mail the output to the user specified
  19. #
  20. #  -s tells cops where the secure directory is; mostly this is used by
  21. #     cops itself, when it is run with the -a flag; it will rerun itself
  22. #     with the -a flag's argument as an argument to this.
  23. #
  24. #  -x prints out the version number (running out of letters! :-))
  25. #
  26. #  -[vV] are the verbose flags.  Small "v" says print whatever program
  27. #     is running, when it is executed, in the output file; capital
  28. #     "V" says print everything to the screen.
  29. #
  30. #  Warning!  COPS will get confused if you use a command line arg that
  31. # expects an argument and you don't give it one.  Don't say I didn't
  32. # warn you :-)
  33. #
  34. # Overall --
  35. #
  36. #  Cops will change into the $SECURE/architecture directory, ensure all
  37. # the security programs (listed below) indeed do exist, and run all of the
  38. # security programs.  If any of the programs find any security problems, it
  39. # either sends mail to everyone in the $SECURE_USERS list, or saves the results
  40. # in a file $SECURE/architecture/hostname.  It then destroys all temporary
  41. # files, and exits the program.  Programs that are run (besides this one):
  42. #
  43. #    root.chk    dev.chk        group.chk
  44. #    home.chk     rc.chk        passwd.chk
  45. #    is_able.chk    pass.chk     user.chk
  46. #    cron.chk    misc.chk    ftp.chk
  47. #
  48. # The U-kuang system runs these additional programs:
  49. #    init_kuang    kuang        addto
  50. #    clearfiles    filewriters    members
  51.  
  52. #
  53. #  If this is changed to "NO", the report that cops creates
  54. # will not be deleted and the results will not be mailed to anyone.
  55. MMAIL=NO
  56.  
  57. #
  58. # Foreign language users can change this (thanks to Wolfgang Denk!):
  59. LANGUAGE=english
  60. export LANGUAGE
  61.  
  62. #
  63. #  If this is changed to "YES", then the report will only be mailed
  64. # if it detects a difference between the last report and this one.
  65. # Note that this makes no sense unless the mail is set to "YES" as well.
  66. ONLY_DIFF=YES
  67.  
  68. #
  69. #  Do you want to run suid.chk within cops?
  70. RUN_SUID=NO
  71.  
  72. # Where is everyone?
  73. ECHO=/bin/echo
  74. TEST=/bin/test
  75. RM=/bin/rm
  76. CAT=/bin/cat
  77. MAIL=/bin/mail
  78. DATE=/bin/date
  79. CHMOD=/bin/chmod
  80. AWK=/bin/awk
  81. SED=/bin/sed
  82. MV=/bin/mv
  83. MKDIR=/bin/mkdir
  84.  
  85. # send errors and verbosity to...
  86. BIT_BUCKET=/dev/null
  87. # send verbose messages to...
  88. VERBUCKET=/dev/null
  89.  
  90. ######################
  91. #  Change these lines!
  92. ######################
  93. SECURE=/usr/foo/bar
  94. SECURE_USERS="foo@bar.edu"
  95. ######################
  96.  
  97. # arg stuff:
  98. while $TEST $# != 0
  99.     do      case "$1" in
  100.         -a)     arch=$2 ; SECURE=$SECURE"/"$arch ; shift ;;
  101.         -b)    BIT_BUCKET=$2 ; flags=$flags" -b $2" ; shift ;;
  102.         -d)    ONLY_DIFF=YES ;;
  103.     -f)    filter=yes ; cops_filter=$2 ; shift ;;
  104.         -m)    SECURE_USERS=$2 ; flags=$flags" -m $2" ; MMAIL=YES ; shift ;;
  105.         -s)     SECURE=$2 ; shift ;;
  106.         -v)    verbose=yes ; v="-v" ; flags=$flags" -v" ;;
  107.         -V)    verbose=yes ; VERBUCKET="/dev/tty" ; RESULT="/dev/tty" ; flags=$flags" -V" ;;
  108.         -x)     $AWK '{print "Version 1.0" $NF}' ./patchlevel.h ; exit 0 ;;
  109.         *)      $ECHO Usage $0 [-a arch] [-b bit_bucket] [-s sec_dir] [-f filter] [-m user] [-dvVx] ; exit ;;
  110.         esac
  111.         shift
  112.     done
  113.  
  114. if $TEST "$filter" = "yes" -a ! -s "$cops_filter" ; then
  115.     $ECHO "Can't open filter: $cops_filter"
  116.     exit 1
  117.     fi
  118.  
  119. #  architecture?  change to that dir, and execute cops there:
  120. if $TEST -n "$arch" ; then
  121.     if $TEST ! -d "$SECURE" ; then
  122.          $ECHO Architecture directory $1 does not exist
  123.          exit 1
  124.          fi
  125.     $CHMOD 700 $SECURE
  126.      cd $SECURE
  127.      ./cops -s "." $flags
  128.      exit
  129.      fi
  130.  
  131. SECURE_PROGRAMS="root.chk dev.chk is_able.chk group.chk \
  132.                  home.chk rc.chk passwd.chk pass.chk misc.chk ftp.chk \
  133.          cron.chk user.chk init_kuang kuang addto \
  134.          clearfiles filewriters members is_able bug.chk"
  135.  
  136. if $TEST ! -d "$SECURE" ; then
  137.     $ECHO "Error -- Security directory $SECURE doesn't exist"
  138.     exit 1
  139. fi
  140.  
  141. $CHMOD 700 $SECURE
  142. cd $SECURE
  143.  
  144. for i in $SECURE_PROGRAMS
  145.     do
  146.     if $TEST ! -s "$i" ; then
  147.         $ECHO "Error -- Security program $SECURE/$i doesn't exist"
  148.         exit 1
  149.     fi
  150. done
  151.  
  152. # results go:
  153. if $TEST -z "$RESULT" ; then
  154.     RESULT=$SECURE/result.$$
  155.     fi
  156. if $TEST x"-v" = "x$v" ; then
  157.     VERBUCKET=$RESULT
  158.     fi
  159.  
  160. if $TEST -n "$verbose" ; then
  161.     $ECHO "**** root.chk ****" > $VERBUCKET ; fi
  162. $SECURE/root.chk        >>    $RESULT 2>  $BIT_BUCKET
  163. if $TEST -n "$verbose" ; then 
  164.     $ECHO "**** dev.chk ****" >> $VERBUCKET ; fi
  165. $SECURE/dev.chk            >>    $RESULT 2>> $BIT_BUCKET
  166. if $TEST -n "$verbose" ; then 
  167.     $ECHO "**** is_able.chk ****" >> $VERBUCKET ; fi
  168. $SECURE/is_able.chk        >>    $RESULT 2>> $BIT_BUCKET
  169. if $TEST -n "$verbose" ; then 
  170.     $ECHO "**** rc.chk ****" >> $VERBUCKET ; fi
  171. $SECURE/rc.chk            >>    $RESULT 2>> $BIT_BUCKET
  172. if $TEST -n "$verbose" ; then 
  173.     $ECHO "**** cron.chk ****" >> $VERBUCKET ; fi
  174. $SECURE/cron.chk        >>    $RESULT 2>> $BIT_BUCKET
  175. if $TEST -n "$verbose" ; then 
  176.     $ECHO "**** group.chk ****" >> $VERBUCKET ; fi
  177. $SECURE/group.chk        >>    $RESULT 2>> $BIT_BUCKET
  178. if $TEST -n "$verbose" ; then 
  179.     $ECHO "**** home.chk ****" >> $VERBUCKET ; fi
  180. $SECURE/home.chk        >>    $RESULT 2>> $BIT_BUCKET
  181. if $TEST -n "$verbose" ; then 
  182.     $ECHO "**** passwd.chk ****" >> $VERBUCKET ; fi
  183. $SECURE/passwd.chk        >>    $RESULT 2>> $BIT_BUCKET
  184. if $TEST -n "$verbose" ; then 
  185.     $ECHO "**** user.chk ****" >> $VERBUCKET ; fi
  186. $SECURE/user.chk        >>    $RESULT 2>> $BIT_BUCKET
  187. if $TEST -n "$verbose" ; then 
  188.     $ECHO "**** misc.chk ****" >> $VERBUCKET ; fi
  189. $SECURE/misc.chk        >>    $RESULT 2>> $BIT_BUCKET
  190.  
  191. # use the -a option for checking anon-ftp; e.g., "$SECURE/ftp.chk -a"
  192. if $TEST -n "$verbose" ; then 
  193.     $ECHO "**** ftp.chk ****" >> $VERBUCKET ; fi
  194. $SECURE/ftp.chk            >>    $RESULT 2>> $BIT_BUCKET
  195.  
  196. #   Optional -- use "pass_diff.chk", instead of "pass.chk" to make your
  197. # life easier!
  198. if $TEST -n "$verbose" ; then 
  199.     $ECHO "**** pass.chk ****" >> $VERBUCKET ; fi
  200. $SECURE/pass.chk -w ./pass.words -b -g -s -c -d -n >> $RESULT 2>> $BIT_BUCKET
  201. # $SECURE/pass_diff.chk        >>    $RESULT 2>> $BIT_BUCKET
  202. # try it with "-w ./pass.words -b -g -s -c -d -n" flags....
  203.  
  204. if $TEST -n "$verbose" ; then 
  205.     $ECHO "**** kuang ****" >> $VERBUCKET ; fi
  206. #   Optional -- use "kuang.pl", instead of "kuang", if you have perl
  207. # installed on your system, for extra speed and functionality:
  208. $SECURE/kuang            >>    $BIT_BUCKET 2>> $BIT_BUCKET
  209. # $SECURE/kuang.pl        >>    $BIT_BUCKET 2>> $BIT_BUCKET
  210.  
  211. # kuang puts it's results in a file called "Success"; check it out:
  212. # if $TEST -s "$SECURE/Success" ; then
  213. #     $CAT $SECURE/Success >> $RESULT
  214. # fi
  215. # $RM -f $SECURE/Success
  216.  
  217. # Optional!  Should use this interactively, with a secret key!
  218. # if $TEST -n "$verbose" ; then 
  219. #     $ECHO "**** crc.chk ****" >> $VERBUCKET ; fi
  220. # $SECURE/crc.chk    2>> $BIT_BUCKET
  221.  
  222. # crc.chk puts it's results in a file called crc.results; uncomment
  223. # this as well:
  224. # if $TEST -s "$SECURE/crc_results" ; then
  225. #     $CAT $SECURE/crc_results >> $RESULT
  226. # fi
  227. # $RM -f $SECURE/crc_results
  228.  
  229. #
  230. #  Want to run suid check from within cops?  (Results get mailed separately)
  231. # if $TEST "$RUN_SUID" = "YES" ; then
  232. #    $SECURE/suid.chk > /dev/null 2>&1
  233. # fi
  234.  
  235. #
  236. # Bug.chk?  New stuff...
  237. if $TEST -n "$verbose" ; then 
  238.     $ECHO "**** bug.chk ****" >> $VERBUCKET ; fi
  239. $SECURE/bug.chk        >>    $RESULT 2>> $BIT_BUCKET
  240.  
  241. #
  242. #
  243. #  Filter results, if used
  244. if $TEST "$filter" = "yes" ; then
  245.     $AWK -f $cops_filter $RESULT > $RESULT".FILT"
  246.     # if no results are there, don't worry about printing a report...
  247.     if $TEST ! -s $RESULT".FILT" ; then
  248.         $RM -f $RESULT
  249.         exit 0
  250.         fi
  251.     # else, move the filtered results in the old result location:
  252.     $MV $RESULT".FILT" $RESULT
  253.     fi
  254.  
  255. #
  256. #   Save or Mail the final report to $SECURE_USERS and remove the evidence.
  257. #
  258. #  (Thanks to Ian Darwin for the next nifty idea!)
  259. #  If the result is not mailed, it will be saved in a directory with the
  260. # same name as the host, in a file with the name:
  261. #
  262. #  Year_Month_Day  (for example: $SECURE/ucbvax/1999_Dec_31 )
  263. #
  264. if $TEST -s "$RESULT" ; then
  265.     # want to put the date and hostname at top; use tmp file: report.$$
  266.     REPORT=$SECURE/report.$$
  267.  
  268.     # name of final resting place:
  269.     NAME=`$DATE | $AWK '{print $NF"_"$2"_"$3}'`
  270.     #
  271.     if $TEST -s /bin/hostname ; then
  272.         HOSTNAME=`/bin/hostname`
  273.     elif $TEST -s /bin/uname ; then
  274.         HOSTNAME=`/bin/uname -n`
  275.     elif $TEST -s /usr/bin/uuname ; then
  276.         HOSTNAME=`/usr/bin/uuname -l`
  277.         fi
  278.     if $TEST -z "$HOSTNAME" ; then
  279.         HOSTNAME="foobar"
  280.         fi
  281.     HOST=`$ECHO $HOSTNAME | $SED 's/[.].*$//'`
  282.  
  283.     $ECHO                                   >  $REPORT
  284.     $ECHO ATTENTION:            >> $REPORT
  285.     $ECHO "Security Report for "`$DATE`    >> $REPORT
  286.  
  287.     $ECHO "from host $HOSTNAME"        >> $REPORT
  288.     $ECHO                    >> $REPORT
  289.     $ECHO                    >> $REPORT
  290.     $CAT $SECURE/result.$$            >> $REPORT
  291.  
  292.  
  293.     #   figure out where all the old reports are kept, or where the new
  294.     # one should be kept; make directories if needed...
  295.     if $TEST -d "$SECURE/$HOST" -a "$MMAIL" = "YES" ; then
  296.         if $TEST "$ONLY_DIFF" = "YES" ; then
  297.             if $TEST -n "`./res_diff $SECURE/$HOST $REPORT`" ; then
  298.                 $MAIL $SECURE_USERS < $REPORT
  299.                 $MV $REPORT $SECURE/$HOST/$NAME
  300.                 fi
  301.         else
  302.             $MAIL $SECURE_USERS < $REPORT
  303.         fi
  304.         $RM -f $REPORT
  305.     elif $TEST ! -d "$SECURE/$HOST" -a "$MMAIL" = "YES" ; then
  306.         $MAIL $SECURE_USERS < $REPORT
  307.         if $TEST -n "$HOST" ; then
  308.             $MKDIR $SECURE/$HOST 2> /dev/null
  309.             $MV $REPORT $SECURE/$HOST/$NAME
  310.         else
  311.             $MV $REPORT $NAME
  312.             fi
  313.     else
  314.         #  Either saving it to a hostname, in which case move to
  315.         # the hostname directory, or just move result to
  316.         # the current dir
  317.  
  318.         if $TEST -n "$HOST" ; then
  319.             $MKDIR $SECURE/$HOST 2> /dev/null
  320.             $MV $REPORT $SECURE/$HOST/$NAME
  321.         else
  322.             $MV $REPORT $NAME
  323.             fi
  324.     fi
  325. fi
  326.  
  327. $RM -f $SECURE/result.$$
  328.  
  329. #  end it all....
  330. exit 0
  331.