Guest User

Untitled

a guest
Nov 23rd, 2017
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #################################################
  4. # file: blocksshd.sh #
  5. # author: Jason Alejandro Barinas Guio #
  6. # date: September/2011 #
  7. # alejandro.barinas@gmail.com #
  8. # Description: Script para realizar #
  9. # bloqueo de IP's que intenten ingresar por #
  10. # SSH. #
  11. #################################################
  12.  
  13.  
  14. pathlogs=/var/log/secure
  15. hostsfile=/etc/hosts.deny
  16. ips=`/bin/grep -R "Failed" $pathlogs* | awk '/sshd/ && /Failed password for/ { if (/invalid user/) try[$13]++; else try[$11]++; }END { for (h in try) if (try[h] > USERVAR) print h; }'`
  17.  
  18.  
  19. blockip()
  20. {
  21. verify=`/bin/grep -R "$ip" $hostsfile`
  22. if [ "$verify" == "" ] && [ $ip != "192.168.99.106" ]
  23. then
  24. echo "$ip IP NO ESTA"
  25. echo "sshd:$ip" >> $hostsfile
  26. else
  27. echo "$ip IP YA ESTA"
  28. fi
  29.  
  30. }
  31.  
  32. for ip in ${ips[*]}
  33. do
  34. if [[ $ip = *[[:digit:]]* ]]; then
  35. #echo "Es una IP valida:$ip"
  36. blockip $ip
  37. fi
  38. done
Add Comment
Please, Sign In to add comment