I'm setting up a server with coturn using only STUN (TURN is disabled). It seems that STUN UDP can be used for DDoS, so I'm trying to set nftables
rules to make it harder, but the rules don't seem to always work. Sometimes, I can see something like this using tcpdump
:
21:16:08.006842 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.007091 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.258386 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.258613 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.278988 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.279229 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.475423 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.475734 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.481217 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.481416 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.484939 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.485211 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.490332 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.490545 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.505617 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.505901 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.529745 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.530020 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.819766 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.820048 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
Which is above the 3/second limit specified on nft
. The nft
rules are:
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
ct state vmap { established : accept, related : accept, invalid : drop }
iifname lo accept
tcp dport 1935 ct state new log prefix "[RTMP]: " accept
tcp dport 443 ct state new log prefix "[HTTPS]: " accept
tcp dport 3478 ct state new log prefix "[STUN TCP]: " limit rate 5/second accept
tcp dport 5349 ct state new log prefix "[STUN TLS]: " limit rate 5/second accept
########################################################################
####### These two rules are where it is not behaving as intended #######
udp dport 3478 log prefix "[STUN UDP]: " limit rate 3/second accept
udp dport 3478 log prefix "[STUN UDP THIS RULE]: " limit rate over 3/second drop
########################################################################
ip saddr E.F.G.H ct state new log prefix "[Some server that is allowed]: " accept
udp dport 5060 ct state new log prefix "[SIP UDP]: " accept
tcp dport 5060 ct state new log prefix "[SIP TCP]: " accept
tcp dport 5061 ct state new log prefix "[SIP TLS]: " accept
udp dport { 5000-31000 } ct state new log prefix "[RTP]: " accept
ip saddr 0.0.0.0 ip daddr 255.255.255.255 udp dport { 67, 68 } ct state new drop
}
chain forward {
type filter hook forward priority 0;
}
chain output {
type filter hook output priority 0;
}
}
There are some additional rules because there are some other services running, but I faced this problem even when the other services using the other ports were stopped.
The strangest thing to me is that there is only one mention about these packets on dmesg
:
[4151543.207466] [STUN UDP]: IN=eth0 OUT= MAC=00:00:00:00:00:00:d4:c1:9e:0b:4d:c0:08:00 SRC=5.39.71.183 DST=A.B.C.D LEN=48 TOS=0x00 PREC=0x00 TTL=241 ID=31022 PROTO=UDP SPT=25565 DPT=3478 LEN=28
It's very likely I'm not understanding something, either about nftables
, STUN, both or something else. The questions:
Is the order of the rules wrong? Like, the STUN UDP rules should be before the
ct state vmap
line?With the
nftables
rule setting the 3/second limit, with no consideration about the state of the packet, shouldn't it be processed on every packet received on port 3478?
Or maybe it's something else I have not identified that is making the nftables
limit not be applied.
System information:
OS: Debian 11
coturn version: 4.5.2-3 from the Debian repository.
nftables version: v0.9.8 (E.D.S.) from the Debian repository.