Ergebnis 1 bis 2 von 2
  1. #1
    Mitglied
    Registriert seit
    Mar 2010
    Beiträge
    109

    Standard Frage IPTables

    Hallo,

    ich bin gerade dabei mich mit iptables auseinanderzusetzen bzw. verstehen zu lernen. Es wäre sehr nett, wenn sich jemand mal meine Regeln anschauen könnte. Meine Frage, sind die soweit korrekt (auch Sicherheitsrelevante Fragen)?
    Mein System: Debian6, Apache2, Postfix, Dovecote, Amavis-New, Clamav, spamassassin

    Code:
    #!/bin/bash
    
    
    case "$1" in
    start)
    echo "Starte IP-Paketfilter"
    
    # iptables-Modul
    modprobe ip_tables
    # Connection-Tracking-Module
    modprobe ip_conntrack
    # Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar
    modprobe ip_conntrack_irc
    modprobe ip_conntrack_ftp
    
    # Tabelle flushen
    iptables -F
    iptables -t nat -F
    iptables -t mangle -F
    iptables -X
    iptables -t nat -X
    iptables -t mangle -X
    
    # Default-Policies setzen
    iptables -P INPUT DROP
    iptables -P OUTPUT DROP
    iptables -P FORWARD DROP
    
    # MY_REJECT-Chain
    iptables -N MY_REJECT
    
    # MY_REJECT fuellen
    iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset
    iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable
    iptables -A MY_REJECT -p icmp -j DROP
    iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable
    
    # MY_DROP-Chain
    iptables -N MY_DROP
    iptables -A MY_DROP -j DROP
    
    # Korrupte Pakete zurueckweisen
    iptables -A INPUT -m state --state INVALID -j DROP
    iptables -A OUTPUT -m state --state INVALID -j DROP
    
    # Stealth Scans etc. DROPpen
    # Keine Flags gesetzt
    iptables -A INPUT -p tcp --tcp-flags ALL NONE -j MY_DROP
    
    # SYN und FIN gesetzt
    iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP
    
    # SYN und RST gleichzeitig gesetzt
    iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP
    
    # FIN und RST gleichzeitig gesetzt
    iptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP
    
    # FIN ohne ACK
    iptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP
    
    # PSH ohne ACK
    iptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP
    
    # URG ohne ACK
    iptables -A INPUT -p tcp --tcp-flags ACK,URG URG -j MY_DROP
    
    # Loopback-Netzwerk-Kommunikation zulassen
    iptables -A INPUT -i lo -j ACCEPT
    iptables -A OUTPUT -o lo -j ACCEPT
    
    # Connection-Tracking aktivieren
    iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
    iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    
    # HTTP
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 80 -j ACCEPT
    
    # HTTPS
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 443 -j ACCEPT
    
    # SSH
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 22 -j ACCEPT
    
    # SMTP
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 25 -j ACCEPT
    iptables -A OUTPUT -i eth0 -m state --state NEW -p tcp --dport 25 -j ACCEPT
    
    # SMTP Submission
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 587 -j ACCEPT
    
    # SMTPS
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 465 -j ACCEPT
    
    # POP3
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 110 -j ACCEPT
    
    # POPS
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 995 -j ACCEPT
    
    # IMAP
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 143 -j ACCEPT
    
    # IMAPS
    iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 993 -j ACCEPT
    
    # ICMP
    iptables -A INPUT -p icmp --icmp-type ping -j ACCEPT
    iptables -A OUTPUT -p icmp --icmp-type ping -j ACCEPT
    
    
    # Default-Policies mit REJECT
    #iptables -A INPUT -j MY_REJECT
    #iptables -A OUTPUT -j MY_REJECT
    
    # Max. 500/Sekunde (5/Jiffie) senden
    echo 5 > /proc/sys/net/ipv4/icmp_ratelimit
    
    # Speicherallozierung und -timing für IP-De/-Fragmentierung
    echo 262144 > /proc/sys/net/ipv4/ipfrag_high_thresh
    echo 196608 > /proc/sys/net/ipv4/ipfrag_low_thresh
    echo 30 > /proc/sys/net/ipv4/ipfrag_time
    
    # TCP-FIN-Timeout zum Schutz vor DoS-Attacken setzen
    echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
    
    # Maximal 3 Antworten auf ein TCP-SYN
    echo 3 > /proc/sys/net/ipv4/tcp_retries1
    
    # TCP-Pakete maximal 15x wiederholen
    echo 15 > /proc/sys/net/ipv4/tcp_retries2
    
    ;;
    
    stop)
    echo "Stoppe IP-Paketfilter"
    # Tabelle flushen
    iptables -F
    iptables -t nat -F
    iptables -t mangle -F
    iptables -X
    iptables -t nat -X
    iptables -t mangle -X
    # Default-Policies setzen
    iptables -P INPUT ACCEPT
    iptables -P OUTPUT ACCEPT
    iptables -P FORWARD ACCEPT
    ;;
    
    status)
    echo "Tabelle filter"
    iptables -L -vn
    echo "Tabelle nat"
    iptables -t nat -L -vn
    echo "Tabelle mangle"
    iptables -t mangle -L -vn
    ;;
    
    *)
    echo "Fehlerhafter Aufruf"
    echo "Syntax: $0 {start|stop|status}"
    exit 1
    ;;
    
    esac
    Gruß Hille

  2. #2
    Open Source Kätzchen Avatar von HouseKatZe
    Registriert seit
    Apr 2010
    Ort
    /root
    Beiträge
    1.036
    NewsPresso
    10 (Fachgröße)

    Standard Re: Frage IPTables

    Das sieht für mich soweit okay aus, bis auf:

    Ich weiß nicht was von den Regeln unter "Stealth Scans etc. DROPpen" zu halten ist, reicht das "--state INVALID" darüber nicht? Ausserdem könntest du dort anstatt zu MY_DROP zu jumpen direkt das TCP Reset Paket senden, ist ja immer TCP wieso also das zusätzliche Nachprüfen in der MY_DROP Chain?

    Du solltest ICMP Zulassen! Das hat noch mehr Aufgaben als zu sagen welcher Port geschlossen ist und Pings rumzusenden.

    Dann generell noch: Du nutzt IMAPS/POP3S? Wenn du die nicht-SSL Ports nicht brauchst mach sie dich und binde die Daemons erst gar nicht an die Ports. Den SSH Port würde ich noch ändern (und SSH Keys nutzen) und SYN Cookies würde ich auch noch anmachen.

  3.  
     
     

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •