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 / misc.chk < prev    next >
Text File  |  1992-03-10  |  4KB  |  170 lines

  1. :
  2. #
  3. #  Usage: misc.chk
  4. #
  5. #  This shell script checks a variety of miscellaneous potential
  6. # security problems that really don't belong anywhere else.
  7. #
  8. #  Right now this looks for to see if tftp & rexd are enabled,
  9. # to check if the uudecode alias is in the mail alias file and
  10. # not commented out, and if uudecode can create a SUID file.
  11. #
  12. #  Mechanism:  tftp.chk will try to get /etc/motd from the localhost.
  13. # Not much too it; just connect and try to get it.  For rexd, just
  14. # look in the /etc/{inetd.conf,servers} file to see if it's enabled (e.g.,
  15. # not commented out).
  16. #
  17. #  Warning:  it may take a minute or so to complete the test, since tftp
  18. # might take a while to get the test file, or it may take a while to time
  19. # out the connection (which is what usually happens if the test fails.)
  20.  
  21. #
  22. #  Location of stuff:
  23. TFTP=/usr/ucb/tftp
  24. GREP=/bin/grep
  25. ECHO=/bin/echo
  26. TEST=/bin/test
  27. AWK=/bin/awk
  28. SED=/bin/sed
  29. RM=/bin/rm
  30. UUDECODE=/usr/bin/uudecode
  31. CMP=/bin/cmp
  32.  
  33. # shells to look for in inetd.conf:
  34. all_shells="/bin/sh /bin/csh /bin/ksh /usr/local/bin/tcsh /usr/local/bin/bash"
  35. for i in $all_shells ; do
  36.     if $TEST -f $i ; then
  37.         shells=$shells" "$i
  38.         fi
  39.     done
  40.  
  41. # look for uudecode alias in $aliases
  42. aliases=/usr/lib/aliases
  43. uu=decode
  44.  
  45. # look for rexd in $inetd; this file could be "/etc/servers", too!
  46. if $TEST -f "/etc/inetd.conf" ; then
  47.     inetd="/etc/inetd.conf"
  48. elif $TEST -f "/usr/etc/inetd.conf" ; then
  49.     inetd="/usr/etc/inetd.conf"
  50. elif $TEST -f "/etc/servers" ; then
  51.     inetd="/etc/servers"
  52.     fi
  53. # else give up!
  54. rexd=rexd
  55.  
  56. # tmp and target file
  57. TARGET=/etc/motd
  58. TMP=./tmp.$$
  59.  
  60. #  Read from $inetd to see if daemons are running.
  61. # Comments are lines starting with a "#", so ignore.
  62. # Checking for rexd:
  63. #
  64. # If sysV based
  65. if $TEST "$inetd" = "/etc/servers" ; then
  66.     if $TEST -n "`$AWK '{if($1~/^#/)next;else if(\"'$rexd'\"==$3)print}' $inetd`" ; then
  67.         $ECHO Warning!  $rexd is enabled in $inetd!
  68.         fi
  69.     # 3rd field is program?
  70.     files=`$AWK '{if ($1 ~ /^#/) next; else print $3}' $inetd`
  71.  
  72. # else BSD (e.g. the right way :-))
  73. else
  74.     if $TEST -n "`$AWK '{if ($1 ~ /^#/) next; else if (\"'$rexd'\" == $NF) print}' $inetd`" ; then
  75.         $ECHO Warning!  $rexd is enabled in $inetd!
  76.         fi
  77.     # 6th field is program:
  78.     files=`$AWK '{if ($1 ~ /^#/) next; else print $6}' $inetd`
  79.     fi
  80.  
  81. #   Check to see if anything started $inetd is writable or is
  82. # the same size as a user shell:
  83. if $TEST -n "$files" ; then
  84.     for i in $files ; do
  85.         # use chk_strings if paranoid; e.g. "chk_strings $i"
  86.         if $TEST -r $i ; then
  87.             # ./is_able $i w w
  88.             if ./is_writable $i ; then
  89.                 $ECHO "Warning!  File $i (in $inetd) is _World_ writable!"
  90.                 fi
  91.  
  92.             for shell in $shells ; do
  93.                 if $TEST -z "`$CMP $shell $i 2> /dev/null`"
  94.                     then
  95.                     $ECHO Warning!  Shell $shell is \(hidden\?\) in $inetd as $i!
  96.                     fi
  97.                 done
  98.             fi
  99.         done
  100.     fi
  101.  
  102. # Checking for uudecode alias:
  103. res=`$SED -n '/^[^#]*|*"'$uu'"/p' $aliases`
  104.  
  105. if $TEST -n "$res"
  106.     then
  107.     $ECHO Warning!  $uu is enabled in $aliases!
  108.     fi
  109.  
  110. if $TEST -f $TMP ; then
  111. #    $ECHO "You've got to be kidding.  Tmp file $TMP already exists!"
  112.     exit 1
  113.     fi
  114.  
  115.  
  116. # uucode stuff -- thanks to pete shipley...
  117. $UUDECODE << EOD_
  118. begin 4755 ./foobar.$$
  119.  
  120. end
  121. EOD_
  122.  
  123. if $TEST -n "`./is_able $UUDECODE s s`" ; then
  124.     $ECHO Warning!  $UUDECODE is SUID!
  125. fi
  126.  
  127. if $TEST -n "`./is_able ./foobar.$$ s s`"; then
  128.     $ECHO Warning!  $UUDECODE creates setuid files!
  129. fi
  130.  
  131. $RM -f ./foobar.$$
  132.  
  133. #  The rest is all for tftp stuff:
  134. #
  135. #   Get the local hostname...
  136. if $TEST -s /bin/hostname ; then
  137.     HOSTNAME=`/bin/hostname`
  138. elif $TEST -s /bin/uname ; then
  139.     HOSTNAME=`/bin/uname -n`
  140. elif $TEST -s /usr/bin/uuname ; then
  141.     HOSTNAME=`/usr/bin/uuname -l`
  142.     fi
  143. if $TEST -z "$HOSTNAME" ; then
  144.     HOSTNAME="foobar"
  145.     fi
  146.  
  147. if $TEST -z "$HOSTNAME" ; then
  148. #    $ECHO "Unable to find hostname"
  149.     exit 1
  150.     fi
  151.  
  152. #   Do the dirty work -- check tftp for the localhost, if it was found;
  153. # this might take a bit, since tftp might have to time out.
  154. {
  155. $TFTP << _XXX_
  156. connect $HOSTNAME
  157. get $TARGET $TMP
  158. quit
  159. _XXX_
  160. }  > /dev/null 2> /dev/null
  161.  
  162. if $TEST -s $TMP ; then
  163.     $ECHO "Warning!  tftp is enabled on $HOSTNAME!"
  164.     fi
  165.  
  166. $RM -f $TMP
  167.  
  168. exit 0
  169. # end of script
  170.