nftables für Basis Keyhelp Installation  [GELÖST]

Locked
User avatar
Moritz83
Posts: 38
Joined: Sun 26. Jul 2020, 18:01

nftables für Basis Keyhelp Installation

Post by Moritz83 »

Servus,
ich versuche nun seit Tagen mich ein wenig in die "nftables" Thematik einzuarbeiten in der Hoffnung, eine Art "Grundkonfiguration" zu erstellen, sprich eine conf Datei die man direkt bei Neuinstallation von Keyhelp (für Server mit öffentlicher IP) nutzen kann und die alle mit Keyhelp installierten Dienste (+ SSH) erstmal grundlegend abdeckt. Mal abgesehen davon das ich nicht wirklich viel Ahnung von Firewalls habe (Grundverständniss der Funktionsweise ja, danach wirds düster) sind auch die Informationen teilweise so kryptisch für den Laien das ich nicht wirklich dahinter steige. Ich bin mit der Forumssuche auch über diesen
Thread gestolpert aber ich wollte nun nix kopieren wenn ich nicht weiss ob das auf meinen Fall auch zutrifft

Mein "Flickwerk" sieht mittlerweile so aus

Code: Select all

#!/usr/sbin/nft -f

flush ruleset

table inet filter {
        chain input {
                type filter hook input priority 0;

                # allow from loopback
                iifname lo accept;

                # established/related connections
                ct state established,related accept;

                # invalid connections
                ct state invalid drop;

                # no ping floods
                ip6 nexthdr icmpv6 icmpv6 type echo-request limit rate 2/second accept;
                ip protocol icmp icmp type echo-request limit rate 2/second accept;

                tcp dport ssh ip saddr MEINEIP accept;
                tcp dport {http, https, ftp, smtp, pop3, pop3s, imap, imaps} accept;

                policy drop;
        }
        chain forward {
                type filter hook forward priority 0;
        }
        chain output {
                type filter hook output priority 0;
        }
}
Was muss ich hier noch ändern um einen Grundschutz zu erreichen?
Denke ihr kennt euch hier viel besser aus als ich - wäre echt dankbar für eure Unterstützung ;)

(nf_conntrack und nf_conntrack_ftp habe ich bereits aktiviert - gibt es hier sonst noch etwas spezielles was ich wissen sollte?)
User avatar
Moritz83
Posts: 38
Joined: Sun 26. Jul 2020, 18:01

Re: nftables für Basis Keyhelp Installation  [GELÖST]

Post by Moritz83 »

Habe ein wenig rumgebastelt und eine für mich (zumindest auf dem Papier --- ist noch nicht getestet!!) mehr oder weniger schlüssige Möglichkeit gefunden die nftables.conf aufzubauen dank der Hilfe mehrerer Beispiele aus dem Netz. Vielleicht kann sich einer der Profis hier das mal anschauen und ggf. Verbesserungen oder Veränderungen vorschlagen. Danke euch im Vorraus :)

Code: Select all

#!/usr/sbin/nft -f

# Start by flushing all the rules.
flush ruleset

# Define private IP for ssh access
define privateip = {1.1.1.1}

table inet filter {
    # TCP ports to allow. (Allowed services: HTTP, HTTPS)
    set tcp_accepted {
        type inet_service; flags interval;
        elements = {
        80,443
        }
    }
    # TCP port for SSH service.
    set ssh_accepted {
        type inet_service; flags interval;
        elements = {
        721
        }
    }
    # UDP ports to allow.
    set udp_accepted {
        type inet_service; flags interval;
        elements = {
        
        }
    }
    chain input {
        # This line set what traffic the chain will handle, the priority and default policy.
        # The priority comes in when you in another table have a chain set to "hook input" and want to specify in what order they should run.
        # Use a semicolon to separate multiple commands on one row.
        type filter hook input priority 0; policy drop;

        # Limit ping requests. (Limit rules need to be put before accepting "established" connections)
        ip protocol icmp icmp type echo-request limit rate over 1/second burst 5 packets drop
        ip6 nexthdr icmpv6 icmpv6 type echo-request limit rate over 1/second burst 5 packets drop

        # Allow all incomming established and related traffic. Drop invalid traffic.
        ct state established,related accept
        ct state invalid drop

        # Allow loopback.
        iif lo accept

        # Drop all fragments.
        ip frag-off & 0x1fff != 0 counter drop

        # Force SYN checks.
        tcp flags & (fin|syn|rst|ack) != syn ct state new counter drop

        # Drop XMAS packets.
        tcp flags & (fin|syn|rst|psh|ack|urg) == fin|syn|rst|psh|ack|urg counter drop

        # Drop NULL packets.
        tcp flags & (fin|syn|rst|psh|ack|urg) == 0x0 counter drop

        # Allow certain inbound ICMP types (ping, traceroute).
        # Without the nd-* ones ipv6 will not work.
        ip protocol icmp icmp type { destination-unreachable, echo-reply, echo-request, source-quench, time-exceeded } accept      
        ip6 nexthdr icmpv6 icmpv6 type { destination-unreachable, echo-reply, echo-request, nd-neighbor-solicit,  nd-router-advert, nd-neighbor-advert, packet-too-big, parameter-problem, time-exceeded } accept

        # Allow SSH for specific IP only
        iifname $privateip tcp dport @ssh_accepted ct state new accept

        # Allow needed tcp and udp ports.
        tcp dport @tcp_accepted ct state new accept
        udp dport @udp_accepted ct state new accept
    }
    chain forward {
        type filter hook forward priority 0; policy drop;

        # Forward all established and related traffic. Drop invalid traffic.
        ct state established,related accept
        ct state invalid drop
    }
    chain output {
        type filter hook output priority 0; policy drop;

        # Allow all outgoing traffic. Drop invalid traffic.
        # ipv6 ICMP needs to be explicitly allowed here.
        ip6 nexthdr ipv6-icmp accept
        ct state new,established,related accept
        ct state invalid drop
    }
}
PS: Natürlich bin ich auch für reine Anmerkungen zum besseren Verständnis immer dankbar ;)
Locked