home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / SATAN11.ZIP / PERL / SUBNETS.PL < prev    next >
Text File  |  1995-04-11  |  2KB  |  108 lines

  1. #
  2. # sift by subnets
  3. #
  4. # Output to: 
  5. #
  6. # $all_subnets{subnet}: hosts per subnet
  7. #
  8. # $host_subnet{host}: subnet of this host
  9. #
  10. # $subnet_count{subnet}: number of hosts in this subnet
  11. #
  12. # $subnet_severities{subnet}: nr of vulnerable hosts in subnet
  13. #
  14. # $subnet_flag: reset whenever the tables are updated. To recalculate,
  15. # invoke make_subnet_info().
  16. #
  17. # Standalone usage: perl subnets.pl [data directory]
  18.  
  19. #
  20. # Generate subnet statistics.
  21. #
  22. sub make_subnet_info {
  23. local($subnet, $host);
  24.  
  25. if ($subnet_flag > 0) {
  26.     return;
  27.     }
  28. $subnet_flag = time();
  29. %all_subnets = ();
  30.  
  31. &make_severity_info();
  32.  
  33. print "Rebuild subnet type statistics...\n" if $debug;
  34.  
  35. %all_subnets = ();
  36. %host_subnet = ();
  37.  
  38. for $host (keys %all_hosts) {
  39.     if ($host) {
  40.         ($subnet = $all_hosts{$host}{'IP'}) =~ s/\.[^.]*$//;
  41.         $subnet = "unknown" unless $subnet;
  42.         $all_subnets{$subnet} .= "$host ";
  43.         $host_subnet{$host} = $subnet;
  44.         }
  45.     }
  46.  
  47. # Cheat in case the facts file has names not in all-hosts.
  48.  
  49. for $host (keys %hosttype, keys %severity_host_count) {
  50.     next unless $host;
  51.     next if defined($host_subnet{$host});
  52.     if ($host =~ /^([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$/) {
  53.         $subnet = $1;
  54.     } else {
  55.         $subnet = "unknown";
  56.     }
  57.     $all_subnets{$subnet} .= "$host ";
  58.     $host_subnet{$host} = $subnet;
  59. }
  60.  
  61. for $subnet (keys %all_subnets) {
  62.     $subnet_count{$subnet} = split(/\s+/, $all_subnets{$subnet});
  63.     $subnet_severities{$subnet} = 0;
  64.     for $host (split(/\s+/, $all_subnets{$subnet})) {
  65.         $subnet_severities{$subnet}++ if exists($severity_host_type_info{$host});
  66.         }
  67.     }
  68. }
  69.  
  70. #
  71. # erase the subnet info tables
  72. #
  73. sub clear_subnet_info {
  74.     %all_subnets = ();
  75.     %host_subnet = ();
  76.     %subnet_count = ();
  77.     %subnet_severities = ();
  78.     $subnet_flag = 0;
  79. }
  80.  
  81. #
  82. # Stand-alone mode
  83. #
  84. if ($running_under_satan == 0) {
  85. warn "subnets.p in stand-alone mode...";
  86. $running_under_satan = 1;
  87. $debug = 1;
  88. require 'perl/targets.pl';
  89. require 'perl/severities.pl';
  90. require 'perl/facts.pl';
  91.  
  92. &read_all_hosts("$ARGV[0]/all-hosts");
  93. &read_facts("$ARGV[0]/facts");
  94. &make_subnet_info();
  95.  
  96. print "Subnet info\n";
  97.  
  98. for (keys %all_subnets) {
  99.     print "Subnet: $_ $subnet_severities{$_}/$subnet_count{$_}\n";
  100.     for (split(/\s/, $all_subnets{$_})) {
  101.         print "\t$_\n";
  102.         }
  103.     }
  104. }
  105.  
  106. 1;
  107.