Files
urutau/deploy/host/urutau-egress.nft
T
Lucas RayanandClaude Opus 5.5 432f521ed1
Release / Publish tags (push) Successful in 18s
Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Successful in 1m47s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 28s
CI / Format and vet (push) Successful in 23s
CI / Tests (Linux, race detector) (push) Successful in 1m24s
CI / Dependency audit (push) Successful in 24s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 5s
feat: 1.4.1 pagination, network probes, survival by blocker, report polish
Backend pagination with one pager for sessions, IPs, campaigns and events;
network probe source (port-scan, T1046, second firewall reason port-scan);
host kit logs inbound probes; urutau call on the report cover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 00:21:43 -03:00

64 lines
3.7 KiB
Plaintext

#!/usr/sbin/nft -f
# Urutau: logs NEW outbound connections (host and containers), and inbound
# probes to closed ports, so the egress
# analysis can spot beaconing, mining, spam and unauthorised scans.
# Lives in its own table: it never touches the iptables-nft tables of Docker
# or fail2ban, and it only logs (policy accept, no drop).
# @WAN@ is replaced by the uplink interface by install.sh.
#
# Volume control without blinding the beacon detector:
# - a (source, destination, protocol, port) seen in the last 2 h is ALWAYS
# logged (a beacon repeats the same pair, so a ceiling never hides it);
# - a NEW pair is logged under a per-source ceiling of 20/s (burst 100): an
# authorised scan (thousands of new pairs) is capped, and one noisy
# workload never eats the budget of the others.
table inet urutau_egress
delete table inet urutau_egress
table inet urutau_egress {
set rl4 { type ipv4_addr; flags dynamic; timeout 2m; size 65535; }
set rl6 { type ipv6_addr; flags dynamic; timeout 2m; size 65535; }
set seen4 { type ipv4_addr . ipv4_addr . inet_proto . inet_service; flags dynamic, timeout; timeout 2h; size 131072; }
set seen6 { type ipv6_addr . ipv6_addr . inet_proto . inet_service; flags dynamic, timeout; timeout 2h; size 131072; }
chain egress {
# known pair: always log, refresh its timer
meta nfproto ipv4 meta l4proto { tcp, udp } ip saddr . ip daddr . meta l4proto . th dport @seen4 update @seen4 { ip saddr . ip daddr . meta l4proto . th dport } log prefix "URUTAU-EGRESS: " level info return
meta nfproto ipv6 meta l4proto { tcp, udp } ip6 saddr . ip6 daddr . meta l4proto . th dport @seen6 update @seen6 { ip6 saddr . ip6 daddr . meta l4proto . th dport } log prefix "URUTAU-EGRESS: " level info return
# new pair: per-source ceiling, then remember it
meta nfproto ipv4 meta l4proto { tcp, udp } add @rl4 { ip saddr limit rate 20/second burst 100 packets } add @seen4 { ip saddr . ip daddr . meta l4proto . th dport } log prefix "URUTAU-EGRESS: " level info return
meta nfproto ipv6 meta l4proto { tcp, udp } add @rl6 { ip6 saddr limit rate 20/second burst 100 packets } add @seen6 { ip6 saddr . ip6 daddr . meta l4proto . th dport } log prefix "URUTAU-EGRESS: " level info return
# other protocols (ICMP...) under the same ceiling, not remembered
meta nfproto ipv4 meta l4proto != { tcp, udp } add @rl4 { ip saddr limit rate 20/second burst 100 packets } log prefix "URUTAU-EGRESS: " level info
meta nfproto ipv6 meta l4proto != { tcp, udp } add @rl6 { ip6 saddr limit rate 20/second burst 100 packets } log prefix "URUTAU-EGRESS: " level info
}
# inbound probes: NEW connections to ports nobody listens on (port scans,
# RDP/SMB/database probing). @open is refreshed every minute by
# urutau-containers-map from `ss` (it also sees ports Docker publishes).
set open { type inet_proto . inet_service; }
set prl4 { type ipv4_addr; flags dynamic; timeout 2m; size 65535; }
set prl6 { type ipv6_addr; flags dynamic; timeout 2m; size 65535; }
chain probe_log {
type filter hook prerouting priority -150; policy accept;
iifname != "@WAN@" return
ct state != new return
meta l4proto != { tcp, udp } return
fib daddr type != local return
meta l4proto . th dport @open return
meta nfproto ipv4 add @prl4 { ip saddr limit rate 10/second burst 50 packets } log prefix "URUTAU-PROBE: " level info
meta nfproto ipv6 add @prl6 { ip6 saddr limit rate 10/second burst 50 packets } log prefix "URUTAU-PROBE: " level info
}
chain forward_log {
type filter hook forward priority filter - 10; policy accept;
ct state new oifname "@WAN@" iifname != "@WAN@" jump egress
}
chain output_log {
type filter hook output priority filter - 10; policy accept;
ct state new oifname "@WAN@" jump egress
}
}