Advertisement
skraps

abuse.sh

Aug 19th, 2011
1,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.15 KB | None | 0 0
  1. #This script scans a log for failed attempts then gets the ip address of the person failing
  2. #at logging in. After that it attempts to get the abuse contact for the network the ip
  3. # address is from. If found it sends a email with the relevant log file information to the
  4. # admin and also the abuse contact for that network.
  5.  
  6. # Jackie Craig Sparks jackie.craig.sparks@gmail.com - feel free to contact me anytime thru
  7. # Email or gtalk!
  8. # Visit my websites!! and like them on facebook brothers!
  9. # http://www.phonesnake.com http://www.communicationslibrary.info
  10.  
  11.  
  12. securelog="/var/log/secure"
  13. offenders=`cat ${securelog} | grep "Failed password for " | awk '{ print $11 }' | grep -v '[^0-9]\{3\}.[^0-9]\{1,3\}.[^0-9]\{1,3\}.[^0-9]\{1,3\}' |uniq -d | grep '[^a-zA-Z\-\+0-9]\{1,20\}' | uniq -d`
  14.  
  15. emails="csparks@acho-hosting.com"
  16. logdir="/var/log/"
  17. log="bruteforceip"
  18. found=0
  19. for i in $offenders; do
  20.         while read line;do
  21.                 if [ "$line" = "$i" ]; then
  22.                         found=1
  23.                         break;
  24.                 else    
  25.                         found=0
  26.                 fi
  27.         done < "${logdir}${log}"
  28.        
  29.         if [ "$found" == "0" ];then
  30.                 echo $i >> ${logdir}${log}
  31.                 logentries=`grep ${i} secure`
  32.                 contactinfo=`whois_psad $i`
  33.                 abuseemail=`whois_psad ${i} | grep 'abuse' | grep -o -E '([[:alnum:]+\.\_\-])+@([[:alnum:]+\.\_\-])+'`
  34.                 #echo $abuseemail;
  35.                 subject="SSH BRUTE FORCE ${i}"
  36.                 echo "ip: ${i} ${contactinfo} ${logentries}" > tmp
  37.                 if [ -z "$abuseemail" ]; then
  38.                         for a in $abuseemail;do #email us
  39.                                 echo "$abuseemail" >> tmp
  40.                        
  41.                         mail $a -s "${subject}" < tmp
  42.                         done
  43.                         subject="${subject} EMAIL sent to abuse at host"
  44.                 fi
  45.        
  46.                 for a in $emails;do #email us
  47.                         mail $a -s "${subject}" < tmp
  48.                 #       echo "Sending mail"
  49.                 done
  50.         fi
  51.         found=0
  52. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement