skraps

abuse.sh

Aug 19th, 2011
1,143
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 [email protected] - 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. logdir="/var/log/"
  16. log="bruteforceip"
  17. found=0
  18. for i in $offenders; do
  19.         while read line;do
  20.                 if [ "$line" = "$i" ]; then
  21.                         found=1
  22.                         break;
  23.                 else    
  24.                         found=0
  25.                 fi
  26.         done < "${logdir}${log}"
  27.        
  28.         if [ "$found" == "0" ];then
  29.                 echo $i >> ${logdir}${log}
  30.                 logentries=`grep ${i} secure`
  31.                 contactinfo=`whois_psad $i`
  32.                 abuseemail=`whois_psad ${i} | grep 'abuse' | grep -o -E '([[:alnum:]+\.\_\-])+@([[:alnum:]+\.\_\-])+'`
  33.                 #echo $abuseemail;
  34.                 subject="SSH BRUTE FORCE ${i}"
  35.                 echo "ip: ${i} ${contactinfo} ${logentries}" > tmp
  36.                 if [ -z "$abuseemail" ]; then
  37.                         for a in $abuseemail;do #email us
  38.                                 echo "$abuseemail" >> tmp
  39.                        
  40.                         mail $a -s "${subject}" < tmp
  41.                         done
  42.                         subject="${subject} EMAIL sent to abuse at host"
  43.                 fi
  44.        
  45.                 for a in $emails;do #email us
  46.                         mail $a -s "${subject}" < tmp
  47.                 #       echo "Sending mail"
  48.                 done
  49.         fi
  50.         found=0
  51. done
Advertisement
Add Comment
Please, Sign In to add comment