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
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:
1 parent
f27d8441a9
commit
432f521ed1
40 files changed
+927
-136
No files matched your search
@@ -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.1"
|
||||
Reference in new issue
Block a user