Merge pull request 'fix(egress): container map refreshed on start; no new_geo for anycast CDNs (2.2.2)' (#4) from fix/egress-attribution-anycast into main
CI / Format and vet (push) Successful in 1m21s
CI / Dependency audit (push) Successful in 47s
CI / Tests (Linux, race detector) (push) Successful in 2m26s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build hub image (amd64) (push) Skipped
Release / Build probe image (amd64) (push) Skipped
Release / Build hub image (arm64) (push) Skipped
Release / Build probe image (arm64) (push) Skipped
Release / Publish tags (probe) (push) Successful in 21s
Release / Publish tags (hub) (push) Successful in 21s
Release / Gitea release (push) Successful in 4s

This commit was merged in pull request #4.
This commit is contained in:
lucasrguerra committed 2026-11-19 18:43:51 +00:00
commit 4143bf599e
17 files changed
+81 -14

No files matched your search

+7
View File
@@ -6,6 +6,13 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versio
## [Unreleased]
## [2.2.2] - 2026-11-19
### Fixed
- Outbound traffic: a redeploy that swapped addresses between containers (LambdaMail's rspamd and clamav traded 172.19.0.2 and .5) was judged with the previous minute's `containers.map`, so findings landed on the wrong workload (rspamd's SURBL and DNS traffic as `clamav`, freshclam as `dns`). The host kit now also runs `urutau-containers-watch`, which rewrites the map on every container start or network attach, and the probe checks the file every 2 seconds instead of 10. Reinstall the host kit (`deploy/host/install.sh`) and update the probes.
- Outbound traffic: `new_geo` no longer fires for large CDNs and clouds (Cloudflare, Google, AWS, Azure, Akamai, Fastly, Telegram): their addresses are anycast or global, and the database country (1.1.1.1 in Australia, a Cloudflare edge in Canada) says nothing about where the traffic goes. Test `TestNewGeoSkipsAnycastCDN`.
## [2.2.1] - 2026-11-16
### Fixed
+7
View File
@@ -6,6 +6,13 @@ Formato baseado no [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/);
## [Não lançado]
## [2.2.2] - 2026-11-19
### Corrigido
- Tráfego de saída: um redeploy que trocou endereços entre contêineres (o rspamd e o clamav do LambdaMail trocaram 172.19.0.2 e .5) era julgado com o `containers.map` do minuto anterior, e os achados caíam no workload errado (SURBL e DNS do rspamd como `clamav`, freshclam como `dns`). O kit do host agora também roda o `urutau-containers-watch`, que regrava o mapa a cada contêiner que sobe ou entra numa rede, e a sonda confere o arquivo a cada 2 segundos em vez de 10. Reinstale o kit do host (`deploy/host/install.sh`) e atualize as sondas.
- Tráfego de saída: `new_geo` não dispara mais para grandes CDNs e nuvens (Cloudflare, Google, AWS, Azure, Akamai, Fastly, Telegram): os endereços são anycast ou globais, e o país da base (1.1.1.1 na Austrália, uma borda da Cloudflare no Canadá) nada diz sobre o destino do tráfego. Teste `TestNewGeoSkipsAnycastCDN`.
## [2.2.1] - 2026-11-16
### Corrigido
+1 -1
View File
@@ -87,7 +87,7 @@ It never blocks trusted addresses, private ranges, CDN (Cloudflare) and public r
## Outbound traffic and incidents
Optional (`URUTAU_EGRESS=auto|on|off`; `auto` turns it on for a probe that sends the outbound log). The host kit logs only new TCP connection attempts through nftables, and a container map names the workloads. Urutau checks them for beaconing (regular conversations with one destination), mining, IRC and SMTP ports, contact with addresses that attacked the server or with Tor relays, DNS outside the allowed resolvers (`URUTAU_EGRESS_RESOLVERS`), unauthorised outbound scans and new countries. Workloads are defined by network or container name (`URUTAU_EGRESS_WORKLOADS`); a `scanner` workload (an authorised surface scanner) has only its scan-shaped traffic summarised, everything else is judged like any other workload. The servers themselves, peers and the host's own provider never raise findings, cloud metadata services polled by the host are `infra`, and regular connections to large CDNs and clouds are low severity.
Optional (`URUTAU_EGRESS=auto|on|off`; `auto` turns it on for a probe that sends the outbound log). The host kit logs only new TCP connection attempts through nftables, and a container map names the workloads. Urutau checks them for beaconing (regular conversations with one destination), mining, IRC and SMTP ports, contact with addresses that attacked the server or with Tor relays, DNS outside the allowed resolvers (`URUTAU_EGRESS_RESOLVERS`), unauthorised outbound scans and new countries. Workloads are defined by network or container name (`URUTAU_EGRESS_WORKLOADS`); a `scanner` workload (an authorised surface scanner) has only its scan-shaped traffic summarised, everything else is judged like any other workload. The servers themselves, peers and the host's own provider never raise findings, cloud metadata services polled by the host are `infra`, and regular connections to large CDNs and clouds are low severity, and they never raise a new country (their database country means nothing for anycast).
Every finding above info severity becomes a ticket `INC-<n>` (list, ticket page, manual tickets, CSV export, `/api/v1/incidents`). A ticket marked `false_positive` or `benign` can suppress findings with exactly its key; a resolved ticket reopens if the finding comes back.
+1 -1
View File
@@ -87,7 +87,7 @@ Nunca bloqueia endereços confiáveis, faixas privadas, faixas de CDN (Cloudflar
## Tráfego de saída e incidentes
Opcional (`URUTAU_EGRESS=auto|on|off`; `auto` liga para a sonda que envia o log de saída). O kit de host registra, pelo nftables, só tentativas novas de conexão TCP, e um mapa de contêineres nomeia os workloads. O Urutau checa beaconing (conversas regulares com um destino), mineração, portas de IRC e SMTP, contato com endereços que atacaram o servidor ou com relays Tor, DNS fora dos resolvers permitidos (`URUTAU_EGRESS_RESOLVERS`), varreduras de saída não autorizadas e países novos. Os workloads são definidos por nome de rede ou de contêiner (`URUTAU_EGRESS_WORKLOADS`); um workload `scanner` (um scanner de superfície autorizado) tem só o tráfego em forma de varredura resumido, o resto é julgado como qualquer outro workload. Os próprios servidores, peers e o provedor do host nunca geram achados, serviços de metadados de nuvem consultados pelo host são `infra`, e conexões regulares a grandes CDNs e nuvens têm severidade baixa.
Opcional (`URUTAU_EGRESS=auto|on|off`; `auto` liga para a sonda que envia o log de saída). O kit de host registra, pelo nftables, só tentativas novas de conexão TCP, e um mapa de contêineres nomeia os workloads. O Urutau checa beaconing (conversas regulares com um destino), mineração, portas de IRC e SMTP, contato com endereços que atacaram o servidor ou com relays Tor, DNS fora dos resolvers permitidos (`URUTAU_EGRESS_RESOLVERS`), varreduras de saída não autorizadas e países novos. Os workloads são definidos por nome de rede ou de contêiner (`URUTAU_EGRESS_WORKLOADS`); um workload `scanner` (um scanner de superfície autorizado) tem só o tráfego em forma de varredura resumido, o resto é julgado como qualquer outro workload. Os próprios servidores, peers e o provedor do host nunca geram achados, serviços de metadados de nuvem consultados pelo host são `infra`, e conexões regulares a grandes CDNs e nuvens têm severidade baixa e nunca geram país novo (o país da base nada diz sobre anycast).
Todo achado acima de info vira um chamado `INC-<n>` (lista, página do chamado, chamados manuais, exportação CSV, `/api/v1/incidents`). Um chamado marcado `false_positive` ou `benign` pode suprimir achados com exatamente a sua chave; um chamado resolvido reabre se o achado voltar.
+6 -3
View File
@@ -35,9 +35,10 @@ done
[ "$(id -u)" = 0 ] || { echo "run as root" >&2; exit 1; }
if [ "$remove" = 1 ]; then
systemctl disable --now urutau-egress.service urutau-containers-map.timer urutau-logrotate.timer urutau-unban.path 2>/dev/null || true
systemctl disable --now urutau-egress.service urutau-containers-watch.service urutau-containers-map.timer urutau-logrotate.timer urutau-unban.path 2>/dev/null || true
rm -f /etc/systemd/system/urutau-egress.service /etc/systemd/system/urutau-containers-map.service \
/etc/systemd/system/urutau-containers-map.timer /usr/local/sbin/urutau-containers-map \
/etc/systemd/system/urutau-containers-watch.service /usr/local/sbin/urutau-containers-watch \
/etc/rsyslog.d/41-urutau-egress.conf /etc/logrotate.d/urutau-egress \
/etc/fail2ban/jail.d/urutau.local /etc/fail2ban/filter.d/urutau.conf /etc/fail2ban/action.d/urutau-allports.conf \
/etc/systemd/system/urutau-logrotate.service /etc/systemd/system/urutau-logrotate.timer \
@@ -62,14 +63,16 @@ nft -c -f /etc/urutau/egress.nft
install -m 0644 "$here/41-urutau-egress.conf" /etc/rsyslog.d/41-urutau-egress.conf
install -m 0644 "$here/urutau.logrotate" /etc/logrotate.d/urutau-egress
install -m 0755 "$here/urutau-containers-map" /usr/local/sbin/urutau-containers-map
install -m 0755 "$here/urutau-containers-watch" /usr/local/sbin/urutau-containers-watch
install -m 0644 "$here/urutau-egress.service" "$here/urutau-containers-map.service" \
"$here/urutau-containers-map.timer" "$here/urutau-logrotate.service" "$here/urutau-logrotate.timer" /etc/systemd/system/
"$here/urutau-containers-map.timer" "$here/urutau-containers-watch.service" "$here/urutau-logrotate.service" "$here/urutau-logrotate.timer" /etc/systemd/system/
systemctl daemon-reload
systemctl restart rsyslog
systemctl enable urutau-egress.service urutau-containers-map.timer urutau-logrotate.timer >/dev/null
systemctl enable urutau-egress.service urutau-containers-map.timer urutau-containers-watch.service urutau-logrotate.timer >/dev/null
systemctl start urutau-logrotate.timer
systemctl restart urutau-egress.service
systemctl start urutau-containers-map.service urutau-containers-map.timer
systemctl restart urutau-containers-watch.service
echo "egress logging on $wan: /var/log/urutau/egress.log, map: /var/log/urutau/containers.map"
if [ "$probe" = 1 ] && [ "$enforce" = 0 ]; then
+13
View File
@@ -0,0 +1,13 @@
#!/bin/bash
# Urutau: rewrites containers.map as soon as Docker attaches a container to a
# network, so a redeploy that swaps addresses between containers is not judged
# with the old names until the next minute of the timer.
set -u
docker events --filter type=network --filter event=connect --filter type=container --filter event=start --format '{{.Type}}' |
while read -r _; do
/usr/local/sbin/urutau-containers-map || true
# a stack redeploy fires dozens of events: drain the burst, then refresh once more
n=0
while read -r -t 1 _; do n=$((n + 1)); done
[ "$n" -gt 0 ] && { /usr/local/sbin/urutau-containers-map || true; }
done
@@ -0,0 +1,12 @@
[Unit]
Description=Urutau: refresh the container map when containers start
After=docker.service
Requires=docker.service
[Service]
ExecStart=/usr/local/sbin/urutau-containers-watch
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target
+1 -1
View File
@@ -96,7 +96,7 @@ The probe has only these variables (flags in [cli.md](cli.md#urutau-probe)). A p
| `URUTAU_FAIL2BAN_LOG` | `/logs/host/fail2ban.log` | fail2ban log |
| `URUTAU_PROBE_LOG` | `/logs/host/probe.log` | kernel log of connections to unserved ports, written by the host kit (see [Probes](#probes-port-scans)) |
| `URUTAU_EGRESS_LOG` | `/logs/host/egress.log` | kernel log of new outbound connections, written by the host kit |
| `URUTAU_EGRESS_CONTAINERS` | `/logs/host/containers.map` | `"<ip> <container>"` map written by the host kit every minute, so workloads keep their name when the address changes on a redeploy; sent whole when it changes |
| `URUTAU_EGRESS_CONTAINERS` | `/logs/host/containers.map` | `"<ip> <container>"` map written by the host kit when a container starts (and every minute), so workloads keep their name when the address changes on a redeploy; sent whole when it changes |
| `URUTAU_RESOLV` | `/etc/resolv.conf` of the host (mounted) | resolvers of the host, sent whole when it changes |
| `URUTAU_ENFORCE_LOG` | `/logs/enforce/decisions.log` | file where the ban decisions of the hub are appended, read by the host jail; empty ignores ban commands and counts them as errors |
| `URUTAU_ENFORCE_UNBAN_LOG` | `/logs/enforce/unban.log` | file where unban requests are appended, read by the host; empty ignores them |
+1 -1
View File
@@ -179,7 +179,7 @@ It is idempotent. `URUTAU_WAN` overrides the detected uplink interface and `URUT
|---|---|
| egress logging | nftables table `inet urutau_egress` (`/etc/urutau/egress.nft`, only logs, never drops, separate from the Docker and fail2ban tables) and the `urutau-egress.service` unit; rsyslog rule `41-urutau-egress.conf` sends the kernel lines to `/var/log/urutau/egress.log` (`URUTAU-EGRESS:`) and `/var/log/urutau/probe.log` (`URUTAU-PROBE:`); logrotate daily, 7 copies, at most 200 MB (`urutau-logrotate.timer`) |
| probes | the `URUTAU-PROBE:` rule logs new inbound connections on the uplink to ports no socket listens on (at most 10 per second per source); the set of open ports is refreshed every minute from `ss`, including ports Docker publishes |
| container map | `urutau-containers-map` and its timer (every minute) write `/var/log/urutau/containers.map` (`<ip> <container>`) and `/var/log/urutau/resolv.conf` (the real upstream resolvers) |
| container map | `urutau-containers-map`, run by its timer (every minute) and by `urutau-containers-watch` (on every container start or network attach, so a redeploy that swaps addresses is named right within seconds), writes `/var/log/urutau/containers.map` (`<ip> <container>`) and `/var/log/urutau/resolv.conf` (the real upstream resolvers) |
| second firewall (`--enforce`) | directory `/var/log/urutau-enforce` (owned by `URUTAU_UID`, group `adm`) with `decisions.log` and `unban.log`; fail2ban filter `urutau`, action `urutau-allports` and jail `urutau` (`polling` backend, `maxretry = 1`, `bantime = 1h`, actions on `INPUT` and `DOCKER-USER`, host `ignoreip` kept); `urutau-unban.path` and `urutau-unban` apply the Unban button |
The `urutau-allports` action behaves like `iptables-allports` but only drops connections the banned address starts (conntrack original direction), so replies to connections the host opened keep flowing. The egress and probe files land in `/var/log/urutau`, which the probe compose file already mounts at `/logs/host`, so the probe finds them at its defaults (`URUTAU_EGRESS=auto` turns on by itself once the file exists). For the second firewall add the mount and the variables to the compose file, start with `observe` and move to `on` when the decisions look right:
+1 -1
View File
@@ -81,7 +81,7 @@ A side rail (a tab bar on phones, with a "More" menu that scrolls when it is tal
<p align="center"><img src="img/incidents-dark.png" width="900" alt="Page: Incidents"><br><sub>Incidents: tickets for outbound-traffic findings.</sub></p>
<p align="center"><img src="img/incident-detail-dark.png" width="900" alt="Page: Incident ticket"><br><sub>Incident ticket: summary, activity timeline and properties.</sub></p>
**Outbound traffic** (`#/egress`, needs `URUTAU_EGRESS` and the host kit in `deploy/host` on a probe): the new outbound connections of the host and containers, logged by nftables, analysed for beaconing (regular conversations with one destination, with the interval histogram), mining, IRC and SMTP ports, contact with addresses that attacked the server or Tor relays, DNS outside the allowed resolvers, unauthorised outbound scans and new countries. It shows a plain-language verdict, evidence cards, a destination map, activity by hour, compact workloads (by network or container name, `URUTAU_EGRESS_WORKLOADS`; a `scanner` workload has only its scan-shaped traffic summarised) and the timeline of authorised scans. Servers themselves, probes and the host's own provider never raise findings; regular connections to large CDNs and clouds are low severity.
**Outbound traffic** (`#/egress`, needs `URUTAU_EGRESS` and the host kit in `deploy/host` on a probe): the new outbound connections of the host and containers, logged by nftables, analysed for beaconing (regular conversations with one destination, with the interval histogram), mining, IRC and SMTP ports, contact with addresses that attacked the server or Tor relays, DNS outside the allowed resolvers, unauthorised outbound scans and new countries. It shows a plain-language verdict, evidence cards, a destination map, activity by hour, compact workloads (by network or container name, `URUTAU_EGRESS_WORKLOADS`; a `scanner` workload has only its scan-shaped traffic summarised) and the timeline of authorised scans. Servers themselves, probes and the host's own provider never raise findings; regular connections to large CDNs and clouds are low severity, and they never raise a new country (anycast).
<p align="center"><img src="img/egress-dark.png" width="900" alt="Page: Outbound traffic"><br><sub>Outbound traffic: scan bursts, beacons and mining from containers.</sub></p>
+1 -1
View File
@@ -96,7 +96,7 @@ A sonda usa só estas variáveis (flags em [cli.md](cli.md#urutau-probe)). Um ca
| `URUTAU_FAIL2BAN_LOG` | `/logs/host/fail2ban.log` | log do fail2ban |
| `URUTAU_PROBE_LOG` | `/logs/host/probe.log` | log do kernel de conexões a portas que ninguém serve, gravado pelo kit do host (veja [Sondagens](#sondagens-varreduras-de-portas)) |
| `URUTAU_EGRESS_LOG` | `/logs/host/egress.log` | log do kernel de conexões novas de saída, gravado pelo kit do host |
| `URUTAU_EGRESS_CONTAINERS` | `/logs/host/containers.map` | mapa `"<ip> <container>"` gravado pelo kit do host a cada minuto, para que as cargas mantenham o nome quando o endereço muda num redeploy; enviado inteiro quando muda |
| `URUTAU_EGRESS_CONTAINERS` | `/logs/host/containers.map` | mapa `"<ip> <container>"` gravado pelo kit do host quando um contêiner sobe (e a cada minuto), para que as cargas mantenham o nome quando o endereço muda num redeploy; enviado inteiro quando muda |
| `URUTAU_RESOLV` | `/etc/resolv.conf` do host (montado) | resolvedores do host, enviados inteiros quando mudam |
| `URUTAU_ENFORCE_LOG` | `/logs/enforce/decisions.log` | arquivo onde as decisões de ban do hub são acrescentadas, lido pela jail do host; vazio ignora comandos de ban e os conta como erro |
| `URUTAU_ENFORCE_UNBAN_LOG` | `/logs/enforce/unban.log` | arquivo onde os pedidos de desban são acrescentados, lido pelo host; vazio os ignora |
+1 -1
View File
@@ -179,7 +179,7 @@ sudo sh deploy/host/install.sh --remove # desfaz tudo (os logs são mantidos)
|---|---|
| registro de egress | tabela nftables `inet urutau_egress` (`/etc/urutau/egress.nft`, só registra, nunca descarta, separada das tabelas do Docker e do fail2ban) e a unit `urutau-egress.service`; a regra rsyslog `41-urutau-egress.conf` manda as linhas do kernel para `/var/log/urutau/egress.log` (`URUTAU-EGRESS:`) e `/var/log/urutau/probe.log` (`URUTAU-PROBE:`); logrotate diário, 7 cópias, no máximo 200 MB (`urutau-logrotate.timer`) |
| sondagens | a regra `URUTAU-PROBE:` registra conexões novas de entrada pela interface externa a portas em que nenhum socket escuta (no máximo 10 por segundo por origem); o conjunto de portas abertas é atualizado a cada minuto a partir do `ss`, incluindo as portas que o Docker publica |
| mapa de containers | `urutau-containers-map` e seu timer (a cada minuto) gravam `/var/log/urutau/containers.map` (`<ip> <container>`) e `/var/log/urutau/resolv.conf` (os resolvedores reais de upstream) |
| mapa de containers | `urutau-containers-map`, executado pelo timer (a cada minuto) e pelo `urutau-containers-watch` (a cada contêiner que sobe ou entra numa rede, para que um redeploy que troca endereços seja nomeado certo em segundos), grava `/var/log/urutau/containers.map` (`<ip> <container>`) e `/var/log/urutau/resolv.conf` (os resolvedores reais de upstream) |
| segundo firewall (`--enforce`) | diretório `/var/log/urutau-enforce` (dono `URUTAU_UID`, grupo `adm`) com `decisions.log` e `unban.log`; filtro `urutau`, ação `urutau-allports` e jail `urutau` do fail2ban (backend `polling`, `maxretry = 1`, `bantime = 1h`, ações em `INPUT` e `DOCKER-USER`, `ignoreip` do host mantido); `urutau-unban.path` e `urutau-unban` aplicam o botão Desbanir |
A ação `urutau-allports` funciona como `iptables-allports`, mas só descarta conexões que o endereço banido inicia (direção original do conntrack), então as respostas a conexões que o host abriu continuam fluindo. Os arquivos de egress e sondagem caem em `/var/log/urutau`, que o compose já monta em `/logs/host`, então a sonda os encontra nos padrões (`URUTAU_EGRESS=auto` liga sozinho assim que o arquivo existe). Para o segundo firewall, acrescente a montagem e as variáveis ao compose, comece com `observe` e passe para `on` quando as decisões parecerem certas:
+1 -1
View File
@@ -81,7 +81,7 @@ Uma barra lateral (barra de abas no celular, com um menu "Mais" que rola quando
<p align="center"><img src="../img/incidents-dark-pt.png" width="900" alt="Página: Incidentes"><br><sub>Incidentes: chamados para achados do tráfego de saída.</sub></p>
<p align="center"><img src="../img/incident-detail-dark-pt.png" width="900" alt="Página: Chamado de incidente"><br><sub>Chamado de incidente: resumo, linha do tempo de atividade e propriedades.</sub></p>
**Tráfego de saída** (`#/egress`, exige `URUTAU_EGRESS` e o kit de host em `deploy/host` numa sonda): as novas conexões de saída do host e dos contêineres, registradas pelo nftables, analisadas quanto a beaconing (conversas regulares com um destino, com o histograma de intervalos), mineração, portas de IRC e SMTP, contato com endereços que atacaram o servidor ou relays Tor, DNS fora dos resolvers permitidos, varreduras de saída não autorizadas e países novos. Mostra um veredito em linguagem simples, cartões de evidência, mapa de destinos, atividade por hora, workloads compactos (por nome de rede ou contêiner, `URUTAU_EGRESS_WORKLOADS`; um workload `scanner` tem só o tráfego em forma de varredura resumido) e a linha do tempo das varreduras autorizadas. Os próprios servidores, sondas e o provedor do host nunca geram achados; conexões regulares a grandes CDNs e nuvens têm severidade baixa.
**Tráfego de saída** (`#/egress`, exige `URUTAU_EGRESS` e o kit de host em `deploy/host` numa sonda): as novas conexões de saída do host e dos contêineres, registradas pelo nftables, analisadas quanto a beaconing (conversas regulares com um destino, com o histograma de intervalos), mineração, portas de IRC e SMTP, contato com endereços que atacaram o servidor ou relays Tor, DNS fora dos resolvers permitidos, varreduras de saída não autorizadas e países novos. Mostra um veredito em linguagem simples, cartões de evidência, mapa de destinos, atividade por hora, workloads compactos (por nome de rede ou contêiner, `URUTAU_EGRESS_WORKLOADS`; um workload `scanner` tem só o tráfego em forma de varredura resumido) e a linha do tempo das varreduras autorizadas. Os próprios servidores, sondas e o provedor do host nunca geram achados; conexões regulares a grandes CDNs e nuvens têm severidade baixa e nunca geram país novo (anycast).
<p align="center"><img src="../img/egress-dark-pt.png" width="900" alt="Página: Tráfego de saída"><br><sub>Tráfego de saída: rajadas de varredura, beacons e mineração em contêineres.</sub></p>
+1 -1
View File
@@ -2,4 +2,4 @@ package app
// Version is the release version (SemVer). Release builds may override it with
// -ldflags "-X .../internal/app.Version=...".
var Version = "2.2.1"
var Version = "2.2.2"
+23
View File
@@ -700,3 +700,26 @@ func TestEngineDst(t *testing.T) {
t.Fatal("dst found outside the window")
}
}
func TestNewGeoSkipsAnycastCDN(t *testing.T) {
geo := func(s string) (string, string, string) {
switch s {
case "1.1.1.1":
return "AU", "AS13335", "Cloudflare"
case "149.154.166.110":
return "NL", "", ""
case "203.0.113.50":
return "DE", "AS197540", "netcup"
}
return "BR", "AS2", "y"
}
e := newEng(t, Config{Geo: geo})
e.IngestEvent(mk(t0, "10.0.3.5", "203.0.113.1", "tcp", 443))
e.IngestEvent(mk(t0.Add(25*time.Hour), "10.0.3.5", "1.1.1.1", "udp", 53)) // Cloudflare anycast
e.IngestEvent(mk(t0.Add(25*time.Hour), "10.0.3.5", "149.154.166.110", "tcp", 443)) // Telegram prefix, no ASN
e.IngestEvent(mk(t0.Add(26*time.Hour), "10.0.3.5", "203.0.113.50", "tcp", 443))
g := kinds(rep(e), "new_geo")
if len(g) != 1 || g[0].Dst != "203.0.113.50" {
t.Fatalf("new_geo: %+v", g)
}
}
+3 -1
View File
@@ -752,7 +752,9 @@ func (e *Engine) checks(ws *wstate, ev Event, dport uint16, t int64, ds *dstStat
if ws.role != RoleScanner && !fan && ds.cc != "" && isGlobal(ev.Dst) {
if _, seen := ws.geo[ds.cc]; !seen {
ws.geo[ds.cc] = struct{}{}
if t-ws.first >= int64(e.cfg.Learn/time.Second) {
// Anycast CDNs and big clouds: the database country of 1.1.1.1 or a
// Cloudflare edge says nothing about where the traffic goes.
if t-ws.first >= int64(e.cfg.Learn/time.Second) && !commonCloudASNs[ds.asn] && !inCommonCDN(ev.Dst) {
e.addFinding("new_geo", "low", ws.name, dst, dport, ev.Proto, t, 0, 0, "first contact with country "+ds.cc+" "+ds.asn, 1)
}
} else if len(ws.geo) > 300 {
+1 -1
View File
@@ -17,7 +17,7 @@ import (
const (
chanSize = 4096
batchBytes = 128 << 10 // well under the hub limit; keeps the probe heap small
filePollEach = 10 * time.Second
filePollEach = 2 * time.Second
)
// item is what the followers and the file watcher hand to the collector.