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>
83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
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 ""
|
|
}
|