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 / kuang < prev    next >
Text File  |  1992-03-10  |  6KB  |  205 lines

  1. :
  2. # /* Copyright 1985 Robert W. Baldwin */
  3. # /* Copyright 1986 Robert W. Baldwin */
  4. #
  5. # Jan 1990, Ported to bourne shell from Csh.  Dan Farmer
  6. #
  7. #   Took out some comments, combined four of Bob's shell
  8. # scripts into one (the target script remains separate for
  9. # easy editing of targets.)  More or less a straight line
  10. # for line translation; a rewrite that goes for speed will
  11. # come later.  Maybe just rewrite it in C.  Yeah, that's it....
  12.  
  13. ###############################################
  14. # Kuang: Rule based computer security checker.
  15. ###############################################
  16.  
  17. # commands used....
  18. SH=/bin/sh
  19. MV=/bin/mv
  20. TEST=/bin/test
  21. ECHO=/bin/echo
  22. AWK=/bin/awk
  23. RM=/bin/rm
  24.  
  25. # Initialization.
  26. $SH ./init_kuang
  27.  
  28. # Main loop
  29. #
  30. $ECHO Starting main loop                        #>/dev/tty
  31. while $TEST -f uids.n -o -f gids.n -o -f files.n
  32.     do
  33.     if $TEST -f uids.n ; then
  34.         $MV uids.n uids.x
  35.  
  36. # Process a list of uids from stdin.
  37. # Usage: douids username comments
  38.     $ECHO Called douids                        #>/dev/tty
  39.     i=1
  40.     while $TEST "1"
  41.         do
  42.         nextuid=`$AWK '{if (NR=="'$i'") print $0}' uids.x`
  43.         i=`expr $i + 1`
  44.  
  45.         if $TEST -z "$nextuid"  ; then
  46.             break;
  47.         fi
  48.  
  49.             user=`$ECHO $nextuid | $AWK '{print $1}'`
  50.  
  51.         $ECHO "   " User $user                    #>/dev/tty
  52.  
  53. # Rules mapping uids to files.
  54. #
  55.         next=`$ECHO $nextuid | $AWK '{for (i=2;i<=NF;i++) printf("%s ", $i)}'`
  56.         ./addto files /etc/passwd replace grant $user $next
  57.         ./addto files /usr/lib/aliases replace trojan $user $next
  58.  
  59. #   hsh = home sweet home = home directory of $user
  60.         hsh=`./tilde $user`
  61.  
  62.         if $TEST -f $hsh/.rhosts ;  then
  63.             ./addto files $hsh/.rhosts write grant $user $next
  64.         fi
  65.  
  66.         if $TEST -f $hsh/.login ;  then
  67.             ./addto files $hsh/.login replace trojan $user $next
  68.         fi
  69.  
  70.         if $TEST -f $hsh/.cshrc ;  then
  71.             ./addto files $hsh/.cshrc replace trojan $user $next
  72.         fi
  73.  
  74.         if $TEST -f $hsh/.profile ;  then
  75.             ./addto files $hsh/.profile replace trojan $user $next
  76.         fi
  77.  
  78.         if $TEST "$user" = "root" ;  then
  79.         if $TEST -f /usr/lib/crontab ; then
  80.                ./addto files /usr/lib/crontab replace create supershell $next
  81.         else
  82.                ./addto files /usr/spool/cron/crontabs replace create supershell $next
  83.         fi
  84.             ./addto files /etc/rc replace trojan $user $next
  85.             ./addto files /etc/rc.local replace trojan $user $next
  86.         fi
  87.  
  88.         if $TEST "$user" != "root" ;  then
  89.             ./addto files /etc/hosts.equiv replace allow rlogin $next
  90.         fi
  91.  
  92.         if $TEST "$user" != "root" -a -f /etc/hosts.equiv -a -s /etc/hosts.equiv 
  93.             then
  94.             ./addto files /etc/hosts replace fake HostAddress $next
  95.         fi
  96.  
  97.     done
  98. fi
  99.  
  100.     if $TEST -f gids.n ; then
  101.        $MV gids.n gids.x
  102.  
  103.     $ECHO Called dogids                        #>/dev/tty
  104.     i=1
  105.     while $TEST "1"
  106.         do
  107.         nextgid=`$AWK '{if (NR=="'$i'") print $0}' gids.x`
  108.         i=`expr $i + 1`
  109.  
  110.         if $TEST -z "$nextgid" ; then
  111.             break;
  112.         fi
  113.  
  114.         group=`$ECHO $nextgid | $AWK '{print $1}'`
  115.         $ECHO "   " Group $group                    #>/dev/tty
  116.  
  117. # Rules mapping gids to uids.
  118. #
  119.         next=`$ECHO $nextgid | $AWK '{for (i=2;i<=NF;i++) printf("%s ", $i)}'`
  120.         use=`./members $group`
  121.         for user in $use
  122.             do
  123.             ./addto uids $user grant $group $next
  124.             done
  125.  
  126. # Rules mapping gids to files.
  127. #
  128.         ./addto files /etc/group replace grant $group $next
  129.         done
  130.     fi
  131.  
  132.     if $TEST -f files.n ; then
  133.        $MV files.n files.x
  134.  
  135. # A list of file names is read from successive lines of stdin.
  136. # Each file is examined for ways to access it.
  137. # The input format is:
  138. #    <filename> <whitespace> <mode> <comments>
  139. # The <mode> is either "write" or "replace".
  140. #
  141.     $ECHO Called dofiles.                        #>/dev/tty
  142.     i=1
  143.     while $TEST "1"
  144.         do
  145.         nextfile=`$AWK '{if (NR=='"$i"') print $0}' files.x`
  146.         i=`expr $i + 1`
  147.         if $TEST -z "$nextfile" ; then
  148.             break;
  149.         fi
  150.  
  151.         file=`$ECHO $nextfile | $AWK '{print $1}'`
  152.         mode=`$ECHO $nextfile | $AWK '{print $2}'`
  153.  
  154.         $ECHO "    File $file, mode $mode"            #>/dev/tty
  155.  
  156. # Rules converting filename goals into UserName or GroupName goals.
  157. #
  158.         next=`$ECHO $nextfile | $AWK '{for (i=3;i<=NF;i++) printf("%s ", $i)}'`
  159.  
  160.         writers=`./filewriters $file`
  161.         numwriters=`$ECHO $writers | $AWK '{print NF}'`
  162.         if $TEST "$numwriters" = "3" ; then
  163.             owner=`$ECHO $writers | $AWK '{print $1}'`
  164.             group=`$ECHO $writers | $AWK '{print $2}'`
  165.             other=`$ECHO $writers | $AWK '{print $3}'`
  166.  
  167.             $ECHO "        Writers are $owner $group $other"    #>/dev/tty
  168.                 ./addto uids $owner $mode $file $next
  169.             if $TEST "$group" != "NONE" ; then
  170.                 ./addto gids $group $mode $file $next
  171.             fi
  172.             if $TEST "$other" != "NONE" ; then
  173.                 ./addto uids $other $mode $file $next
  174.             fi
  175.         else
  176.             $ECHO "        $file does not exist"        #>/dev/tty
  177.             continue
  178.         fi
  179.  
  180. # Rules converting filename goals into other filename goals.
  181. #
  182.         if $TEST "$mode" != "replace" ; then
  183.             continue
  184.         fi
  185.  
  186.     parent=`$ECHO $file | $AWK -F/ '{if (NF == 2) {
  187.         printf("/%s", $1)}
  188.         else if (NF>2) {for (i=2;i<NF;i++) printf("/%s", $i)} 
  189.         else printf("")'}`
  190.  
  191.     basename=`$ECHO $file | $AWK -F/ '{print $NF}'`
  192.  
  193.     $ECHO -n "       " Parent directory is $parent        #>/dev/tty
  194.     $ECHO ", " basename is $basename                #>/dev/tty
  195.     if $TEST -n "$parent" ; then
  196.        ./addto files $parent write replace $basename $next
  197.         fi
  198.     done
  199.  
  200.     fi
  201. done
  202.  
  203. # destroy the evidence.... Need "Success" file for report, though.
  204. $RM files.? gids.? uids.?
  205.