Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. ###############################################################################
  2. # The MIT License
  3. #
  4. # Copyright 2012-2014 Jakub Jirutka <jakub@jirutka.cz>.
  5. # Copyright 2015 Andrey Klimentev <andrei650816@gmail.com>.
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. # THE SOFTWARE.
  23. ###############################################################################
  24.  
  25. *filter
  26.  
  27. :INPUT DROP [0:0]
  28. :FORWARD DROP [0:0]
  29. :OUTPUT ACCEPT [0:0]
  30.  
  31. -A INPUT -i lo -m comment --comment "Do not attempt to firewall internal traffic on the loopback device." -j ACCEPT
  32.  
  33. -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -m comment --comment "Continue connections that are already established or related to an established connection." -j ACCEPT
  34.  
  35. -A INPUT -m conntrack --ctstate INVALID -m comment --comment "Drop non-conforming packets, such as malformed headers, etc." -j DROP
  36.  
  37. -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
  38. -6 -A INPUT -s ::1/128 ! -i lo -m comment --comment "Block remote packets claiming to be from a loopback address (IPv6)." -j DROP
  39.  
  40. -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
  41. -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
  42. -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
  43. -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
  44.  
  45. -N SSHBRUTE
  46. -A SSHBRUTE -m recent --name SSH --set
  47. -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]: "
  48. -A SSHBRUTE -m recent --name SSH --update --seconds 300 --hitcount 10 -j DROP
  49. -A SSHBRUTE -j ACCEPT
  50.  
  51. -N ICMPFLOOD
  52. -A ICMPFLOOD -m recent --set --name ICMP --rsource
  53. -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]: "
  54. -A ICMPFLOOD -m recent --update --seconds 1 --hitcount 6 --name ICMP --rsource --rttl -j DROP
  55. -A ICMPFLOOD -j ACCEPT
  56.  
  57. -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
  58.  
  59. -4 -A INPUT -p icmp --icmp-type 8 -m conntrack --ctstate NEW -m comment --comment "Block ICMP Echo flood." -j ICMPFLOOD
  60. -6 -A INPUT -p ipv6-icmp --icmpv6-type 128 -m comment --comment "Block ICMP Echo flood." -j ICMPFLOOD
  61.  
  62. -4 -A INPUT -p icmp -m comment --comment "Permit ICMP (IPv4)." -j ACCEPT
  63.  
  64. -6 -A INPUT -p ipv6-icmp -m comment --comment "Permit ICMP (IPv6)." -j ACCEPT
  65.  
  66. -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
  67.  
  68. -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]: "
  69.  
  70. COMMIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement