pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Advertising: 3 mobile - Mortgages - Bad Credit Loan - Phoenix Pools
paste-bin - collaborative debugging tool View Help

Posted by logged0ut on Sun 16th Dec 11:41 (modification of post by view diff)
download | new post

  1. #!/bin/bash
  2.  
  3. VERSION="1.0.1"
  4.  
  5. #------- CONFIGURATION -------#
  6.  
  7. HOSTNAME="ftp.fiend.ath.cx"
  8. ROUTER1="tarpit"
  9. ROUTER2="switch"
  10.  
  11. APACHE_LOGS="/var/log/apache2/*access_log*"
  12. POSTFIX_LOGS="/var/log/messages*"
  13.  
  14. SUBNET_THRESHOLD=10
  15.  
  16. #WWW Search strings
  17. www_list=( ""EZI_HTTP_NETDEV_DISCOVER"" ""/cgi/"" ""scanner"" ""admin"" ""robots.txt"" )
  18.  
  19. #SMTP Search strings
  20. mail_list=( ""NOQUEUE"" ""relay access denied"" ""reject"" )
  21.  
  22. #Additional IPs (Not found in logs)
  23. ban_list=( ""78.150.0.0/16"" ""194.97.153.0/24"" ""193.254.186.0/24"" ""72.148.0.0/16"" ""72.148.40.0/24"" ""220.240.0.0/16"" ""79.210.98.0/24"" )
  24.  
  25. #------- END -------#
  26.  
  27. sh_hp(){
  28. echo -e "$0 version: $VERSION \n Usage $0 [OPTION] [ARGUMENT] \n Examples: $0 -add 12.12.12.0/24 \n \n Options: \n -build              -- Build the firewall \n -clear              -- Clear the firewall \n -rules              -- Prints the Iptable rules \n -add [IP ADDRESS]   -- Adds a host or subnet to the firewall \n -del [RULE NUMBER]  -- Deletes a rule from the firewall \n -reroute [HOSTNAME] -- Reroute traffic to a different router \n -help               -- Prints this info \n"
  29. }
  30.  
  31. sh_ip(){
  32. nslookup $1 | grep -a2 $1 | grep Address | cut -d: -f2 | cut -d. -f1,2,3,4
  33. }
  34.  
  35. sh_fw(){
  36. iptables -L INPUT -v -n --line-numbers
  37. }
  38.  
  39. cr_fw(){
  40. iptables -P INPUT ACCEPT && iptables -P OUTPUT ACCEPT && iptables -P FORWARD ACCEPT && iptables -F && iptables -X && iptables -Z && echo "Iptables cleared."
  41. }
  42.  
  43. rm_rle(){
  44. if [ "$#" -gt 1 ] && [ "$#" - eq 2 ]; then iptables -D INPUT $1 && echo "$2"; elif [ "$#" -lt 2 ] && [ "$#" -gt 0 ]; then iptables -D INPUT $1; fi
  45. }
  46.  
  47. mk_rle(){
  48. if [ "$#" -lt 2 ]; then iptables -I INPUT -s "$1" -j DROP; else iptables -I INPUT -s "$1" && echo "Ruled created for $2"; fi
  49. }
  50.  
  51. mk_ban(){
  52. if [ ${#ban_list[@]} -gt 0 ]; then i=0; while [ "$i" -lt "${#ban_list[@]}" ]; do mk_rle "${ban_list[$i]}" "${ban_list[$i]}"; let "i = $i + 1"; done; fi
  53. }
  54.  
  55. ch_ban()
  56. {
  57. t=0; m=0
  58. while [ "$t" -lt "${#ban_list[@]}" ]; do if [ "$1" == "`echo ${ban_list[$t]} | cut -d. -f1,2,3`" ]; then m=1; fi; let "t = $t + 1"; done
  59. echo $m
  60. }
  61.  
  62. search(){
  63. #loop for apache
  64. j=0
  65. while [ "$j" -lt "${#www_list[@]}" ]; do zgrep --no-filename -i -u "${www_list[$j]}" $APACHE_LOGS | cut -d \  -f1 | cut -d. -f1,2,3; let "j = $j + 1"; done
  66.  
  67. #loop for postfix
  68. i=0
  69. while [ "$i" -lt "${#mail_list[@]}" ]; do zgrep --no-filename -i -u ${mail_list[$i]} $POSTFIX_LOGS | cut -d[ -f3 | cut -d] -f1 | cut -d. -f1,2,3; let "i = $i + 1"; done
  70. }
  71.  
  72. mk_fw(){
  73. ip_list=( `search | sort -u` ); i=0; cr_fw;
  74. while [ "$i" -lt "${#ip_list[@]}" ]; do if [ "${ip_list[$i]}" != `sh_ip $HOSTNAME | cut -d. -f1,2,3` ]; then if [ `ch_ban ${ip_list[$i]}` -eq  0 ]; then mk_rle "${ip_list[$i]}.0/24" "${ip_list[$i]}.0/24"; fi; fi; let "i = $i + 1"; done; mk_ban; echo "Firewall built."
  75. }
  76.  
  77. case "$1" in
  78.       "")
  79.          sh_hp
  80.          ;;
  81.       --help|-h)
  82.          sh_hp
  83.          shift
  84.          ;;
  85.       --build|-b)
  86.          mk_fw
  87.          shift
  88.          ;;
  89.       --clear|-c)
  90.          cr_fw
  91.          shift
  92.          ;;
  93.       --rules|-r)
  94.          sh_fw
  95.          shift
  96.          ;;
  97.        --add|-a)
  98.          mk_rle $2
  99.          shift
  100.          ;;
  101.       --delete|-d)
  102.          rm_rle $2
  103.          shift
  104.          ;;
  105.    esac
  106.  
  107. exit 0

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me
: