From 3e23b80e9cb42b73dd46669f5b67fddcf6686802 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 1 Apr 2024 19:40:46 -0400 Subject: [PATCH] move mail server HTTP(S) connection limit to nftables This has the same reasoning as 9fcac6b105274c308a3c59955b40985f4e60a905 other than these services being used for MTA-STS in addition to ACME and redirects to the FAQ for the domains. --- nftables-mail.conf | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/nftables-mail.conf b/nftables-mail.conf index 71ae92b..04acd8b 100644 --- a/nftables-mail.conf +++ b/nftables-mail.conf @@ -21,6 +21,16 @@ table inet filter { flags dynamic } + set ip-connlimit-http { + type ipv4_addr + flags dynamic + } + + set ip6-connlimit-http { + type ipv6_addr + flags dynamic + } + chain prerouting-raw { type filter hook prerouting priority raw @@ -32,8 +42,8 @@ table inet filter { # drop packets to address not configured on incoming interface (strong host model) fib daddr . iif type != { local, broadcast, multicast } counter drop - tcp dport { 25, 80, 443, 465, 993 } notrack accept - tcp dport 22 tcp flags syn notrack accept + tcp dport { 25, 465, 993 } notrack accept + tcp dport { 22, 80, 443 } tcp flags syn notrack accept meta l4proto { icmp, ipv6-icmp } notrack accept } @@ -41,7 +51,7 @@ table inet filter { type filter hook output priority raw oif lo notrack accept - tcp sport { 25, 80, 443, 465, 993 } notrack accept + tcp sport { 25, 465, 993 } notrack accept meta l4proto { icmp, ipv6-icmp } notrack accept } @@ -50,18 +60,22 @@ table inet filter { policy drop iif lo goto input-loopback - tcp dport { 25, 80, 443, 465, 993 } accept + tcp dport { 25, 465, 993 } accept meta l4proto { icmp, ipv6-icmp } accept ct state vmap { established : accept, related : accept, new : goto graceful-reject } tcp dport 22 ip saddr @ip-connlimit-ssh counter reject with tcp reset tcp dport 22 ip6 saddr and ffff:ffff:ffff:ffff:ffff:: @ip6-connlimit-ssh counter reject with tcp reset - tcp dport 22 synproxy mss 1460 wscale 7 timestamp sack-perm + tcp dport { 80, 443 } ip saddr @ip-connlimit-http counter reject with tcp reset + tcp dport { 80, 443 } ip6 saddr and ffff:ffff:ffff:ffff:: @ip6-connlimit-http counter reject with tcp reset + tcp dport { 22, 80, 443 } synproxy mss 1460 wscale 7 timestamp sack-perm } chain input-loopback { tcp dport 22 tcp flags syn ip saddr != $ip-allowlist-ssh add @ip-connlimit-ssh { ip saddr ct count over 1 } counter reject with tcp reset tcp dport 22 tcp flags syn ip6 saddr != $ip6-allowlist-ssh add @ip6-connlimit-ssh { ip6 saddr and ffff:ffff:ffff:ffff:ffff:: ct count over 1 } counter reject with tcp reset + tcp dport { 80, 443 } tcp flags syn add @ip-connlimit-http { ip saddr ct count over 32 } counter reject with tcp reset + tcp dport { 80, 443 } tcp flags syn add @ip6-connlimit-http { ip6 saddr and ffff:ffff:ffff:ffff:: ct count over 32 } counter reject with tcp reset accept }