Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec46fb94ff | ||
|
|
432f521ed1 | ||
|
|
f27d8441a9 | ||
|
|
b267b98f18 | ||
|
|
9bdfdb491b | ||
|
|
5d3374ee11 |
No files matched your search
@@ -6,6 +6,26 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versio
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.4.2] - 2026-11-15
|
||||
|
||||
### Changed
|
||||
|
||||
- Services page redesigned: plain-language verdict, KPIs with sparklines, services from worst to best with availability against the 99.5% SLO, error budget left, burn rate, Apdex and latency, and a service detail with requests and errors, how requests were answered, p95 by hour and failing routes split into service errors, blocked attacks and client mistakes. API: `err_spark` in `/api/v1/services`.
|
||||
|
||||
## [1.4.1] - 2026-11-15
|
||||
|
||||
### Added
|
||||
|
||||
- Network probes source (`URUTAU_PROBE_LOG`, default `/logs/host/probe.log`): the host kit logs new inbound connections to ports nobody listens on; each becomes a `port-scan` event (MITRE T1046), and 10 distinct ports in 10 minutes make the second firewall ban the address (reason `port-scan`).
|
||||
- Survival: who blocked and how fast, the host fail2ban jails apart from the Urutau second firewall.
|
||||
- Pagination in the backend for sessions, IPs, campaigns and the events of an address, with one pager for every list; event search pages by cursor.
|
||||
|
||||
### Changed
|
||||
|
||||
- Outbound traffic page redesigned: plain-language verdict, evidence cards (beacon rhythm and interval histogram), destination map, activity by hour, compact workloads and the timeline of authorised scans. API: `findings[].samples`, `by_country`.
|
||||
- Reports page: a preview of the HTML report itself, always an A4 sheet scaled to the screen, with only Download and Print; language selector, period and server from the header.
|
||||
- Report: sharp logo (the repository logo at 800 px) and the cover drawing is now the urutau's call, five descending notes.
|
||||
|
||||
## [1.4.0] - 2026-11-15
|
||||
|
||||
### Added
|
||||
|
||||
@@ -6,6 +6,26 @@ Formato baseado no [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/);
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.4.2] - 2026-11-15
|
||||
|
||||
### Alterado
|
||||
|
||||
- Página Serviços refeita: veredito em linguagem leiga, indicadores com mini gráficos, serviços dos piores para os melhores com disponibilidade contra o SLO de 99,5%, orçamento de erro restante, consumo, Apdex e latência, e detalhe do serviço com requisições e erros, como as requisições foram respondidas, p95 por hora e rotas que falham separadas em erros do serviço, ataques barrados e enganos do cliente. API: `err_spark` em `/api/v1/services`.
|
||||
|
||||
## [1.4.1] - 2026-11-15
|
||||
|
||||
### Adicionado
|
||||
|
||||
- Fonte de sondagens de rede (`URUTAU_PROBE_LOG`, padrão `/logs/host/probe.log`): o kit do host registra conexões novas de entrada para portas em que nada escuta; cada uma vira um evento `port-scan` (MITRE T1046), e 10 portas distintas em 10 minutos fazem o segundo firewall banir o endereço (motivo `port-scan`).
|
||||
- Sobrevivência: quem bloqueou e com que rapidez, os jails do fail2ban do host separados do segundo firewall do Urutau.
|
||||
- Paginação no backend para sessões, IPs, campanhas e eventos de um endereço, com um paginador único em todas as listas; a busca de eventos pagina por cursor.
|
||||
|
||||
### Alterado
|
||||
|
||||
- Página Tráfego de saída refeita: veredito em linguagem leiga, cartões de evidência (ritmo do beacon e histograma dos intervalos), mapa de destinos, atividade por hora, workloads compactos e a linha do tempo das varreduras autorizadas. API: `findings[].samples`, `by_country`.
|
||||
- Página Relatórios: prévia do próprio relatório HTML, sempre uma folha A4 em escala, só com Baixar e Imprimir; seletor de idioma, período e servidor do topo.
|
||||
- Relatório: logo nítida (a logo do repositório em 800 px) e o desenho da capa agora é o canto do urutau, cinco notas descendentes.
|
||||
|
||||
## [1.4.0] - 2026-11-15
|
||||
|
||||
### Adicionado
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
<p align="center"><img src="docs/img/ip-analysis-dark.png" width="900" alt="Urutau IP analysis page: verdict, score, critical exposure and recommended actions for one attacker"><br><sub>IP analysis: verdict, evidence and recommended actions for one address.</sub></p>
|
||||
|
||||
<p align="center"><img src="docs/img/defense-dark.png" width="900" alt="Urutau defense page with the second firewall section"><br><sub>Defense: the second firewall in observe mode, next to the host fail2ban.</sub></p>
|
||||
|
||||
<p align="center"><img src="docs/img/egress-dark.png" width="900" alt="Egress"><br><sub>Egress: scan bursts, beacons and mining from containers.</sub></p>
|
||||
|
||||
**Status: stable, v1.0.0.** See [CHANGELOG.md](CHANGELOG.md) for exactly what shipped.
|
||||
|
||||
Urutau is a small panel that runs on each of your servers (as a container), reads the logs the server already writes, and answers one question: who is attacking me right now? It classifies hostile activity, scores every source IP, keeps a rolling window on disk and serves an embedded dashboard, a JSON API and an exportable blocklist.
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
|
||||
<p align="center"><img src="docs/img/ip-analysis-dark-pt.png" width="900" alt="Página de análise de IP do Urutau: veredito, pontuação, exposição crítica e ações recomendadas para um atacante"><br><sub>Análise de IP: veredito, evidências e ações recomendadas para um endereço.</sub></p>
|
||||
|
||||
<p align="center"><img src="docs/img/defense-dark-pt.png" width="900" alt="Página Defesa do Urutau com a seção do segundo firewall"><br><sub>Defesa: o segundo firewall em modo observe, ao lado do fail2ban do host.</sub></p>
|
||||
|
||||
<p align="center"><img src="docs/img/egress-dark-pt.png" width="900" alt="Egress"><br><sub>Saída: rajadas de varredura, beacons e mineração em contêineres.</sub></p>
|
||||
|
||||
**Status: estável, v1.0.0.** Veja o [CHANGELOG.pt-BR.md](CHANGELOG.pt-BR.md) para saber exatamente o que foi entregue.
|
||||
|
||||
O Urutau é um painel pequeno que roda em cada um dos seus servidores (como container), lê os logs que o servidor já escreve e responde a uma pergunta: quem está me atacando agora? Ele classifica a atividade hostil, pontua cada IP de origem, mantém uma janela móvel em disco e serve um dashboard embutido, uma API JSON e uma blocklist exportável.
|
||||
|
||||
@@ -5,3 +5,10 @@ if ($syslogfacility-text == "kern" and $msg contains "URUTAU-EGRESS: ") then {
|
||||
fileOwner="syslog" fileGroup="adm" fileCreateMode="0640")
|
||||
stop
|
||||
}
|
||||
|
||||
# inbound probes to closed ports (port scans)
|
||||
if ($syslogfacility-text == "kern" and $msg contains "URUTAU-PROBE: ") then {
|
||||
action(type="omfile" file="/var/log/urutau/probe.log" template="RSYSLOG_FileFormat"
|
||||
fileOwner="syslog" fileGroup="adm" fileCreateMode="0640")
|
||||
stop
|
||||
}
|
||||
@@ -11,3 +11,22 @@ docker ps -q | xargs -r docker inspect -f '{{$n := .Name}}{{range .NetworkSettin
|
||||
chgrp adm "$tmp"; chmod 0640 "$tmp"
|
||||
mv -f "$tmp" "$out"
|
||||
trap - EXIT
|
||||
|
||||
# The real upstream resolvers (systemd-resolved hides them behind 127.0.0.53),
|
||||
# so DNS to the provider resolver is not reported as a bypass.
|
||||
r=/var/log/urutau/resolv.conf
|
||||
{
|
||||
resolvectl dns 2>/dev/null | tr ' ' '\n' | grep -E '^([0-9]{1,3}\.){3}[0-9]{1,3}$|^[0-9a-fA-F]*:[0-9a-fA-F:]+$' || true
|
||||
awk '/^nameserver/ {print $2}' /run/systemd/resolve/resolv.conf 2>/dev/null || true
|
||||
} | grep -vE '^127\.' | sort -u | sed 's/^/nameserver /' > "$r.tmp"
|
||||
chgrp adm "$r.tmp"; chmod 0640 "$r.tmp"; mv -f "$r.tmp" "$r"
|
||||
|
||||
# Ports this host serves (listening sockets, including the ones Docker
|
||||
# publishes): connections to any other port are logged as probes.
|
||||
if nft list set inet urutau_egress open >/dev/null 2>&1; then
|
||||
{
|
||||
echo "flush set inet urutau_egress open"
|
||||
ss -Hlnt | awk '{print $4}' | sed -n 's/.*:\([0-9][0-9]*\)$/tcp . \1/p'
|
||||
ss -Hlnu | awk '{print $4}' | sed -n 's/.*:\([0-9][0-9]*\)$/udp . \1/p'
|
||||
} | sort -u | awk 'NR==1 {print; next} {e = e (e ? ", " : "") $0} END {if (e) print "add element inet urutau_egress open { " e " }"}' | nft -f -
|
||||
fi
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/sbin/nft -f
|
||||
# Urutau: logs NEW outbound connections (host and containers) so the egress
|
||||
# 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).
|
||||
@@ -32,6 +33,24 @@ table inet urutau_egress {
|
||||
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
|
||||
|
||||
@@ -7,6 +7,7 @@ Wants=network-online.target
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/sbin/nft -f /etc/urutau/egress.nft
|
||||
ExecStartPost=-/usr/local/sbin/urutau-containers-map
|
||||
ExecStop=/usr/sbin/nft delete table inet urutau_egress
|
||||
|
||||
[Install]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/var/log/urutau/egress.log {
|
||||
/var/log/urutau/egress.log /var/log/urutau/probe.log {
|
||||
daily
|
||||
rotate 7
|
||||
maxsize 200M
|
||||
|
||||
|
After Width: | Height: | Size: 149 KiB |
|
After Width: | Height: | Size: 145 KiB |
|
After Width: | Height: | Size: 211 KiB |
|
After Width: | Height: | Size: 210 KiB |
|
After Width: | Height: | Size: 211 KiB |
|
After Width: | Height: | Size: 215 KiB |
|
After Width: | Height: | Size: 193 KiB |
|
After Width: | Height: | Size: 186 KiB |
|
After Width: | Height: | Size: 437 KiB |
|
After Width: | Height: | Size: 413 KiB |
|
After Width: | Height: | Size: 421 KiB |
|
After Width: | Height: | Size: 190 KiB |
|
After Width: | Height: | Size: 693 KiB |
|
After Width: | Height: | Size: 677 KiB |
|
After Width: | Height: | Size: 690 KiB |
|
After Width: | Height: | Size: 270 KiB |
|
After Width: | Height: | Size: 225 KiB |
|
After Width: | Height: | Size: 209 KiB |
|
After Width: | Height: | Size: 289 KiB |
|
After Width: | Height: | Size: 154 KiB |
|
After Width: | Height: | Size: 151 KiB |
|
After Width: | Height: | Size: 175 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 171 KiB |
|
After Width: | Height: | Size: 202 KiB |
|
Before Width: | Height: | Size: 175 KiB After Width: | Height: | Size: 196 KiB |
|
Before Width: | Height: | Size: 166 KiB After Width: | Height: | Size: 188 KiB |
|
Before Width: | Height: | Size: 168 KiB After Width: | Height: | Size: 187 KiB |
|
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 184 KiB |
|
After Width: | Height: | Size: 219 KiB |
|
After Width: | Height: | Size: 206 KiB |
|
Before Width: | Height: | Size: 238 KiB After Width: | Height: | Size: 259 KiB |
|
Before Width: | Height: | Size: 236 KiB After Width: | Height: | Size: 255 KiB |
|
Before Width: | Height: | Size: 241 KiB After Width: | Height: | Size: 260 KiB |
|
Before Width: | Height: | Size: 169 KiB After Width: | Height: | Size: 191 KiB |
|
Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 190 KiB |
|
Before Width: | Height: | Size: 222 KiB After Width: | Height: | Size: 222 KiB |
|
After Width: | Height: | Size: 416 KiB |
|
Before Width: | Height: | Size: 372 KiB After Width: | Height: | Size: 391 KiB |
|
Before Width: | Height: | Size: 368 KiB After Width: | Height: | Size: 393 KiB |
|
Before Width: | Height: | Size: 310 KiB After Width: | Height: | Size: 296 KiB |
|
Before Width: | Height: | Size: 596 KiB After Width: | Height: | Size: 612 KiB |
|
Before Width: | Height: | Size: 593 KiB After Width: | Height: | Size: 617 KiB |
|
After Width: | Height: | Size: 203 KiB |
|
After Width: | Height: | Size: 196 KiB |
|
Before Width: | Height: | Size: 173 KiB After Width: | Height: | Size: 211 KiB |
|
Before Width: | Height: | Size: 163 KiB After Width: | Height: | Size: 197 KiB |
|
Before Width: | Height: | Size: 167 KiB After Width: | Height: | Size: 203 KiB |
|
Before Width: | Height: | Size: 221 KiB After Width: | Height: | Size: 224 KiB |
|
After Width: | Height: | Size: 210 KiB |
|
After Width: | Height: | Size: 188 KiB |
|
Before Width: | Height: | Size: 207 KiB After Width: | Height: | Size: 232 KiB |
|
Before Width: | Height: | Size: 207 KiB After Width: | Height: | Size: 228 KiB |
|
After Width: | Height: | Size: 162 KiB |
|
After Width: | Height: | Size: 151 KiB |
|
After Width: | Height: | Size: 202 KiB |
|
After Width: | Height: | Size: 194 KiB |
|
After Width: | Height: | Size: 186 KiB |
|
After Width: | Height: | Size: 175 KiB |
|
After Width: | Height: | Size: 390 KiB |
|
After Width: | Height: | Size: 380 KiB |
|
After Width: | Height: | Size: 381 KiB |
|
After Width: | Height: | Size: 312 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 176 KiB |
|
Before Width: | Height: | Size: 148 KiB After Width: | Height: | Size: 167 KiB |
|
After Width: | Height: | Size: 198 KiB |
|
After Width: | Height: | Size: 190 KiB |
|
Before Width: | Height: | Size: 181 KiB After Width: | Height: | Size: 212 KiB |
|
Before Width: | Height: | Size: 162 KiB After Width: | Height: | Size: 189 KiB |
|
Before Width: | Height: | Size: 244 KiB After Width: | Height: | Size: 248 KiB |
|
Before Width: | Height: | Size: 180 KiB After Width: | Height: | Size: 215 KiB |
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 204 KiB |
@@ -53,6 +53,36 @@ A side rail (a tab bar on phones) holds the pages. Each page opens with a senten
|
||||
|
||||
<p align="center"><img src="img/sources-dark.png" width="900" alt="Sources and hosts page: instances, log sources and blocklist"><br><sub>Sources and hosts.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/sessions-dark.png" width="900" alt="Page: Sessions"><br><sub>Sessions: the stages of each attacker, with a replay link.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/campaigns-dark.png" width="900" alt="Page: Campaigns"><br><sub>Campaigns: coordinated groups of addresses (Gantt and similarity).</sub></p>
|
||||
|
||||
<p align="center"><img src="img/campaign-detail-dark.png" width="900" alt="Page: Campaign detail"><br><sub>Campaign detail: members, timeline and shared traits.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/search-dark.png" width="900" alt="Page: Search"><br><sub>Search: filter the event registry by IP, path, family and status.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/mitre-dark.png" width="900" alt="Page: MITRE ATT&CK"><br><sub>MITRE ATT&CK: techniques observed, by tactic.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/defense-dark.png" width="900" alt="Page: Defense, with the second firewall"><br><sub>Defense: coverage of the host fail2ban and the second firewall (observe mode).</sub></p>
|
||||
|
||||
<p align="center"><img src="img/egress-dark.png" width="900" alt="Page: Egress traffic"><br><sub>Egress: outbound connections of the host and containers, with scan bursts, beacons and mining.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/evolution-dark.png" width="900" alt="Page: Evolution"><br><sub>Evolution: how attacks change over time.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/concentration-dark.png" width="900" alt="Page: Concentration"><br><sub>Concentration: how much of the hostility a few sources or networks account for.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/survival-dark.png" width="900" alt="Page: Survival"><br><sub>Survival: how long attackers keep coming back.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/errors-dark.png" width="900" alt="Page: Errors"><br><sub>Errors: response classes, targets and hosts.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/slo-dark.png" width="900" alt="Page: Services"><br><sub>Services: availability and latency of each service.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/protocol-dark.png" width="900" alt="Page: Protocols and TLS"><br><sub>Protocols and TLS: HTTP and TLS versions by class.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/integrity-dark.png" width="900" alt="Page: Integrity"><br><sub>Integrity: health of the log sources and the registry.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/reports-dark.png" width="900" alt="Page: Reports"><br><sub>Reports: the exportable report.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/overview-light.png" width="620" alt="Overview in the light theme"> <img src="img/overview-mobile.png" height="420" alt="Overview on a phone"><br><sub>The light theme on a desktop and the phone layout (a tab bar replaces the side rail).</sub></p>
|
||||
|
||||
## Page groups
|
||||
@@ -112,3 +142,7 @@ State and city boundaries on the Geography page are from [Natural Earth](https:/
|
||||
An invalid `range` or period answers 400, and `range` in the responses is an object `{name,from,to,step,clipped}` (`step` is the timeline granularity in seconds).
|
||||
|
||||
API clients send `Authorization: Bearer <URUTAU_TOKEN>`. The peer token is accepted only by `/api/v1/peer/export`, `/api/v1/peer/stream` and `/api/v1/peer/period`; every other route answers 403 to it.
|
||||
|
||||
<p align="center"><img src="img/defense-light.png" width="620" alt="Defense"> <img src="img/defense-mobile.png" height="420" alt="Defense"><br><sub>Defense, egress and campaigns in the light theme and on a phone.</sub></p>
|
||||
|
||||
<p align="center"><img src="img/egress-light.png" width="620" alt="Egress"> <img src="img/egress-mobile.png" height="420" alt="Egress"></p>
|
||||
@@ -50,6 +50,36 @@ Uma barra lateral (barra de abas no celular) reúne as páginas. Cada página ab
|
||||
|
||||
<p align="center"><img src="../img/sources-dark-pt.png" width="900" alt="Página Fontes e hosts: instâncias, fontes de log e blocklist"><br><sub>Fontes e hosts.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/sessions-dark-pt.png" width="900" alt="Página: Sessões"><br><sub>Sessões: as etapas de cada atacante, com link para o replay.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/campaigns-dark-pt.png" width="900" alt="Página: Campanhas"><br><sub>Campanhas: grupos coordenados de endereços (Gantt e similaridade).</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/campaign-detail-dark-pt.png" width="900" alt="Página: Detalhe da campanha"><br><sub>Detalhe da campanha: membros, linha do tempo e traços em comum.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/search-dark-pt.png" width="900" alt="Página: Busca"><br><sub>Busca: filtre o registro de eventos por IP, caminho, família e status.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/mitre-dark-pt.png" width="900" alt="Página: MITRE ATT&CK"><br><sub>MITRE ATT&CK: técnicas observadas, por tática.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/defense-dark-pt.png" width="900" alt="Página: Defesa, com o segundo firewall"><br><sub>Defesa: cobertura do fail2ban do host e do segundo firewall (modo observe).</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/egress-dark-pt.png" width="900" alt="Página: Tráfego de saída"><br><sub>Saída: conexões de saída do host e dos contêineres, com rajadas de varredura, beacons e mineração.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/evolution-dark-pt.png" width="900" alt="Página: Evolução"><br><sub>Evolução: como os ataques mudam ao longo do tempo.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/concentration-dark-pt.png" width="900" alt="Página: Concentração"><br><sub>Concentração: quanto da hostilidade poucas fontes ou redes explicam.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/survival-dark-pt.png" width="900" alt="Página: Sobrevivência"><br><sub>Sobrevivência: por quanto tempo os atacantes continuam voltando.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/errors-dark-pt.png" width="900" alt="Página: Erros"><br><sub>Erros: classes de resposta, alvos e hosts.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/slo-dark-pt.png" width="900" alt="Página: Serviços"><br><sub>Serviços: disponibilidade e latência de cada serviço.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/protocol-dark-pt.png" width="900" alt="Página: Protocolos e TLS"><br><sub>Protocolos e TLS: versões de HTTP e TLS por classe.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/integrity-dark-pt.png" width="900" alt="Página: Integridade"><br><sub>Integridade: saúde das fontes de log e do registro.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/reports-dark-pt.png" width="900" alt="Página: Relatórios"><br><sub>Relatórios: o relatório exportável.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/overview-light.png" width="620" alt="Visão geral no tema claro"> <img src="../img/overview-mobile.png" height="420" alt="Visão geral no celular"><br><sub>O tema claro no desktop e o layout de celular (uma barra de abas substitui a lateral).</sub></p>
|
||||
|
||||
## Grupos de páginas
|
||||
@@ -109,3 +139,7 @@ Os limites de estados e cidades da página Geografia são do [Natural Earth](htt
|
||||
Um `range` ou período inválido responde 400, e `range` nas respostas é um objeto `{name,from,to,step,clipped}` (`step` é a granularidade da linha do tempo em segundos).
|
||||
|
||||
Clientes da API enviam `Authorization: Bearer <URUTAU_TOKEN>`. O token de peer só é aceito por `/api/v1/peer/export`, `/api/v1/peer/stream` e `/api/v1/peer/period`; todas as outras rotas respondem 403 a ele.
|
||||
|
||||
<p align="center"><img src="../img/defense-light.png" width="620" alt="Defense"> <img src="../img/defense-mobile.png" height="420" alt="Defense"><br><sub>Defesa, saída e campanhas no tema claro e no celular.</sub></p>
|
||||
|
||||
<p align="center"><img src="../img/egress-light.png" width="620" alt="Egress"> <img src="../img/egress-mobile.png" height="420" alt="Egress"></p>
|
||||
@@ -26,6 +26,7 @@ type Config struct {
|
||||
TraefikLog string
|
||||
AuthLog string
|
||||
Fail2banLog string
|
||||
ProbeLog string // kernel log of new connections to unserved ports
|
||||
Ignore string // networks whose events are dropped (--ignore, alias of --trusted)
|
||||
Trusted string // trusted sources, e.g. the servers themselves (--trusted)
|
||||
MonitorUA string // regex of monitoring User-Agents
|
||||
@@ -149,6 +150,7 @@ func ParseFlags(name string, args []string) (Config, error) {
|
||||
fs.StringVar(&c.DataDir, "data-dir", env("URUTAU_DATA_DIR", "/data"), "snapshot directory (URUTAU_DATA_DIR)")
|
||||
fs.StringVar(&c.TraefikLog, "traefik-log", env("URUTAU_TRAEFIK_LOG", "/data/coolify/proxy/access.log"), "Traefik JSON access log, empty disables (URUTAU_TRAEFIK_LOG)")
|
||||
fs.StringVar(&c.AuthLog, "auth-log", env("URUTAU_AUTH_LOG", "/var/log/auth.log"), "sshd auth log, empty disables (URUTAU_AUTH_LOG)")
|
||||
fs.StringVar(&c.ProbeLog, "probe-log", env("URUTAU_PROBE_LOG", "/logs/host/probe.log"), "kernel log of network probes (unserved ports) written by the host kit, empty disables (URUTAU_PROBE_LOG)")
|
||||
fs.StringVar(&c.Fail2banLog, "fail2ban-log", env("URUTAU_FAIL2BAN_LOG", "/var/log/fail2ban.log"), "fail2ban log, empty disables (URUTAU_FAIL2BAN_LOG)")
|
||||
ign := &csvFlag{val: env("URUTAU_IGNORE", DefaultIgnore)}
|
||||
trusted := &csvFlag{val: env("URUTAU_TRUSTED", "")}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/egress"
|
||||
)
|
||||
|
||||
const probeMarker = "URUTAU-PROBE:"
|
||||
|
||||
// probeMaxKeys bounds the aggregation map; when it is full the entries older
|
||||
// than a minute are dropped.
|
||||
const probeMaxKeys = 100000
|
||||
|
||||
type probeKey struct {
|
||||
ip string
|
||||
port uint16
|
||||
proto string
|
||||
}
|
||||
|
||||
// probeParser turns "URUTAU-PROBE:" kernel lines into scanner events, at most
|
||||
// one per (ip, port, proto) per minute, so a SYN flood does not inflate the store.
|
||||
type probeParser struct {
|
||||
mu sync.Mutex
|
||||
last map[probeKey]int64 // minute of the last event kept
|
||||
now func() time.Time
|
||||
}
|
||||
|
||||
func newProbeParser() *probeParser {
|
||||
return &probeParser{last: map[probeKey]int64{}, now: time.Now}
|
||||
}
|
||||
|
||||
func (p *probeParser) parse(b []byte) (core.Event, error) {
|
||||
k, err := egress.ParseKernel(b, probeMarker, p.now())
|
||||
if err != nil {
|
||||
return core.Event{}, err
|
||||
}
|
||||
if (k.Proto != "tcp" && k.Proto != "udp") || k.DPort == 0 || !k.Src.IsValid() {
|
||||
return core.Event{}, fmt.Errorf("not a tcp/udp probe")
|
||||
}
|
||||
key := probeKey{k.Src.String(), k.DPort, k.Proto}
|
||||
min := k.Time.Unix() / 60
|
||||
p.mu.Lock()
|
||||
if m, ok := p.last[key]; ok && m >= min {
|
||||
p.mu.Unlock()
|
||||
return core.Event{}, core.ErrIgnored
|
||||
}
|
||||
if len(p.last) >= probeMaxKeys {
|
||||
cut := p.now().Unix()/60 - 1
|
||||
for kk, m := range p.last {
|
||||
if m < cut {
|
||||
delete(p.last, kk)
|
||||
}
|
||||
}
|
||||
if len(p.last) >= probeMaxKeys {
|
||||
p.last = map[probeKey]int64{}
|
||||
}
|
||||
}
|
||||
p.last[key] = min
|
||||
p.mu.Unlock()
|
||||
return core.Event{Time: k.Time, IP: k.Src.String(), Cat: core.Scanner, Source: "probe", Method: upper(k.Proto),
|
||||
Path: k.Proto + "/" + itoa(int(k.DPort)) + serviceSuffix(k.Proto, k.DPort), Proto: k.Proto, Port: k.DPort}, nil
|
||||
}
|
||||
|
||||
func upper(s string) string {
|
||||
if s == "udp" {
|
||||
return "UDP"
|
||||
}
|
||||
return "TCP"
|
||||
}
|
||||
|
||||
func itoa(n int) string { return fmt.Sprint(n) }
|
||||
|
||||
func serviceSuffix(proto string, port uint16) string {
|
||||
if s := core.PortService(proto, port); s != "" {
|
||||
return " " + s
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/intel"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
||||
)
|
||||
|
||||
const probeV4 = `2026-11-15T03:20:01.123456+00:00 srv kernel: URUTAU-PROBE: IN=eth0 OUT= MAC=aa SRC=203.0.113.9 DST=195.200.0.252 LEN=44 TTL=241 ID=1 PROTO=TCP SPT=51234 DPT=3389 WINDOW=1024 SYN URGP=0`
|
||||
|
||||
func TestProbeParse(t *testing.T) {
|
||||
p := newProbeParser()
|
||||
ev, err := p.parse([]byte(probeV4))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if ev.IP != "203.0.113.9" || ev.Cat != core.Scanner || ev.Source != "probe" || ev.Port != 3389 || ev.Proto != "tcp" || ev.Path != "tcp/3389 rdp" {
|
||||
t.Fatalf("%+v", ev)
|
||||
}
|
||||
v6 := `2026-11-15T03:20:01+00:00 srv kernel: URUTAU-PROBE: IN=eth0 OUT= SRC=2001:db8::5 DST=2001:db8::1 LEN=60 PROTO=TCP SPT=1 DPT=445 SYN`
|
||||
if ev, err = p.parse([]byte(v6)); err != nil || ev.IP != "2001:db8::5" || ev.Port != 445 {
|
||||
t.Fatalf("%+v %v", ev, err)
|
||||
}
|
||||
udp := `2026-11-15T03:20:01+00:00 srv kernel: URUTAU-PROBE: IN=eth0 OUT= SRC=203.0.113.9 DST=195.200.0.252 LEN=60 PROTO=UDP SPT=1 DPT=161 LEN=40`
|
||||
if ev, err = p.parse([]byte(udp)); err != nil || ev.Proto != "udp" || ev.Path != "udp/161 snmp" {
|
||||
t.Fatalf("%+v %v", ev, err)
|
||||
}
|
||||
for _, bad := range []string{"", "garbage", "kernel: URUTAU-PROBE: nothing", `x URUTAU-PROBE: SRC=bad DST=1.1.1.1 PROTO=TCP DPT=1`,
|
||||
`x URUTAU-PROBE: SRC=1.1.1.1 DST=2.2.2.2 PROTO=ICMP`} {
|
||||
if _, err := newProbeParser().parse([]byte(bad)); err == nil {
|
||||
t.Errorf("accepted %q", bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProbePerMinuteAggregation(t *testing.T) {
|
||||
p := newProbeParser()
|
||||
if _, err := p.parse([]byte(probeV4)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// same ip/port/proto in the same minute: ignored (not malformed)
|
||||
if _, err := p.parse([]byte(probeV4)); !errors.Is(err, core.ErrIgnored) {
|
||||
t.Fatalf("got %v", err)
|
||||
}
|
||||
// another port is kept
|
||||
if _, err := p.parse([]byte(probeV4[:len(probeV4)-0])); err == nil {
|
||||
t.Fatal("repeat accepted")
|
||||
}
|
||||
other := `2026-11-15T03:20:02+00:00 srv kernel: URUTAU-PROBE: IN=eth0 OUT= SRC=203.0.113.9 DST=1.2.3.4 PROTO=TCP SPT=1 DPT=22 SYN`
|
||||
if _, err := p.parse([]byte(other)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// next minute: kept again
|
||||
next := `2026-11-15T03:21:01+00:00 srv kernel: URUTAU-PROBE: IN=eth0 OUT= SRC=203.0.113.9 DST=1.2.3.4 PROTO=TCP SPT=1 DPT=3389 SYN`
|
||||
if _, err := p.parse([]byte(next)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProbeFamilyMitre(t *testing.T) {
|
||||
fam, tech, _ := store.IntelClassifier(core.Event{Source: "probe", Cat: core.Scanner, Path: "tcp/23 telnet"})
|
||||
if fam != intel.FamPortScan {
|
||||
t.Fatalf("fam %q", fam)
|
||||
}
|
||||
has := false
|
||||
for _, x := range tech {
|
||||
has = has || x == "T1046"
|
||||
}
|
||||
if !has {
|
||||
t.Fatalf("tech %v", tech)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProbeSourceMissingIsWaiting(t *testing.T) {
|
||||
s := &source{name: "probe", path: t.TempDir() + "/absent.log"}
|
||||
if st := s.status(); st.State != "waiting" || st.Error != "" {
|
||||
t.Fatalf("%+v", st)
|
||||
}
|
||||
_ = time.Now
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func NewRunner(c Config, st *store.Store, log *slog.Logger) (*Runner, error) {
|
||||
for _, d := range []struct {
|
||||
name, path string
|
||||
parse func([]byte) (core.Event, error)
|
||||
}{{"traefik", c.TraefikLog, traefikParse}, {"ssh", c.AuthLog, authParse}, {"fail2ban", c.Fail2banLog, f2bParse}} {
|
||||
}{{"traefik", c.TraefikLog, traefikParse}, {"ssh", c.AuthLog, authParse}, {"fail2ban", c.Fail2banLog, f2bParse}, {"probe", c.ProbeLog, newProbeParser().parse}} {
|
||||
if d.path != "" {
|
||||
r.Sources = append(r.Sources, &source{name: d.name, path: d.path, parse: d.parse})
|
||||
}
|
||||
|
||||
@@ -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 = "1.4.0"
|
||||
var Version = "1.4.2"
|
||||
@@ -132,6 +132,8 @@ type Event struct {
|
||||
User string
|
||||
Jail string
|
||||
Status int
|
||||
// Port is the destination port probed (Source "probe"); Proto holds tcp/udp.
|
||||
Port uint16
|
||||
// Unban marks a fail2ban unban (Cat is Ban). Restore marks a ban replayed
|
||||
// by fail2ban after a restart: it updates the ban state but is not scored.
|
||||
Unban bool
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package core
|
||||
|
||||
// PortService is the well-known service of a probed port ("" when unknown).
|
||||
func PortService(proto string, port uint16) string {
|
||||
if proto == "udp" {
|
||||
return udpServices[port]
|
||||
}
|
||||
return tcpServices[port]
|
||||
}
|
||||
|
||||
var tcpServices = map[uint16]string{
|
||||
21: "ftp", 22: "ssh", 23: "telnet", 25: "smtp", 53: "dns", 80: "http", 110: "pop3", 111: "rpcbind", 135: "msrpc",
|
||||
139: "netbios", 143: "imap", 389: "ldap", 443: "https", 445: "smb", 465: "smtps", 587: "submission", 993: "imaps",
|
||||
995: "pop3s", 1433: "mssql", 1521: "oracle", 1723: "pptp", 2049: "nfs", 2375: "docker", 3306: "mysql", 3389: "rdp",
|
||||
5432: "postgres", 5900: "vnc", 5901: "vnc", 6379: "redis", 8080: "http-alt", 8443: "https-alt", 9200: "elasticsearch",
|
||||
11211: "memcached", 27017: "mongodb", 2323: "telnet",
|
||||
}
|
||||
|
||||
var udpServices = map[uint16]string{
|
||||
53: "dns", 69: "tftp", 123: "ntp", 161: "snmp", 389: "cldap", 500: "ike", 1900: "ssdp", 5060: "sip", 11211: "memcached",
|
||||
}
|
||||
@@ -173,6 +173,14 @@ func TestBeaconPositive(t *testing.T) {
|
||||
if hi == nil || hi.Severity != "high" {
|
||||
t.Fatalf("attacker beacon: %+v", hi)
|
||||
}
|
||||
if n := len(got.Samples); n < 40 || n > MaxSamples || got.Samples[n-1] != got.Last {
|
||||
t.Fatalf("samples: %d %v", n, got.Samples)
|
||||
}
|
||||
for i := 1; i < len(got.Samples); i++ {
|
||||
if got.Samples[i] <= got.Samples[i-1] {
|
||||
t.Fatalf("samples not increasing: %v", got.Samples)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeaconNegatives(t *testing.T) {
|
||||
@@ -420,6 +428,34 @@ func TestReportMergeSanitize(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReportByCountry(t *testing.T) {
|
||||
geo := func(s string) (string, string, string) {
|
||||
if s == "203.0.113.1" || s == "203.0.113.2" {
|
||||
return "DE", "AS1", "x"
|
||||
}
|
||||
return "US", "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, "10.0.3.5", "203.0.113.2", "tcp", 443))
|
||||
e.IngestEvent(mk(t0.Add(time.Minute), "10.0.3.5", "203.0.113.2", "tcp", 443))
|
||||
e.IngestEvent(mk(t0, "10.0.3.5", "198.51.100.1", "tcp", 443))
|
||||
r := e.Report(t0.Unix()-3600, t0.Unix()+3600)
|
||||
if len(r.ByCountry) != 2 || r.ByCountry[0].CC != "DE" || r.ByCountry[0].Conns != 3 || r.ByCountry[0].Dsts != 2 || r.ByCountry[1].Conns != 1 {
|
||||
t.Fatalf("by_country: %+v", r.ByCountry)
|
||||
}
|
||||
peer := e.Report(t0.Unix()-3600, t0.Unix()+3600)
|
||||
peer.ByCountry = append(peer.ByCountry, make([]CountryOut, 400)...)
|
||||
peer.Sanitize("p")
|
||||
if len(peer.ByCountry) > maxCountries {
|
||||
t.Fatalf("sanitize: %d", len(peer.ByCountry))
|
||||
}
|
||||
r.Merge(peer, "p")
|
||||
if r.ByCountry[0].CC != "DE" || r.ByCountry[0].Conns != 6 {
|
||||
t.Fatalf("merge: %+v", r.ByCountry[:2])
|
||||
}
|
||||
}
|
||||
|
||||
func TestNameMatchExactAndPrefix(t *testing.T) {
|
||||
e := newEng(t, Config{Workloads: "a=name:web:default;b=name:api*:default;c=name:pay:default"})
|
||||
e.SetContainers(map[netip.Addr]string{ip("172.18.0.1"): "web-1700000000000", ip("172.18.0.2"): "webshell-1700000000000",
|
||||
|
||||
@@ -744,7 +744,14 @@ func suspiciousPort(port uint16, role string) (sev, why string) {
|
||||
|
||||
func (e *Engine) beacon(ws *wstate, ev Event, dport uint16, dns bool, p *pairState, ds *dstStat) {
|
||||
if p.flagged {
|
||||
e.addFinding("beacon", "", ws.name, ev.Dst.String(), dport, ev.Proto, p.last, p.interval, p.cv, "", 1)
|
||||
if f := e.addFinding("beacon", "", ws.name, ev.Dst.String(), dport, ev.Proto, p.last, p.interval, p.cv, "", 1); f != nil {
|
||||
if n := len(f.Samples); n == 0 || f.Samples[n-1] != p.last {
|
||||
if n >= MaxSamples {
|
||||
f.Samples = append(f.Samples[:0], f.Samples[1:]...)
|
||||
}
|
||||
f.Samples = append(f.Samples, p.last)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
ntp := ev.Proto == "udp" && dport == 123
|
||||
@@ -806,6 +813,10 @@ func (e *Engine) beacon(ws *wstate, ev Event, dport uint16, dns bool, p *pairSta
|
||||
f := e.addFinding("beacon", sev, ws.name, ev.Dst.String(), dport, ev.Proto, p.last, med, jit, why, 0)
|
||||
if f != nil {
|
||||
f.Count, f.First = int(p.total), p.first
|
||||
f.Samples = make([]int64, 0, MaxSamples)
|
||||
for i := 0; i < p.n; i++ {
|
||||
f.Samples = append(f.Samples, int64(p.ts[i]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,13 @@ var ErrNotEgress = errors.New("not an egress line")
|
||||
// of the "Nov 14 22:01:02" rsyslog format (and as the time of a line whose
|
||||
// timestamp is unreadable).
|
||||
func ParseLine(b []byte, now time.Time) (Event, error) {
|
||||
return ParseKernel(b, marker, now)
|
||||
}
|
||||
|
||||
// ParseKernel parses an nftables log line carrying the given prefix marker
|
||||
// (for instance "URUTAU-EGRESS:" or "URUTAU-PROBE:"). It is shared by every
|
||||
// source that reads kernel log lines.
|
||||
func ParseKernel(b []byte, marker string, now time.Time) (Event, error) {
|
||||
line := string(b)
|
||||
i := strings.Index(line, marker)
|
||||
if i < 0 {
|
||||
|
||||
@@ -22,6 +22,18 @@ type Finding struct {
|
||||
Last int64 `json:"last"`
|
||||
Detail string `json:"detail"`
|
||||
Host string `json:"host,omitempty"`
|
||||
// Samples are the unix times of the last connections (beacons only, at most MaxSamples).
|
||||
Samples []int64 `json:"samples,omitempty"`
|
||||
}
|
||||
|
||||
// MaxSamples bounds Finding.Samples.
|
||||
const MaxSamples = 64
|
||||
|
||||
// CountryOut sums the destinations of one country.
|
||||
type CountryOut struct {
|
||||
CC string `json:"cc"`
|
||||
Conns uint64 `json:"conns"`
|
||||
Dsts int `json:"dsts"`
|
||||
}
|
||||
|
||||
// WorkloadOut summarises a workload over the window.
|
||||
@@ -79,6 +91,7 @@ type Report struct {
|
||||
TopDst []DstOut `json:"top_dst"`
|
||||
Findings []Finding `json:"findings"`
|
||||
Scanner ScannerOut `json:"scanner"`
|
||||
ByCountry []CountryOut `json:"by_country"`
|
||||
}
|
||||
|
||||
func (bs *burstState) out(wl string, end int64) BurstOut {
|
||||
@@ -133,14 +146,16 @@ func (e *Engine) Report(from, to int64) Report {
|
||||
startH = endH - (HourBuckets - 1)
|
||||
}
|
||||
nb := int(endH-startH) + 1
|
||||
r := Report{Workloads: []WorkloadOut{}, TopDst: []DstOut{}, Findings: []Finding{},
|
||||
r := Report{Workloads: []WorkloadOut{}, TopDst: []DstOut{}, Findings: []Finding{}, ByCountry: []CountryOut{},
|
||||
Timeline: Timeline{Start: startH * 3600, Step: 3600, Series: map[string][]uint32{}},
|
||||
Scanner: ScannerOut{Bursts: []BurstOut{}}}
|
||||
|
||||
fc := map[string]int{}
|
||||
for _, f := range e.findings {
|
||||
if f.Last >= from && f.First <= to {
|
||||
r.Findings = append(r.Findings, *f)
|
||||
c := *f
|
||||
c.Samples = append([]int64(nil), f.Samples...)
|
||||
r.Findings = append(r.Findings, c)
|
||||
fc[f.Workload]++
|
||||
}
|
||||
}
|
||||
@@ -212,6 +227,20 @@ func (e *Engine) Report(from, to int64) Report {
|
||||
}
|
||||
return all[i].ds.ip.Compare(all[j].ds.ip) < 0
|
||||
})
|
||||
bc := map[string]*CountryOut{}
|
||||
for _, a := range all {
|
||||
c := bc[a.ds.cc]
|
||||
if c == nil {
|
||||
c = &CountryOut{CC: a.ds.cc}
|
||||
bc[a.ds.cc] = c
|
||||
}
|
||||
c.Conns += a.n
|
||||
c.Dsts++
|
||||
}
|
||||
for _, c := range bc {
|
||||
r.ByCountry = append(r.ByCountry, *c)
|
||||
}
|
||||
sortCountries(r.ByCountry)
|
||||
for i := 0; i < len(all) && i < 50; i++ {
|
||||
ds := all[i].ds
|
||||
ports := append([]uint16(nil), ds.ports...)
|
||||
@@ -237,8 +266,18 @@ const (
|
||||
maxPeerWorkloads = 256
|
||||
maxPeerFindings = MaxFindings
|
||||
maxStr = 200
|
||||
maxCountries = 300
|
||||
)
|
||||
|
||||
func sortCountries(cs []CountryOut) {
|
||||
sort.Slice(cs, func(i, j int) bool {
|
||||
if cs[i].Conns != cs[j].Conns {
|
||||
return cs[i].Conns > cs[j].Conns
|
||||
}
|
||||
return cs[i].CC < cs[j].CC
|
||||
})
|
||||
}
|
||||
|
||||
func clip(s string) string {
|
||||
if len(s) > maxStr {
|
||||
return s[:maxStr]
|
||||
@@ -268,6 +307,15 @@ func (r *Report) Sanitize(host string) {
|
||||
f := &r.Findings[i]
|
||||
f.ID, f.Kind, f.Severity = host+":"+clip(f.ID), clip(f.Kind), clip(f.Severity)
|
||||
f.Workload, f.Dst, f.Proto, f.Detail, f.Host = clip(f.Workload), clip(f.Dst), clip(f.Proto), clip(f.Detail), host
|
||||
if len(f.Samples) > MaxSamples {
|
||||
f.Samples = f.Samples[len(f.Samples)-MaxSamples:]
|
||||
}
|
||||
}
|
||||
if len(r.ByCountry) > maxCountries {
|
||||
r.ByCountry = r.ByCountry[:maxCountries]
|
||||
}
|
||||
for i := range r.ByCountry {
|
||||
r.ByCountry[i].CC = clip(r.ByCountry[i].CC)
|
||||
}
|
||||
for i := range r.TopDst {
|
||||
d := &r.TopDst[i]
|
||||
@@ -312,6 +360,22 @@ func (r *Report) Merge(o Report, host string) {
|
||||
r.Findings = append(r.Findings, o.Findings...)
|
||||
r.Scanner.Bursts = append(r.Scanner.Bursts, o.Scanner.Bursts...)
|
||||
r.TopDst = append(r.TopDst, o.TopDst...)
|
||||
if len(o.ByCountry) > 0 {
|
||||
idx := map[string]int{}
|
||||
for i, c := range r.ByCountry {
|
||||
idx[c.CC] = i
|
||||
}
|
||||
for _, c := range o.ByCountry {
|
||||
if i, ok := idx[c.CC]; ok {
|
||||
r.ByCountry[i].Conns += c.Conns
|
||||
r.ByCountry[i].Dsts += c.Dsts // a destination reached by two hosts counts twice
|
||||
continue
|
||||
}
|
||||
idx[c.CC] = len(r.ByCountry)
|
||||
r.ByCountry = append(r.ByCountry, c)
|
||||
}
|
||||
sortCountries(r.ByCountry)
|
||||
}
|
||||
sort.SliceStable(r.TopDst, func(i, j int) bool { return r.TopDst[i].Conns > r.TopDst[j].Conns })
|
||||
if len(r.TopDst) > 50 {
|
||||
r.TopDst = r.TopDst[:50]
|
||||
@@ -366,6 +430,6 @@ func (r *Report) Stamp(host string) {
|
||||
|
||||
// EmptyReport is a well-formed report without data.
|
||||
func EmptyReport() Report {
|
||||
return Report{Workloads: []WorkloadOut{}, TopDst: []DstOut{}, Findings: []Finding{}, Scanner: ScannerOut{Bursts: []BurstOut{}},
|
||||
return Report{Workloads: []WorkloadOut{}, TopDst: []DstOut{}, Findings: []Finding{}, ByCountry: []CountryOut{}, Scanner: ScannerOut{Bursts: []BurstOut{}},
|
||||
Timeline: Timeline{Step: 3600, Series: map[string][]uint32{}}}
|
||||
}
|
||||
@@ -95,6 +95,7 @@ type aevt struct {
|
||||
type ipState struct {
|
||||
ev []aevt
|
||||
ssh []int64
|
||||
probes map[uint32]int64 // proto<<16|port -> last seen (unix)
|
||||
legit int64
|
||||
uas []string
|
||||
lastAttack int64
|
||||
@@ -384,6 +385,9 @@ func (e *Engine) process(ev core.Event, fam string) {
|
||||
}
|
||||
return
|
||||
case ev.Cat == core.SSHFail:
|
||||
case ev.Source == "probe" && ev.Cat == core.Scanner:
|
||||
e.processProbe(a, ev, now)
|
||||
return
|
||||
case CountsAsAttack(ev):
|
||||
default:
|
||||
return
|
||||
@@ -721,3 +725,32 @@ func (e *Engine) saveState() {
|
||||
e.dirty = true
|
||||
e.mu.Unlock()
|
||||
}
|
||||
|
||||
// processProbe counts the distinct ports a network probe touched in Window; a
|
||||
// scan of PortScanPorts or more is a ban. Probes never count as web attacks.
|
||||
func (e *Engine) processProbe(a netip.Addr, ev core.Event, now time.Time) {
|
||||
ts := ev.Time.Unix()
|
||||
cut := now.Add(-Window).Unix()
|
||||
if ts < cut || ev.Port == 0 {
|
||||
return
|
||||
}
|
||||
st := e.stateOf(a)
|
||||
st.lastAttack = max(st.lastAttack, ts)
|
||||
if st.probes == nil {
|
||||
st.probes = map[uint32]int64{}
|
||||
}
|
||||
var proto uint32
|
||||
if ev.Proto == "udp" {
|
||||
proto = 1
|
||||
}
|
||||
k := proto<<16 | uint32(ev.Port)
|
||||
st.probes[k] = max(st.probes[k], ts)
|
||||
for key, t := range st.probes {
|
||||
if t < cut {
|
||||
delete(st.probes, key)
|
||||
}
|
||||
}
|
||||
in := Input{Now: now, Probes: len(st.probes), Exclude: e.excl.Excluded(a)}
|
||||
e.fill(a, st, &in, now)
|
||||
e.apply(a, st, Decide(in, Params{Threshold: e.cfg.Threshold}), "local", now)
|
||||
}
|
||||
@@ -33,12 +33,14 @@ const (
|
||||
ReasonWebshell = "webshell"
|
||||
ReasonSQLi = "sqli"
|
||||
ReasonLog4Shell = "log4shell"
|
||||
ReasonPortScan = "port-scan"
|
||||
)
|
||||
|
||||
var reasons = map[string]bool{
|
||||
ReasonScannerFlood: true, ReasonExploitFlood: true, ReasonWebBrute: true, ReasonWPBrute: true,
|
||||
ReasonSSHBrute: true, ReasonRCE: true, ReasonTraversal: true, ReasonEnvProbe: true,
|
||||
ReasonVCSProbe: true, ReasonWebshell: true, ReasonSQLi: true, ReasonLog4Shell: true,
|
||||
ReasonPortScan: true,
|
||||
}
|
||||
|
||||
// ValidReason reports whether s is one of the fixed slugs.
|
||||
@@ -60,6 +62,8 @@ const (
|
||||
Window = 10 * time.Minute
|
||||
LegitWindow = 24 * time.Hour
|
||||
SSHThreshold = 5
|
||||
// PortScanPorts distinct ports probed in Window justify a ban.
|
||||
PortScanPorts = 10
|
||||
// CritHits is how many critical events of one address (in Window) justify a ban.
|
||||
CritHits = 2
|
||||
)
|
||||
@@ -104,6 +108,7 @@ type Input struct {
|
||||
Attacks int // counted attack events in the window
|
||||
Top string // reason slug of the dominant attack in the window
|
||||
SSHFails int // failed SSH logins in the window
|
||||
Probes int // distinct (proto, port) probed in the window
|
||||
Crit string // reason of a critical family hit just seen, "" if none
|
||||
Crits int // critical events of the address in the window (a single hit is not enough)
|
||||
Legit bool // a document 2xx from a browser within the last 24 h
|
||||
@@ -141,6 +146,8 @@ func Decide(in Input, p Params) Decision {
|
||||
reason, score = in.Crit, 90
|
||||
case in.SSHFails >= sshTh:
|
||||
reason, score = ReasonSSHBrute, min(100, 60+(in.SSHFails-sshTh)*5)
|
||||
case in.Probes >= PortScanPorts:
|
||||
reason, score = ReasonPortScan, min(100, 60+(in.Probes-PortScanPorts)*3)
|
||||
case in.Attacks >= th:
|
||||
reason, score = in.Top, min(100, 55+(in.Attacks-th)*5)
|
||||
if !ValidReason(reason) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package enforce
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
||||
)
|
||||
|
||||
func probe(ip string, at time.Time, port uint16) core.Event {
|
||||
return core.Event{Time: at, IP: ip, Cat: core.Scanner, Source: "probe", Proto: "tcp", Port: port}
|
||||
}
|
||||
|
||||
func TestPortScanBan(t *testing.T) {
|
||||
r := newRig(t, ModeOn, nil)
|
||||
for i := 0; i < 9; i++ {
|
||||
r.e.process(probe("203.0.114.60", r.now.Add(-time.Duration(i)*time.Second), uint16(1000+i)), "")
|
||||
}
|
||||
// the same port again does not add up
|
||||
r.e.process(probe("203.0.114.60", r.now, 1000), "")
|
||||
if len(r.lines(t)) != 0 {
|
||||
t.Fatal("banned below 10 distinct ports")
|
||||
}
|
||||
r.e.process(probe("203.0.114.60", r.now, 3389), "")
|
||||
if l := r.lines(t); len(l) != 1 || !strings.Contains(l[0], "reason=port-scan") {
|
||||
t.Fatalf("%q", l)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPortScanExcludedAndOld(t *testing.T) {
|
||||
r := newRig(t, ModeOn, nil)
|
||||
for i := 0; i < 12; i++ { // trusted network
|
||||
r.e.process(probe("45.1.1.1", r.now, uint16(2000+i)), "")
|
||||
}
|
||||
for i := 0; i < 12; i++ { // outside the window
|
||||
r.e.process(probe("203.0.114.61", r.now.Add(-time.Hour), uint16(2000+i)), "")
|
||||
}
|
||||
if len(r.lines(t)) != 0 {
|
||||
t.Fatal("excluded or old probes banned")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPortScanReasonValid(t *testing.T) {
|
||||
if !ValidReason(ReasonPortScan) {
|
||||
t.Fatal("port-scan reason not valid")
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,8 @@ type Rec struct {
|
||||
Bytes int64 `json:"bytes"`
|
||||
DurMS int64 `json:"dur_ms"`
|
||||
Flags string `json:"flags"`
|
||||
Port int `json:"port,omitempty"`
|
||||
Proto string `json:"proto,omitempty"`
|
||||
}
|
||||
|
||||
// Item is a parsed line with its raw JSON.
|
||||
|
||||
@@ -28,6 +28,7 @@ const (
|
||||
FamIoTCGI = "iot-cgi"
|
||||
FamAdminPanel = "admin-panel"
|
||||
FamGeneric404 = "generic-404"
|
||||
FamPortScan = "port-scan"
|
||||
maxPathScan = 8192
|
||||
maxPathScanTop = maxPathScan / 2
|
||||
)
|
||||
|
||||
@@ -102,6 +102,9 @@ func Techniques(cat, fam string, ctx TechCtx) []string {
|
||||
switch core.Category(cat) {
|
||||
case core.Scanner:
|
||||
switch {
|
||||
case fam == FamPortScan:
|
||||
set["T1595.001"] = true
|
||||
set["T1046"] = true
|
||||
case hasTool(tool, vulnTools):
|
||||
set["T1595.002"] = true
|
||||
case hasTool(tool, wordTools):
|
||||
|
||||
@@ -18,7 +18,14 @@ func init() {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
writeJSON(w, 200, store.CampaignsOf(p))
|
||||
out := store.CampaignsOf(p)
|
||||
page, per := pageParams(r.URL.Query())
|
||||
from, to := window(len(out.Campaigns), page, per)
|
||||
out.Campaigns = out.Campaigns[from:to]
|
||||
writeJSON(w, 200, struct {
|
||||
store.CampaignsOut
|
||||
pageMeta
|
||||
}{out, metaOf(out.Total, page, per)})
|
||||
}
|
||||
})
|
||||
registerUserRoute("GET /api/v1/campaigns/{id}", func(s *Server) http.HandlerFunc {
|
||||
|
||||