feat: 1.4.1 pagination, network probes, survival by blocker, report polish
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

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>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 00:21:43 -03:00
1 parent f27d8441a9
commit 432f521ed1
40 files changed
+927 -136

No files matched your search

+33
View File
@@ -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)
}
+7
View File
@@ -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) {
+48
View File
@@ -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")
}
}