#!/bin/sh # # Przykladowy plik z regulami dla iptables (Linux). # # Krzysztof Kozlowski http://www.kozik.net.pl # krzysztof [dot] kozlowski [ at ] kozik [dot] net [dot] pl # # # Licencja: GNU General Public License # # Ostatnia zmiana: 2.03.2006 # # ################ Poczatek regul ####################################### iptables -F iptables -X iptables -N icmp_allowed_in iptables -N icmp_allowed_out iptables -F icmp_allowed_in iptables -F icmp_allowed_out iptables -N established_connections iptables -F established_connections iptables -N check_flags iptables -F check_flags iptables -N our_services iptables -F our_services # ####################################################################### # Policy : iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP # ####################################################################### # Loopback : iptables -A INPUT -i lo -j ACCEPT iptables -A FORWARD -o lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT # ####################################################################### # Ruch ICMP # icmp_allowed_in - dozwolony ruch ICMP przychodzacy do maszyny # icmp_allowed_out - dozwolony ruch ICMP wychodzacy z maszyny iptables -A icmp_allowed_in -p icmp --icmp-type time-exceeded -j ACCEPT iptables -A icmp_allowed_in -p icmp --icmp-type destination-unreachable -j ACCEPT iptables -A icmp_allowed_in -p icmp --icmp-type echo-reply -j ACCEPT iptables -A icmp_allowed_in -p icmp --icmp-type parameter-problem -j ACCEPT iptables -A icmp_allowed_in -p icmp --icmp-type timestamp-reply -j ACCEPT iptables -A icmp_allowed_out -p icmp --icmp-type echo-request -j ACCEPT iptables -A icmp_allowed_out -p icmp --icmp-type destination-unreachable -j ACCEPT iptables -A icmp_allowed_out -p icmp --icmp-type time-exceeded -j ACCEPT iptables -A icmp_allowed_out -p icmp --icmp-type parameter-problem -j ACCEPT iptables -A icmp_allowed_out -p icmp --icmp-type timestamp-request -j ACCEPT iptables -A icmp_allowed_in -p icmp -j LOG --log-prefix "ICMP: " iptables -A icmp_allowed_in -p icmp -j DROP iptables -A icmp_allowed_out -p icmp -j LOG --log-prefix "ICMP: " iptables -A icmp_allowed_out -p icmp -j DROP # ####################################################################### # Wszystkie na uprzywilejowane DROP : # lokalny serwer FTP (przedzial pasywnych portow: 10000-10100) : iptables -A our_services -p TCP -d 0/0 --dport 20:21 -j ACCEPT iptables -A our_services -p TCP -d 0/0 --dport 10000:10100 -j ACCEPT # Lokalny WWW: # iptables -A our_services -p TCP -d 0/0 --dport 80 -j ACCEPT # Wszystkie na uprzywilejowane DROP : iptables -A our_services -p TCP -d 0/0 --dport 0:1023 -j DROP iptables -A our_services -p UDP -d 0/0 --dport 0:1023 -j DROP # Pozostale stale otwarte porty : # Klient aMule : iptables -A our_services -p TCP --dport 4662 -j ACCEPT iptables -A our_services -p UDP --dport 4662 -j ACCEPT iptables -A our_services -p TCP --dport 4665 -j ACCEPT iptables -A our_services -p UDP --dport 4665 -j ACCEPT iptables -A our_services -p TCP --dport 4672 -j ACCEPT iptables -A our_services -p UDP --dport 4672 -j ACCEPT # Klient bittorrent : iptables -A our_services -p TCP --dport 6881 -j ACCEPT iptables -A our_services -p UDP --dport 6881 -j ACCEPT # Klient FTP (klienckie polaczenia - konieczne) : iptables -A our_services -p TCP --sport 20 -j ACCEPT # ####################################################################### # Catch portscanners # Z Gentoo Handbook : # http://www.gentoo.org/doc/en/security/security-handbook.xml?part=1&chap=12 iptables -A check_flags -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit 5/minute -j LOG --log-level alert --log-prefix "NMAP-XMAS:" iptables -A check_flags -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP iptables -A check_flags -p tcp --tcp-flags ALL ALL -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "XMAS:" iptables -A check_flags -p tcp --tcp-flags ALL ALL -j DROP iptables -A check_flags -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "XMAS-PSH:" iptables -A check_flags -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP iptables -A check_flags -p tcp --tcp-flags ALL NONE -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "NULL_SCAN:" iptables -A check_flags -p tcp --tcp-flags ALL NONE -j DROP iptables -A check_flags -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit 5/minute -j LOG --log-level 5 --log-prefix "SYN/RST:" iptables -A check_flags -p tcp --tcp-flags SYN,RST SYN,RST -j DROP iptables -A check_flags -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/minute -j LOG --log-level 5 --log-prefix "SYN/FIN:" iptables -A check_flags -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP # ####################################################################### # Reguly statefull: iptables -A established_connections -m state --state ESTABLISHED,RELATED -j ACCEPT # ####################################################################### # Ruch przychodzacy - ICMP, skany i puszczamy TYLKO nawiazane # polaczenia (established_connections) #iptables -A INPUT -m state --state INVALID -j LOG --log-prefix "Invalid STATE: " # nieuzywane #iptables -A INPUT -m state --state INVALID -j DROP # nieuzywane iptables -A INPUT -j icmp_allowed_in iptables -A INPUT -j check_flags iptables -A INPUT -j our_services iptables -A INPUT -j established_connections # ####################################################################### # Ruch wychodzacy - ICMP i reszte puszczamy #iptables -A OUTPUT -m state --state INVALID -j LOG --log-prefix "Invalid STATE: " # nieuzywane #iptables -A OUTPUT -m state --state INVALID -j DROP # nieuzywane iptables -A OUTPUT -j icmp_allowed_out iptables -A OUTPUT -j ACCEPT