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

  1. #!/bin/sh -- need to mention perl here to avoid recursion
  2. 'true' || eval 'exec perl -S $0 $argv:q';
  3. eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
  4. & eval 'exec /usr/bin/perl -S $0 $argv:q'
  5.         if 0;
  6.  
  7. #
  8. #  Usage: misc.chk.pl [-d]
  9. #
  10. # composer@chem.bu.edu
  11. # based on original shell script
  12. #
  13. #  This shell script checks a variety of miscellaneous potential
  14. # security problems that really don't belong anywhere else.
  15. #
  16. #  Right now this looks for to see if tftp & rexd are enabled,
  17. # to check if the uudecode alias is in the mail alias file and
  18. # not commented out, and if uudecode can create a SUID file.
  19. #
  20. #  Mechanism:  tftp.chk will try to get /etc/motd from the localhost.
  21. # Not much too it; just connect and try to get it.  For rexd, just
  22. # look in the /etc/inetd.conf file to see if it's enabled (e.g., not
  23. # commented out).
  24. #
  25. #  Warning:  it may take a minute or so to complete the test, since tftp
  26. # might take a while to get the test file, or it may take a while to time
  27. # out the connection (which is what usually happens if the test fails.)
  28.  
  29. package main;
  30. require 'chk_strings.pl';
  31. require 'fgrep.pl';
  32. require 'hostname.pl';
  33.  
  34. if ($ARGV[0] eq '-d') {
  35.     #$chk_strings'debug = 1;  # verbose debugging
  36.     $misc_chk'debug = 1;
  37.     shift;
  38. }
  39.  
  40. die "Usage: $0 [-d]\n" if @ARGV > 0;
  41.  
  42.  
  43. $TFTP="/usr/ucb/tftp" unless defined $TFTP;
  44. $UUDECODE="/usr/bin/uudecode" unless defined $UUDECODE; 
  45.  
  46. package misc_chk;
  47.  
  48. # look for uudecode alias in $aliases
  49. #$aliases="/usr/lib/aliases" if -f "/usr/lib/aliases";
  50. $aliases = ( -f '/usr/lib/aliases' && '/usr/lib/aliases' )
  51.     || ( -f '/etc/aliases'       && '/etc/aliases' )
  52.     || 'BOGUS';
  53. $uu="decode";
  54.  
  55. # look for rexd in $inetd; this file could be "/etc/servers", too!
  56. if (!defined($inetd)) {
  57.     $inetd = ( -f '/etc/inetd.conf' && '/etc/inetd.conf') ||
  58.          ( -f '/etc/servers' && '/etc/servers') ||
  59.          'BOGUS';
  60.     }
  61. $rexd="rexd";
  62.  
  63. # tmp and target file (for tftp test)
  64. $target="/etc/motd";
  65. $tmp="./tmp.$$";
  66.  
  67. # should probably generalize routine for chking for pats in file at some point
  68.  
  69. #  Read from $inetd to see if daemons are running.
  70. # Comments are lines starting with a "#", so ignore.
  71. # Checking for rexd:
  72. #
  73. print "Checking for $rexd in $inetd\n" if $debug;
  74. if (@matches = grep(!/^\s*#/, &'fgrep($inetd, $rexd))) {
  75.     print "Warning!  $rexd is enabled in $inetd!\n";
  76. }
  77.  
  78. # Check to see if anything started inetd.conf is writable;
  79. print "Checking for writable dirs in $inetd\n" if $debug;
  80. &'chk_strings($inetd);
  81.  
  82. # Checking for uudecode alias:
  83. print "Checking for $uu alias in $aliases\n" if $debug;
  84. print "Warning!  $uu is enabled in $aliases!\n"
  85.     if &'fgrep($aliases, "^\s*$uu:");
  86.  
  87. # uucode stuff -- thanks to pete shipley...
  88. print "Checking uudecode out\n" if $debug;
  89. if (-x $'UUDECODE) {
  90.     open(UU, "| $'UUDECODE");
  91.     print UU <<EOD_;
  92. begin 4755 ./foobar.$$
  93.  
  94. end
  95. EOD_
  96.     close(UU);
  97. }
  98.  
  99. &'is_able($'UUDECODE,'s','s');    # check if uudecode is SUID
  100. $is_able'silent = 1;
  101. print "Warning!  $'UUDECODE creates setuid files!\n"
  102.    if &'is_able("./foobar.$$",'s','s');
  103. $is_able'silent = 0;
  104. unlink("./foobar.$$");
  105.  
  106. #  The rest is all for tftp stuff:
  107. #
  108. #   Get the local hostname...
  109. $hostname = &'hostname;
  110.  
  111. #   Do the dirty work -- check tftp for the localhost, if it was found;
  112. # this might take a bit, since tftp might have to time out.
  113.  
  114. print "Checking out tftp on $hostname\n" if $debug;
  115. if (-x $'TFTP) {
  116.     open(SAVOUT, ">&STDOUT");    # suppress file not found
  117.     open(SAVERR, ">&STDERR");    # it's not as bad as it looks..
  118.     open(STDOUT, ">/dev/null") || die "Can't redirect stdout: $!\n";
  119.     open(STDERR, ">&STDOUT") || die "Can't dup stdout: $!\n";
  120.     close(STDOUT); close(STDERR);
  121.     open(TFTP, "| $'TFTP");
  122. print TFTP <<_XXX_;
  123. connect $hostname
  124. get $target $tmp
  125. quit
  126. _XXX_
  127.     close(TFTP);
  128.     open(STDERR, ">&SAVERR"); close(SAVERR);
  129.     open(STDOUT, ">&SAVOUT"); close(SAVOUT);
  130. } # > /dev/null 2> /dev/null
  131.  
  132. print "Warning!  tftp is enabled on $hostname!\n" if -s $tmp;
  133. unlink $tmp;
  134.  
  135. # end of script
  136.  
  137. 1;
  138.