Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################################
- # The MIT License
- #
- # Copyright 2012-2014 Jakub Jirutka <jakub@jirutka.cz>.
- # Copyright 2015 Andrey Klimentev <andrei650816@gmail.com>.
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documentation files (the "Software"), to deal
- # in the Software without restriction, including without limitation the rights
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- # copies of the Software, and to permit persons to whom the Software is
- # furnished to do so, subject to the following conditions:
- #
- # The above copyright notice and this permission notice shall be included in
- # all copies or substantial portions of the Software.
- #
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- # THE SOFTWARE.
- ###############################################################################
- *filter
- :INPUT DROP [0:0]
- :FORWARD DROP [0:0]
- :OUTPUT ACCEPT [0:0]
- -A INPUT -i lo -m comment --comment "Do not attempt to firewall internal traffic on the loopback device." -j ACCEPT
- -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -m comment --comment "Continue connections that are already established or related to an established connection." -j ACCEPT
- -A INPUT -m conntrack --ctstate INVALID -m comment --comment "Drop non-conforming packets, such as malformed headers, etc." -j DROP
- -4 -A INPUT -s 127.0.0.0/8 ! -i lo -m comment --comment "Block remote packets claiming to be from a loopback address (IPv4)." -j DROP
- -6 -A INPUT -s ::1/128 ! -i lo -m comment --comment "Block remote packets claiming to be from a loopback address (IPv6)." -j DROP
- -4 -A INPUT -m addrtype --dst-type BROADCAST -m comment --comment "Drop all packets that are going to broadcast, multicast or anycast address." -j DROP
- -4 -A INPUT -m addrtype --dst-type MULTICAST -m comment --comment "Drop all packets that are going to broadcast, multicast or anycast address." -j DROP
- -4 -A INPUT -m addrtype --dst-type ANYCAST -m comment --comment "Drop all packets that are going to broadcast, multicast or anycast address." -j DROP
- -4 -A INPUT -d 224.0.0.0/4 -m comment --comment "Drop all packets that are going to broadcast, multicast or anycast address." -j DROP
- -N SSHBRUTE
- -A SSHBRUTE -m recent --name SSH --set
- -A SSHBRUTE -m recent --name SSH --update --seconds 300 --hitcount 10 -m limit --limit 1/second --limit-burst 100 -j LOG --log-prefix "iptables[SSH-brute]: "
- -A SSHBRUTE -m recent --name SSH --update --seconds 300 --hitcount 10 -j DROP
- -A SSHBRUTE -j ACCEPT
- -N ICMPFLOOD
- -A ICMPFLOOD -m recent --set --name ICMP --rsource
- -A ICMPFLOOD -m recent --update --seconds 1 --hitcount 6 --name ICMP --rsource --rttl -m limit --limit 1/sec --limit-burst 1 -j LOG --log-prefix "iptables[ICMP-flood]: "
- -A ICMPFLOOD -m recent --update --seconds 1 --hitcount 6 --name ICMP --rsource --rttl -j DROP
- -A ICMPFLOOD -j ACCEPT
- -A INPUT -p tcp --dport 22 --syn -m conntrack --ctstate NEW -m comment --comment "Accept worldwide access to SSH and use SSHBRUTE chain for preventing brute-force attacks." -j SSHBRUTE
- -4 -A INPUT -p icmp --icmp-type 8 -m conntrack --ctstate NEW -m comment --comment "Block ICMP Echo flood." -j ICMPFLOOD
- -6 -A INPUT -p ipv6-icmp --icmpv6-type 128 -m comment --comment "Block ICMP Echo flood." -j ICMPFLOOD
- -4 -A INPUT -p icmp -m comment --comment "Permit ICMP (IPv4)." -j ACCEPT
- -6 -A INPUT -p ipv6-icmp -m comment --comment "Permit ICMP (IPv6)." -j ACCEPT
- -A INPUT -p tcp --dport 113 --syn -m conntrack --ctstate NEW -m comment --comment "Good practice is to explicitly reject AUTH traffic so that it fails fast." -j REJECT --reject-with tcp-reset
- -A INPUT -m limit --limit 1/second --limit-burst 100 -m comment --comment "Prevent DoS by filling log files." -j LOG --log-prefix "iptables[DOS]: "
- COMMIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement