Guest User

firewall

a guest
Aug 7th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 15.17 KB | None | 0 0
  1. #!/bin/bash
  2. # ---------------------------------------------------------------------
  3. # Linux-iptables-Firewallskript, Copyright (c) 2010 under the GPL
  4. # Autogenerated by iptables Generator v1.22 (c) 2002-2010 by Harald Bertram
  5. # Please visit http://harry.homelinux.org for new versions of
  6. # the iptables Generator (c).
  7. #
  8. # If you have questions about the iptables Generator or about
  9. # your Firewall-Skript feel free to take a look at out website or
  10. # send me an E-Mail to [email protected].
  11. #
  12. # My special thanks are going to Lutz Heinrich (trinitywork at hotmail dot com)
  13. # who made lots of Beta-Testing and gave me lots of well qualified
  14. # Feedback that made me able to improve the iptables Generator.
  15. # --------------------------------------------------------------------
  16. # Besondere Hinweise fuer Nutzer einer Debian-Distribution oder eines Debian-Derivates (Ubuntu, Knoppix, Kanotix, ...)!
  17. # Fuehren Sie die folgenden Kommandos aus, nachdem das Skript  "firewall" nach /etc/init.d kopiert wurde:
  18. # chmod 755 /etc/init.d/firewall
  19. # update-rc.d firewall defaults
  20. # /etc/init.d/firewall start
  21. # --------------------------------------------------------------------
  22.  
  23. case "$1" in
  24.  start)
  25.  echo "Starte IP-Paketfilter"
  26.  
  27.  # iptables-Modul
  28.  modprobe ip_tables
  29.  # Connection-Tracking-Module
  30.  modprobe ip_conntrack
  31.  # Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar
  32.  modprobe ip_conntrack_irc
  33.  modprobe ip_conntrack_ftp
  34.  
  35.  # Tabelle flushen
  36.  iptables -F
  37.  iptables -t nat -F
  38.  iptables -t mangle -F
  39.  iptables -X
  40.  iptables -t nat -X
  41.  iptables -t mangle -X
  42.  
  43.  # Default-Policies setzen
  44.  iptables -P INPUT DROP
  45.  iptables -P OUTPUT DROP
  46.  iptables -P FORWARD DROP
  47.  
  48.  # MY_REJECT-Chain
  49.  iptables -N MY_REJECT
  50.  
  51.  # MY_REJECT fuellen
  52.  iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset
  53.  iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable
  54.  iptables -A MY_REJECT -p icmp -j DROP
  55.  iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable
  56.  
  57.  # MY_DROP-Chain
  58.  iptables -N MY_DROP
  59.  iptables -A MY_DROP -j DROP
  60.  
  61.  # Reject packets from RFC1918 class networks (i.e., spoofed)
  62.  iptables -A INPUT -s 10.0.0.0/8     -j DROP
  63.  iptables -A INPUT -s 169.254.0.0/16 -j DROP
  64.  iptables -A INPUT -s 172.16.0.0/12  -j DROP
  65.  iptables -A INPUT -s 127.0.0.0/8    -j DROP
  66.  iptables -A INPUT -s 224.0.0.0/4      -j DROP
  67.  iptables -A INPUT -d 224.0.0.0/4      -j DROP
  68.  iptables -A INPUT -s 240.0.0.0/5      -j DROP
  69.  iptables -A INPUT -d 240.0.0.0/5      -j DROP
  70.  iptables -A INPUT -s 0.0.0.0/8        -j DROP
  71.  iptables -A INPUT -d 0.0.0.0/8        -j DROP
  72.  iptables -A INPUT -d 239.255.255.0/24 -j DROP
  73.  iptables -A INPUT -d 255.255.255.255  -j DROP
  74.  
  75.  
  76.  # Korrupte Pakete zurueckweisen
  77.  iptables -A INPUT -m state --state INVALID -j DROP
  78.  iptables -A OUTPUT -m state --state INVALID -j DROP
  79.  
  80.  # Stealth Scans etc. DROPpen
  81.  # Keine Flags gesetzt
  82.  iptables -A INPUT -p tcp --tcp-flags ALL NONE -j MY_DROP
  83.  
  84.  # SYN und FIN gesetzt
  85.  iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP
  86.  
  87.  # SYN und RST gleichzeitig gesetzt
  88.  iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP
  89.  
  90.  # FIN und RST gleichzeitig gesetzt
  91.  iptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP
  92.  
  93.  # FIN ohne ACK
  94.  iptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP
  95.  
  96.  # PSH ohne ACK
  97.  iptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP
  98.  
  99.  # URG ohne ACK
  100.  iptables -A INPUT -p tcp --tcp-flags ACK,URG URG -j MY_DROP
  101.  
  102.  # Loopback-Netzwerk-Kommunikation zulassen
  103.  iptables -A INPUT -i lo -j ACCEPT
  104.  iptables -A OUTPUT -o lo -j ACCEPT
  105.  
  106.  # Connection-Tracking aktivieren
  107.  iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
  108.  iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  109.  
  110.  # DNS
  111.  iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 53 -j ACCEPT
  112.  iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 53 -j ACCEPT
  113.  
  114.  # FTP
  115.  iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 21 -j ACCEPT
  116.  
  117.  # SSH
  118.  iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 22 -j ACCEPT
  119.  
  120.  # SMTP
  121.  iptables -A OUTPUT -o eth0 -m state --state NEW -p tcp --dport 25 -j ACCEPT
  122.  
  123.  # Webmin
  124.  iptables -A INPUT -i eth0 -m tcp -p tcp --dport 10000 -j ACCEPT
  125.  
  126.  # Call of Duty Reihe
  127.  iptables -A INPUT -i eth0 -p udp --dport 28984 -j ACCEPT
  128.  iptables -A INPUT -i eth0 -p udp --dport 28983 -j ACCEPT
  129.  iptables -A INPUT -i eth0 -p udp --dport 28982 -j ACCEPT
  130.  iptables -A INPUT -i eth0 -p udp --dport 28981 -j ACCEPT
  131.  iptables -A INPUT -i eth0 -p udp --dport 28980 -j ACCEPT
  132.  iptables -A INPUT -i eth0 -p udp --dport 28967 -j ACCEPT
  133.  iptables -A INPUT -i eth0 -p udp --dport 28966 -j ACCEPT
  134.  iptables -A INPUT -i eth0 -p udp --dport 28964 -j ACCEPT
  135.  iptables -A INPUT -i eth0 -p udp --dport 28963 -j ACCEPT
  136.  iptables -A INPUT -i eth0 -p udp --dport 28962 -j ACCEPT
  137.  iptables -A INPUT -i eth0 -p udp --dport 28961 -j ACCEPT
  138.  iptables -A INPUT -i eth0 -p udp --dport 28960 -j ACCEPT
  139.  iptables -A OUTPUT -o eth0 -p udp --sport 28984 -j ACCEPT
  140.  iptables -A OUTPUT -o eth0 -p udp --sport 28983 -j ACCEPT
  141.  iptables -A OUTPUT -o eth0 -p udp --sport 28982 -j ACCEPT
  142.  iptables -A OUTPUT -o eth0 -p udp --sport 28981 -j ACCEPT
  143.  iptables -A OUTPUT -o eth0 -p udp --sport 28980 -j ACCEPT
  144.  iptables -A OUTPUT -o eth0 -p udp --sport 28967 -j ACCEPT
  145.  iptables -A OUTPUT -o eth0 -p udp --sport 28966 -j ACCEPT
  146.  iptables -A OUTPUT -o eth0 -p udp --sport 28964 -j ACCEPT
  147.  iptables -A OUTPUT -o eth0 -p udp --sport 28963 -j ACCEPT
  148.  iptables -A OUTPUT -o eth0 -p udp --sport 28962 -j ACCEPT
  149.  iptables -A OUTPUT -o eth0 -p udp --sport 28961 -j ACCEPT
  150.  iptables -A OUTPUT -o eth0 -p udp --sport 28960 -j ACCEPT
  151.  
  152.  # CS:S
  153.  iptables -A INPUT -i eth0 -p tcp --dport 27015 -j ACCEPT
  154.  iptables -A OUTPUT -o eth0 -p tcp --sport 27015 -j ACCEPT
  155.  iptables -A INPUT -i eth0 -p udp --dport 27015 -j ACCEPT
  156.  iptables -A OUTPUT -o eth0 -p udp --sport 27015 -j ACCEPT
  157.  
  158.  # Enemy Teritorry
  159.  iptables -A INPUT -i eth0 -p udp --dport 27961 -j ACCEPT
  160.  iptables -A INPUT -i eth0 -p udp --dport 27960 -j ACCEPT
  161.  iptables -A INPUT -i eth0 -p udp --dport 27900 -j ACCEPT
  162.  iptables -A INPUT -i eth0 -p udp --dport 30001 -j ACCEPT
  163.  iptables -A OUTPUT -o eth0 -p udp --sport 27961 -j ACCEPT
  164.  iptables -A OUTPUT -o eth0 -p udp --sport 27960 -j ACCEPT
  165.  iptables -A OUTPUT -o eth0 -p udp --sport 27900 -j ACCEPT
  166.  iptables -A OUTPUT -o eth0 -p udp --sport 30001 -j ACCEPT
  167.  
  168.  # Teamspeak3
  169.  iptables -A INPUT -i eth0 -p udp --dport 1337 -j ACCEPT
  170.  iptables -A INPUT -i eth0 -p udp --dport 1338 -j ACCEPT
  171.  iptables -A INPUT -i eth0 -p udp --dport 9987 -j ACCEPT
  172.  iptables -A INPUT -i eth0 -p udp --dport 9988 -j ACCEPT
  173.  iptables -A INPUT -i eth0 -p udp --dport 9999 -j ACCEPT
  174.  iptables -A INPUT -i eth0 -p udp --dport 9986 -j ACCEPT
  175.  iptables -A INPUT -i eth0 -p tcp --dport 30033 -j ACCEPT
  176.  iptables -A INPUT -i eth0 -p tcp --dport 10011 -j ACCEPT
  177.  iptables -A INPUT -i eth0 -p tcp --dport 2008 -j ACCEPT
  178.  iptables -A OUTPUT -o eth0 -p udp --dport 1337 -j ACCEPT
  179.  iptables -A OUTPUT -o eth0 -p udp --dport 1338 -j ACCEPT
  180.  iptables -A OUTPUT -o eth0 -p udp --dport 9987 -j ACCEPT
  181.  iptables -A OUTPUT -o eth0 -p udp --dport 9988 -j ACCEPT
  182.  iptables -A OUTPUT -o eth0 -p udp --dport 9999 -j ACCEPT
  183.  iptables -A OUTPUT -o eth0 -p udp --dport 9986 -j ACCEPT
  184.  iptables -A OUTPUT -o eth0 -p tcp --dport 30033 -j ACCEPT
  185.  iptables -A OUTPUT -o eth0 -p tcp --dport 10011 -j ACCEPT
  186.  iptables -A OUTPUT -o eth0 -p tcp --dport 2008 -j ACCEPT
  187.  
  188.  #COD4 & ET getstatus DDoS fix
  189.  #New Chain for each Server so Rcon tools like HLSW work
  190.  #for ET pub server
  191.  iptables -N Q3_27960
  192.  iptables -A Q3_27960 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  193.  iptables -A Q3_27960 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_27960
  194.  iptables -A Q3_27960 -m recent --update --seconds 2 --hitcount 4 --name getstatus_27960 -j DROP
  195.  iptables -A Q3_27960 -j RETURN
  196.  iptables -I INPUT 2 -p udp --dport 27960 -j Q3_27960
  197.  #for COD2 pub server
  198.  iptables -N Q3_28967
  199.  iptables -A Q3_28967 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  200.  iptables -A Q3_28967 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28967
  201.  iptables -A Q3_28967 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28967 -j DROP
  202.  iptables -A Q3_28967 -j RETURN
  203.  iptables -I INPUT 2 -p udp --dport 28967 -j Q3_28967
  204.  #for ET facade
  205.  iptables -N Q3_27900
  206.  iptables -A Q3_27900 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  207.  iptables -A Q3_27900 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_27900
  208.  iptables -A Q3_27900 -m recent --update --seconds 2 --hitcount 4 --name getstatus_27900 -j DROP
  209.  iptables -A Q3_27900 -j RETURN
  210.  iptables -I INPUT 2 -p udp --dport 27900 -j Q3_27900
  211.  #for ET facade 2
  212.  iptables -N Q3_30001
  213.  iptables -A Q3_30001 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  214.  iptables -A Q3_30001 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_30001
  215.  iptables -A Q3_30001 -m recent --update --seconds 2 --hitcount 4 --name getstatus_30001 -j DROP
  216.  iptables -A Q3_30001 -j RETURN
  217.  iptables -I INPUT 2 -p udp --dport 30001 -j Q3_30001
  218.  #for sniper server
  219.  iptables -N Q3_28960
  220.  iptables -A Q3_28960 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  221.  iptables -A Q3_28960 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28960
  222.  iptables -A Q3_28960 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28960 -j DROP
  223.  iptables -A Q3_28960 -j RETURN
  224.  iptables -I INPUT 2 -p udp --dport 28960 -j Q3_28960
  225.  #for tdm server
  226.  iptables -N Q3_28963
  227.  iptables -A Q3_28963 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  228.  iptables -A Q3_28963 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28963
  229.  iptables -A Q3_28963 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28963 -j DROP
  230.  iptables -A Q3_28963 -j RETURN
  231.  iptables -I INPUT 2 -p udp --dport 28963 -j Q3_28963
  232.  #for sd server
  233.  iptables -N Q3_28964
  234.  iptables -A Q3_28964 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  235.  iptables -A Q3_28964 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28964
  236.  iptables -A Q3_28964 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28964 -j DROP
  237.  iptables -A Q3_28964 -j RETURN
  238.  iptables -I INPUT 2 -p udp --dport 28964 -j Q3_28964
  239.  #for ET warserver
  240.  iptables -N Q3_27961
  241.  iptables -A Q3_27961 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  242.  iptables -A Q3_27961 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_27961
  243.  iptables -A Q3_27961 -m recent --update --seconds 2 --hitcount 4 --name getstatus_27961 -j DROP
  244.  iptables -A Q3_27961 -j RETURN
  245.  iptables -I INPUT 2 -p udp --dport 27961 -j Q3_27961
  246.  #for cb server
  247.  iptables -N Q3_28962
  248.  iptables -A Q3_28962 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  249.  iptables -A Q3_28962 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28962
  250.  iptables -A Q3_28962 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28962 -j DROP
  251.  iptables -A Q3_28962 -j RETURN
  252.  iptables -I INPUT 2 -p udp --dport 28962 -j Q3_28962
  253.  #for cg server
  254.  iptables -N Q3_28961
  255.  iptables -A Q3_28961 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  256.  iptables -A Q3_28961 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28961
  257.  iptables -A Q3_28961 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28961 -j DROP
  258.  iptables -A Q3_28961 -j RETURN
  259.  iptables -I INPUT 2 -p udp --dport 28961 -j Q3_28961
  260.  #for war1 server
  261.  iptables -N Q3_28980
  262.  iptables -A Q3_28980 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  263.  iptables -A Q3_28980 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28980
  264.  iptables -A Q3_28980 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28980 -j DROP
  265.  iptables -A Q3_28980 -j RETURN
  266.  iptables -I INPUT 2 -p udp --dport 28980 -j Q3_28980
  267.  #for war2 server
  268.  iptables -N Q3_28981
  269.  iptables -A Q3_28981 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  270.  iptables -A Q3_28981 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28981
  271.  iptables -A Q3_28981 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28981 -j DROP
  272.  iptables -A Q3_28981 -j RETURN
  273.  iptables -I INPUT 2 -p udp --dport 28981 -j Q3_28981
  274.  #for gungame server
  275.  iptables -N Q3_28982
  276.  iptables -A Q3_28982 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  277.  iptables -A Q3_28982 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28982
  278.  iptables -A Q3_28982 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28982 -j DROP
  279.  iptables -A Q3_28982 -j RETURN
  280.  iptables -I INPUT 2 -p udp --dport 28982 -j Q3_28982
  281.  #for cupprize server
  282.  iptables -N Q3_28983
  283.  iptables -A Q3_28983 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  284.  iptables -A Q3_28983 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28983
  285.  iptables -A Q3_28983 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28983 -j DROP
  286.  iptables -A Q3_28983 -j RETURN
  287.  iptables -I INPUT 2 -p udp --dport 28983 -j Q3_28983
  288.  #for reddit server
  289.  iptables -N Q3_28984
  290.  iptables -A Q3_28984 -m string ! --hex-string "|FF FF FF FF|" --algo bm --from 27 --to 30 -j RETURN
  291.  iptables -A Q3_28984 -m string --algo bm --string "getstatus" -m recent --set --name getstatus_28984
  292.  iptables -A Q3_28984 -m recent --update --seconds 2 --hitcount 4 --name getstatus_28983 -j DROP
  293.  iptables -A Q3_28984 -j RETURN
  294.  iptables -I INPUT 2 -p udp --dport 28984 -j Q3_28984
  295.  
  296.  # Webserver
  297.  iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  298.  
  299.  # Default-Policies mit REJECT
  300.  iptables -A INPUT -j MY_REJECT
  301.  iptables -A OUTPUT -j MY_REJECT
  302.  
  303.  # Max. 500/Sekunde (5/Jiffie) senden
  304.  echo 5 > /proc/sys/net/ipv4/icmp_ratelimit
  305.  
  306.  # Speicherallozierung und -timing for-De/-Fragmentierung
  307.  echo 262144 > /proc/sys/net/ipv4/ipfrag_high_thresh
  308.  echo 196608 > /proc/sys/net/ipv4/ipfrag_low_thresh
  309.  echo 30 > /proc/sys/net/ipv4/ipfrag_time
  310.  
  311.  # TCP-FIN-Timeout zum Schutz vor DoS-Attacken setzen
  312.  echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
  313.  
  314.  # Maximal 3 Antworten auf ein TCP-SYN
  315.  echo 3 > /proc/sys/net/ipv4/tcp_retries1
  316.  
  317.  # TCP-Pakete maximal 15x wiederholen
  318.  echo 15 > /proc/sys/net/ipv4/tcp_retries2
  319.  
  320.  ;;
  321.  
  322.  stop)
  323.  echo "Stoppe IP-Paketfilter"
  324.  # Tabelle flushen
  325.  iptables -F
  326.  iptables -t nat -F
  327.  iptables -t mangle -F
  328.  iptables -X
  329.  iptables -t nat -X
  330.  iptables -t mangle -X
  331.  # Default-Policies setzen
  332.  iptables -P INPUT ACCEPT
  333.  iptables -P OUTPUT ACCEPT
  334.  iptables -P FORWARD ACCEPT
  335.  ;;
  336.  
  337.  status)
  338.  echo "Tabelle filter"
  339.  iptables -L -vn
  340.  echo "Tabelle nat"
  341.  iptables -t nat -L -vn
  342.  echo "Tabelle mangle"
  343.  iptables -t mangle -L -vn
  344.  ;;
  345.  
  346.  *)
  347.  echo "Fehlerhafter Aufruf"
  348.  echo "Syntax: $0 {start|stop|status}"
  349.  exit 1
  350.  ;;
  351.  
  352. esac
Advertisement
Add Comment
Please, Sign In to add comment