Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. if [ "$#" -eq "1" ]; then
  3.  givenuser="$1"
  4. else
  5.  givenuser=":"
  6. fi
  7.  
  8. confile="/etc/connections"
  9. if [ ! -f $confile ]; then echo "ERROR 00001: $confile does not exist" ; exit ; fi
  10. check1afile=`cat $confile | tr -cd '[A-Za-z0-9_-=]\n' | wc -c`
  11. check1bfile=`cat $confile | wc -c`
  12. if [ $check1afile -ne $check1bfile ]; then echo "ERROR 00002: illegal characters in $confile" ; exit ; fi
  13. defaultlimit=`grep '^default=' $confile | cut -f2 -d'='`
  14. confilelist=`cat /etc/connections`
  15. irconnections=`sockstat -c | grep ":" | grep 'tcp4' | awk '{ print $1 " " $7 }' | egrep ':666[0-9]$|:6670$|:7000$|:7777$' | cut -f1 -d' ' | sort | uniq -c | sort -n | awk '{ print $2 "=" $1 }'`
  16. for a in `echo "$irconnections"`
  17. do
  18. username=`echo "$a" | cut -f1 -d'='`
  19. connections=`echo "$a" | cut -f2 -d'='`
  20. check2file=`echo "$confilelist" | grep "^$username=" | wc -l`
  21. if [ $check2file -gt "1" ]; then echo "double account ($username) found in $confile" ; exit ; fi
  22. if [ $check2file -lt "1" ]; then
  23.  usernamelimit="$defaultlimit"
  24. else
  25.  usernamelimit=`echo "$confilelist" | grep "^$username=" | cut -f2 -d"="`
  26. fi
  27. usernamelimitkill=`expr $usernamelimit + 2`
  28. if [ "$connections" -gt "$usernamelimit" ]; then
  29. echo
  30. if [ "$connections" -gt "$usernamelimitkill" ]; then
  31. echo "CRITICAL: $username = $connections IRC Connections (AlertLimit: $usernamelimit, CriticalLimit: $usernamelimitkill)"
  32. echo "Actions: abused $username & inform server admin with logs"
  33. else
  34. echo "ALERT: $username = $connections IRC Connections (AlertLimit: $usernamelimit, CriticalLimit: $usernamelimitkill)"
  35. echo "Actions: inform server admin with logs"
  36. fi
  37. else
  38. if [ "$givenuser" != ":" ]; then echo "NORMAL: $username = $connections IRC Connections (AlertLimit: $usernamelimit, CriticalLimit: $usernamelimitkill)" ; fi
  39. fi
  40. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement