Advertisement
MartyniP

auth.log scanner

Mar 9th, 2011
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <?php
  2.  
  3. set_time_limit(0);
  4. $file = file_get_contents('/var/log/auth.log');
  5.  
  6. $file = explode("
  7. ",$file);
  8.  
  9. $i = 0;
  10.  
  11. foreach ($file as $k => $v) {
  12.  
  13. $mystring = $v;
  14. $findme = 'Failed password for ';
  15. $pos = strpos($mystring, $findme);
  16.  
  17. if ($pos === false) {
  18.  
  19. } else {
  20.         $v2 = explode($findme, $v);
  21.         $ex = explode(" ",$v2[1]);
  22.         if ($ex[0] == "invalid") {
  23.                         if ($ex[5] != "port") {
  24.                                 $ips[$ex[5]] = $ex[5];
  25.                         }
  26.         } else {
  27.                         if ($ex[2] != "port") {
  28.                                 $ips[$ex[2]] = $ex[2];
  29.                         }
  30.         }
  31.  
  32. }
  33.  
  34. }
  35.  
  36. foreach ($ips as $k => $v) {
  37.         echo "ip route add blackhole ".$v."
  38. ";
  39. }
  40.  
  41.  
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement