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 / chk_strings < prev    next >
Text File  |  1992-03-10  |  2KB  |  84 lines

  1. :
  2. #
  3. #  Usage: chk_strings filename
  4. #
  5. #  This will check pathnames inside executable files for writability,
  6. # using the "strings" command and egrep.
  7. #
  8. #  I have identified three basic types of strings containing paths to files:
  9. # 1)
  10. #    /path1/path2/file            /* standard */
  11. # 2) 
  12. #    '/path1/path2/file'        /* standard, in single quotes */
  13. # 3)
  14. #    :/path1/file1:/path2/file2        /* a path for searching */
  15. #
  16. #  For the first two, I simply test the writability; for the last, I
  17. # parse it into seperate paths and check each one in turn.
  18. #
  19. AWK=/bin/awk
  20. SED=/bin/sed
  21. EGREP=/usr/bin/egrep
  22. TEST=/bin/test
  23. ECHO=/bin/echo
  24. SORT=/usr/bin/sort
  25. STRINGS=/usr/ucb/strings
  26.  
  27. if test ! -s $STRINGS
  28.     then
  29.     exit 0
  30. fi
  31.  
  32. if test $# -eq 0
  33.     then
  34.     $ECHO "Usage: $0 file"
  35.     exit 2
  36. fi
  37.  
  38. while test 0 -ne $#
  39.     do
  40.     # $ECHO Checking $1...
  41.     if ./is_writable $1 ; then
  42.         $ECHO "Warning!  Root executed File $1 is _World_ writable!"
  43.         fi
  44.  
  45.     # get the first two types:
  46.  
  47. #   /path1/path2/file            /* standard */
  48. #   '/path1/path2/file'        /* standard, in single quotes */
  49. #   :/path1/file1:/path2/file2        /* a path for searching */
  50.  
  51. # test_files=`$STRINGS $1 | $EGREP "/.*/" | $AWK '{for (i=1;i<=NF;i++) 
  52. test_files=`$STRINGS $1|$SED -n -e 's/^.*[pP][aA][tT][hH]=//' -e '/\/.*\//p' |
  53.     $AWK '{for (i=1;i<=NF;i++) 
  54.     if ((res = substr($i,1,1))=="/") 
  55.         printf("%s\n",$i)
  56.     else if ((res != ":") && (res2=substr($i,2,1))=="/")
  57.         printf("%s\n",substr($i,2,length($i)-2))}
  58.     /:/ {
  59.         resk=substr($0, index($0,"=")+1, length($0) - index($0,"=")) \
  60.         split($0, path, ":");    \
  61.         for (j in path) printf("%s\n",path[j])}' | $SORT -u`
  62.  
  63.     shift
  64.     done
  65.  
  66.     for i in $test_files
  67.         do
  68.         if $TEST ! -d "$i" -o ! -f "$i" ; then
  69.             i=`$ECHO $i | $SED -e 's/[:;"]//g' -e "s/[']//g"`
  70.             if $TEST ! -f "$i" ; then
  71.                 continue
  72.                 fi
  73.             fi
  74.         
  75.         if $TEST -n "`$ECHO $i | $EGREP /tmp\|/dev/null\|/dev/tty\|/dev/printer\|/dev/console`" ; then
  76.             continue
  77.             fi
  78.         if ./is_writable "$i" ; then
  79.             $ECHO "Warning!  File $i (inside root executed file $1) is _World_ writable!"
  80.             fi
  81.         done
  82.  
  83. # end of script
  84.