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

  1. #
  2. # version 1, Tue Mar 21 20:21:33 1995, last mod by wietse
  3. #
  4. sub policy_engine
  5. {
  6. local($target, $proximity) = @_;
  7.  
  8. #
  9. # Respect the maximal proximity level.
  10. #
  11. if ($proximity > $max_proximity_level) {
  12.     print "policy: pruning $target via proximity level\n" if $debug;
  13.     return -1;
  14. }
  15.  
  16. #
  17. # Do not attack "verboten" hosts.
  18. #
  19. if (&target_is_exception($target)) {
  20.     print "policy: pruning $target via exception\n" if $debug;
  21.     return -1;
  22. }
  23.  
  24. #
  25. # attacks tend to get weaker the farther away from home; do they
  26. # wither and die, or keep going at a low level?
  27. #
  28. $new_attack_level = $attack_level - ($proximity * $proximity_descent);
  29. if ($new_attack_level < 0) {
  30.     if (!$sub_zero_proximity) {
  31.         print "policy: pruning $target via attack level < 0\n";
  32.         return -1;
  33.         }
  34.     else { 
  35.         $new_attack_level = 0; 
  36.         }
  37.     }
  38.  
  39. print "policy: $target prox $proximity level $new_attack_level\n" if $debug;
  40.  
  41. return $new_attack_level;
  42.  
  43. }
  44.  
  45. #
  46. # Does target match list of shell-like patterns?
  47. #
  48. sub match_host {
  49.     local($target, $patterns) = @_;
  50.     local($pattern);
  51.  
  52.     for $pattern (split(/(,|\s)+/, $patterns)) {
  53.     $pattern =~ s/\.$//;    # strip trailing dot
  54.     $pattern =~ s/^\.//;    # strip leading dot
  55.     $pattern =~ s/\./\\./g;    # quote dots
  56.     $pattern =~ s/\*/.*/g;    # translate regexp star to shell star
  57.     if ($pattern =~ /^\d+/) {
  58.         return 1 if ($all_hosts{$target}{'IP'} =~ /^$pattern\b/);
  59.     } else {
  60.         return 1 if ($target =~ /\b$pattern$/);
  61.     }
  62.     }
  63.     return 0;
  64. }
  65.  
  66. #
  67. # don't want to attack certain sites, like .mil, etc.
  68. #
  69. sub target_is_exception
  70. {
  71.     local($target) = @_;
  72.     local($pattern);
  73.  
  74.     #
  75.     # if this is set, only attack things that contain this string:
  76.     if ($only_attack_these && !&match_host($target, $only_attack_these)) {
  77.     return 1;
  78.     }
  79.     #
  80.     # if this is set, don't attack things that contain this string:
  81.     if ($dont_attack_these && &match_host($target, $dont_attack_these)) {
  82.     return 1;
  83.     }
  84.     #
  85.     # else, nothing is wrong, go for it...
  86.     return 0; 
  87. }
  88.  
  89. 1;
  90.