home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SATAN11.ZIP / PERL / COPS2SAT.PL < prev    next >
Perl Script  |  1995-04-11  |  6KB  |  211 lines

  1. #!/usr/local/bin/perl5
  2. #
  3. #  An experimental script that will Convert a COPS warning report
  4. # into SATAN rules.  Take stdin or a filename.  Uses the function
  5. # "satan_print" to emit SATAN rules.
  6. #
  7.  
  8. require "perl/hostname.pl";
  9. require "perl/misc.pl";
  10.  
  11. # we're the target... nothing remote here
  12. $target = &hostname();
  13.  
  14. #
  15. # default value for satan_print(); everything we report is "available"
  16. $status = "a";
  17.  
  18. # most things only affect users on the machine
  19. $trusted = "ANY@$target";
  20.  
  21. # most things will be blank here, at least on my first shot at this...
  22. $service_ouput = "";
  23.  
  24. # ok, process everything now:
  25. while (<>) {
  26.  
  27.     # chow down on blank lines
  28.     if ($_ =~ /^\s*$/) { next; }
  29.  
  30.     # top three lines look like:
  31.     #
  32.     # ATTENTION
  33.     # Security Report for...
  34.     # from host ...
  35.     if ($_ =~ /from host/) { $start_processing = 1; next; }
  36.     if (!$start_processing) { next; }
  37.  
  38.     # get the service, if possible -- 
  39.     # assumes all checks print out something like:
  40.     # "**** foo.chk ****"
  41.     # when the verbose flag is true
  42.     if ($_ =~ /^\*\*\*\*/) {
  43.         ($service) = ($_ =~ /\*\*\*\* (\S+) /);
  44.         next;
  45.         }
  46.     
  47.     #  IMPORTANT - exception list!
  48.     #
  49.     #  Be very careful of regular expressions and other meta stuff...
  50.     # ()'s, *'s, ?'s, /'s, etc. are all trouble.  Backquote if in doubt.
  51.     #
  52.     #  Sample list:
  53.     #
  54.     #  Hassled by mail warning?
  55.     # next if (m@Warning!  /usr/spool/mail is _World_ writable!@);
  56.     #
  57.     #  Running an NIS-free machine but in an NIS environment?
  58.     #  next if (/YG/);
  59.     #  next if (/YP/);
  60.  
  61.     # if it doesn't start with "Warning!", then nuke the second
  62.     # line; it's a multipart print
  63.     next unless ($_ =~ /^Warning!/);
  64.     
  65.     #
  66.     # START THE CHECKING
  67.     #
  68.     # level 0 checks -- the most serious
  69.     #
  70.     if ($_ =~ /A "+" entry in/) {
  71.         $severity = "us";
  72.         $trusted = "ANY@ANY";
  73.         $trustee = "ANY@$target";
  74.         $text = "+ in /etc/hosts.equiv file";
  75.         }
  76.         
  77.     # Assume bugs are all bad -- some bugs are remote; need to
  78.     # change this to recognize them...
  79.     elsif (m@ould have a hole/bug@) {
  80.         $severity = "rs";
  81.         $trusted = "ANY@$target";
  82.         $trustee = "root@$target";
  83.         $text = "serious bug";
  84.         }
  85.  
  86.     # kuang telling us we're in deep yoghurt, or something like that...
  87.     elsif ($_ =~ /DO ANYTHING/) {
  88.         $severity = "rs";
  89.         $trusted = "ANY@$target";
  90.         $trustee = "root@$target";
  91.         $text = "kuang found a path to compromise root";
  92.         }
  93.  
  94.     # writable password file really sucks:
  95.     elsif ($_ =~ /\/etc\/passwd.*_World_/) {
  96.         $severity = "rs";
  97.         $trusted = "ANY@$target";
  98.         $trustee = "root@$target";
  99.         $text = "world-writable password file";
  100.         }
  101.  
  102.     # this is easy root most of the time...
  103.     elsif ($_ =~ /Directory.*is _World_ writable and in roots path!/) {
  104.         $severity = "rs";
  105.         $trusted = "ANY@$target";
  106.         $trustee = "root@$target";
  107.         $text = "world-writable file in root's path";
  108.         }
  109.  
  110.     # level 1 checks:
  111.     #
  112.     elsif ($_ =~ /uudecode is suid!/) {
  113.         $severity = "uw";    # cops should tell us *what* user, eh?
  114.         $trusted = "ANY@$target";
  115.         $trustee = "user@$target";
  116.         $text = "uudecode is suid";
  117.         }
  118.     elsif ($_ =~ /rexd is enabled in/) {
  119.         $severity = "us";
  120.         $trusted = "ANY@ANY";
  121.         $trustee = "user@$target";
  122.         $text = "rexd is enabled";
  123.         }
  124.     elsif ($_ =~ /User.*mode/ && $_ !~ /is not a directory/) {
  125.         $severity = "us";
  126.         $trusted = "ANY@$target";
  127.         $trustee = "user@$target";
  128.         $text = "User home directory or startup file is writable";
  129.         }
  130.     elsif ($_ =~ /tftp is enabled on/) {
  131.         $severity="nr";
  132.         $trustee="nobody@$target";
  133.         $trusted="ANY@ANY";
  134.         $text="tftp is enabled";
  135.         $text = "tftp is enabled on";
  136.         &satan_print();
  137.         # (OUTPUT TWICE)
  138.         $severity="nw";
  139.         $trustee="nobody@$target";
  140.         $trusted="ANY@ANY";
  141.         $text = "tftp is enabled on";
  142.         }
  143.     elsif ($_ =~ /uudecode is enabled in/) {
  144.         $severity = "nw";
  145.         $trustee="nobody@$target";
  146.         $trusted="ANY@ANY";
  147.         $text = "uudecode is enabled in/";
  148.         }
  149.     # unclear what ramifications are...
  150.     # /Password file, line.*is blank/
  151.     # /Password file, line.*nonnumeric user id:/
  152.     elsif ($_ =~ /(in cron_file) is World writable!/) {
  153.         $severity = "root";
  154.         $trusted = "ANY@$target";
  155.         $trustee = "root@$target";
  156.         $status = "q"; # who knows if it really matters?
  157.         $text = "File in cron_file is world writable";
  158.         }
  159.     elsif ($_ =~ /File.*(inside root executed file) is _World_ writable!/) {
  160.         $severity = "root";
  161.         $trusted = "ANY@$target";
  162.         $trustee = "root@$target";
  163.         $status = "q"; # who knows if it really matters?
  164.         $text = "File inside root executed file is _World_ writable!";
  165.         }
  166.     elsif ($_ =~ /File.*(in .*) is _World_ writable!/) {
  167.         $severity = "user";
  168.         $trusted = "ANY@$target";
  169.         $trustee = "root@$target";
  170.         $status = "q"; # who knows if it really matters?
  171.         $text = "File inside important command is _World_ writable!";
  172.         }
  173.     # this assumes anon-ftp is actually on!
  174.     elsif ($_ =~ /ftp's home directory should not be/) {
  175.         $severity = "nw";
  176.         $trusted = "ANY@ANY";
  177.         $trustee = "nobody@$target";
  178.         $text = "ftp's home directory is /";
  179.         &satan_print();
  180.         # (OUTPUT TWICE)
  181.         $severity = "nr";
  182.         $trusted = "ANY@ANY";
  183.         $trustee = "nobody@$target";
  184.         $text = "ftp's home directory is /";
  185.         }
  186.     # this gives away password file; what do we do?
  187.     # elsif (/and.*ass.*are the same/)
  188.     # $text = "system password file and ~ftp/etc/passwd are the same";
  189.  
  190.     # unclear of ramifications; could be very bad or ok
  191.     # elsif (/should be mode 555/)
  192.  
  193.     # rhosts entry in ftp...
  194.     # elsif (/should be be empty/)
  195.     
  196.     #  PRINT *SOMETHING* if can't find anything... give it no
  197.     # severity so it won't get counted...
  198.     else  {
  199.         $severity = "";
  200.         $trusted = "";
  201.         $trustee = "";
  202.         $status = "a";
  203.         ($text) = /Warning!\s+(.+)$/;
  204.         # $text = "Unknown warning!";
  205.         }
  206.  
  207.  
  208.     &satan_print();
  209.     }
  210.  
  211.