Observation-only nftables table (prerouting -150, counters and a rate-limited log, never drops or modifies), a per-minute counters file, probe sources ingress and ingresscnt, a per-host hourly aggregate in the hub (exact totals, sampled ports/ASNs/countries, banned share by the hub's own ban state, no ban feedback loop), GET /api/v1/ingress, a Defense section, doctor check, docs EN/pt-BR and tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
86 lines
3.0 KiB
Plaintext
86 lines
3.0 KiB
Plaintext
#!/usr/sbin/nft -f
|
|
# Urutau: OBSERVES new inbound connection attempts that reach this host from
|
|
# outside (the "firewall" telemetry): TCP SYN without ACK, UDP and ICMP echo
|
|
# requests. Nothing else.
|
|
#
|
|
# It never drops, accepts, marks or rewrites a packet: every statement here is a
|
|
# counter, a rate limit that only gates the log statement, or a jump. Policy is
|
|
# accept and the chain does not touch established traffic.
|
|
#
|
|
# The chain hooks at prerouting priority -150: after the conntrack lookup, before
|
|
# Docker's DNAT (-100). Packets to DNAT'ed container ports and packets from
|
|
# sources that fail2ban or Urutau ban a moment later (and drop in INPUT or
|
|
# FORWARD, far past this hook) are all seen here.
|
|
#
|
|
# EXACT totals come from the named counters (read once a minute by
|
|
# urutau-ingress-tick, appended to /var/log/urutau/ingress.counters). The log
|
|
# lines are only a SAMPLE for details (ports, origins); the rate limits below
|
|
# decide how big the sample is. @WAN@ is replaced by the uplink interface.
|
|
#
|
|
# Not counted: anything that does not arrive on the uplink (loopback, Docker
|
|
# bridges, VPN), anything not addressed to this host, and sources that are
|
|
# loopback, private, link-local, CGNAT, multicast or one of this host's own
|
|
# addresses.
|
|
table inet urutau_ingress
|
|
delete table inet urutau_ingress
|
|
|
|
table inet urutau_ingress {
|
|
# Ports this host serves (listening sockets, including the ones Docker
|
|
# publishes), refreshed every minute by urutau-ingress-tick.
|
|
set open { type inet_proto . inet_service; }
|
|
|
|
counter in_total { }
|
|
counter in_tcp { }
|
|
counter in_udp { }
|
|
counter in_icmp { }
|
|
counter in_open { }
|
|
|
|
chain observe {
|
|
type filter hook prerouting priority -150; policy accept;
|
|
iifname != "@WAN@" return
|
|
fib daddr type != local return
|
|
fib saddr . iif type local return
|
|
ip saddr { 0.0.0.0/8, 10.0.0.0/8, 100.64.0.0/10, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.168.0.0/16, 224.0.0.0/3 } return
|
|
ip6 saddr { ::/128, ::1/128, fc00::/7, fe80::/10, ff00::/8 } return
|
|
meta l4proto tcp tcp flags & (syn | ack) == syn jump new_tcp
|
|
meta l4proto udp ct state new jump new_udp
|
|
meta l4proto icmp icmp type echo-request jump new_icmp
|
|
meta l4proto icmpv6 icmpv6 type echo-request jump new_icmp
|
|
}
|
|
|
|
chain new_tcp {
|
|
counter name in_total
|
|
counter name in_tcp
|
|
jump classify
|
|
}
|
|
|
|
chain new_udp {
|
|
counter name in_total
|
|
counter name in_udp
|
|
jump classify
|
|
}
|
|
|
|
chain new_icmp {
|
|
counter name in_total
|
|
counter name in_icmp
|
|
limit rate 2/second burst 10 packets log prefix "URUTAU-IN: " level info
|
|
}
|
|
|
|
# open vs closed: the open ones are counted, closed = (tcp + udp) - open,
|
|
# computed by urutau-ingress-tick, so the chain needs no negated lookup.
|
|
chain classify {
|
|
meta l4proto . th dport @open counter name in_open jump sample_open
|
|
meta l4proto . th dport @open return
|
|
jump sample_closed
|
|
}
|
|
|
|
# the sample: a ceiling that only gates the log statement
|
|
chain sample_open {
|
|
limit rate 5/second burst 25 packets log prefix "URUTAU-INO: " level info
|
|
}
|
|
|
|
chain sample_closed {
|
|
limit rate 10/second burst 50 packets log prefix "URUTAU-IN: " level info
|
|
}
|
|
}
|