feat: 1.2.0 attack intelligence, replay, 30-day history and new interface
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 27s
CI / Dependency audit (push) Successful in 18s
CI / Tests (Linux, race detector) (push) Successful in 58s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 5s

Intelligence: attack families mapped to MITRE ATT&CK, network type from
ASN/rDNS without external APIs, request cadence, sessions with
recon/probe/exploit/access/banned stages, campaigns across IPs, verdict
with reasons, recommended actions, exposure detection (2xx with a body
on sensitive paths), STIX 2.1 export, FCrDNS for search engine bots,
optional Tor exit list.

Data: 30-day retention, twelve ranges plus custom from/to, an on-disk
event log (daily files, hourly gzip members, size cap, corruption and
disk-full tolerant), /events, /period, /metrics with stable per-hour
metrics, an extended /ip/{ip}, and peer /period merged on the hub.

Interface: layout system with fixed card sizes, range picker in the
URL, IP analysis page, Replay page, Geography down to state and city
(Natural Earth admin-1), Live page redesigned with stable metrics and a
reusable attack map. Demo data and documentation screenshots.

Security: bounded and deadline-limited period computations, linear
campaign clustering, singleflight caches, sanitized peer studies, event
query budgets, gzip bomb guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-14 21:45:59 -03:00
1 parent 8f1ac462d1
commit b7462c14fa
325 files changed
+19117 -1307

No files matched your search

+165 -3
View File
@@ -10,7 +10,7 @@ import (
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
)
const snapshotVersion = 1
const snapshotVersion = 2
// Offset is a saved read position of a log file.
type Offset struct {
@@ -33,6 +33,33 @@ type snapshot struct {
Recent []FeedEvent
Rhead int
Offsets map[string]Offset
IDSeq uint64
}
// Version 1 snapshots (7 days: minute buckets for the whole window, 168 hour
// slots, 8 analytics days) are read and converted on load.
type snapshotV1 struct {
V int
Saved int64
Stamps [7 * 24 * 60]int64
Counts [7 * 24 * 60][core.NumCats]uint32
Hours [7 * 24]hourSlot
MonSt [7 * 24 * 60]int64
MonN [7 * 24 * 60]uint32
Dom map[string]*domDataV1
IPs map[string]*IPRec
Recent []FeedEvent
Rhead int
Offsets map[string]Offset
}
type domDataV1 struct {
MinSt [24 * 60]int64
MinReq [24 * 60]uint32
MinPages [24 * 60]uint32
Hours [7 * 24]anHour
Days [8]anDay
Last int64
}
// Save writes the state atomically (tmp + rename).
@@ -45,7 +72,7 @@ func (s *Store) Save(path string, offsets map[string]Offset) error {
bw := bufio.NewWriterSize(f, 256*1024)
s.mu.RLock()
snap := snapshot{V: snapshotVersion, Saved: s.now().Unix(), Stamps: s.stamps, Counts: s.counts, Hours: s.hours, MonSt: s.monSt, MonN: s.monN, Dom: s.tr.dom,
IPs: s.ips, Recent: s.recent, Rhead: s.rhead, Offsets: offsets}
IPs: s.ips, Recent: s.recent, Rhead: s.rhead, Offsets: offsets, IDSeq: s.ids.Load()}
err = gob.NewEncoder(bw).Encode(&snap)
s.mu.RUnlock()
if err == nil {
@@ -77,7 +104,17 @@ func (s *Store) Load(path string) (map[string]Offset, error) {
defer f.Close()
var snap snapshot
if err := gob.NewDecoder(bufio.NewReaderSize(f, 256*1024)).Decode(&snap); err != nil {
return nil, err
// not a version 2 stream: try the version 1 layout
var v1 snapshotV1
f1, oerr := os.Open(path)
if oerr != nil {
return nil, err
}
defer f1.Close()
if err1 := gob.NewDecoder(bufio.NewReaderSize(f1, 256*1024)).Decode(&v1); err1 != nil || v1.V != 1 {
return nil, err
}
snap = s.migrateV1(&v1)
}
if snap.V != snapshotVersion {
return nil, errors.New("snapshot version mismatch")
@@ -97,6 +134,27 @@ func (s *Store) Load(path string) (map[string]Offset, error) {
}
}
}
for ip, r := range snap.IPs {
if r == nil {
delete(snap.IPs, ip)
}
}
nowU := s.now().Unix()
for _, r := range snap.IPs {
// records saved before ListedSince existed: the best estimate is the last event
if r.ListedSince == 0 && listedRule(r, nowU) {
r.ListedSince = r.Last
}
// records saved before the day counters existed: spread the totals
// evenly over the days between the first and the last event (an
// estimate; the registry refines it where it has data)
if len(r.DayCats) == 0 {
spreadDays(r)
}
}
if snap.IDSeq > s.ids.Load() {
s.ids.Store(snap.IDSeq)
}
s.ips = snap.IPs
if s.ips == nil {
s.ips = map[string]*IPRec{}
@@ -123,3 +181,107 @@ func (s *Store) Load(path string) (map[string]Offset, error) {
// EnsureDir creates the directory of a snapshot path.
func EnsureDir(path string) error { return os.MkdirAll(filepath.Dir(path), 0o700) }
// migrateV1 converts a version 1 snapshot without losing data: the minute
// buckets older than the new minute window are folded into hour buckets.
func (s *Store) migrateV1(v *snapshotV1) snapshot {
n := snapshot{V: snapshotVersion, Saved: v.Saved, IPs: v.IPs, Recent: v.Recent, Rhead: v.Rhead, Offsets: v.Offsets}
// hour slots: same hour numbers, now with category counts
for _, h := range v.Hours {
if h.Hour != 0 {
n.Hours[int(h.Hour%hourSlots)] = h
}
}
for i, m := range v.Stamps {
if m == 0 {
continue
}
hr := m / 60
hs := &n.Hours[int(hr%hourSlots)]
if hs.Hour != hr {
*hs = hourSlot{Hour: hr}
}
for c, k := range v.Counts[i] {
hs.C[c] += k
}
j := int(m % slots)
if n.Stamps[j] < m {
n.Stamps[j], n.Counts[j] = m, v.Counts[i]
}
}
for i, m := range v.MonSt {
if m == 0 {
continue
}
hr := m / 60
hs := &n.Hours[int(hr%hourSlots)]
if hs.Hour != hr {
*hs = hourSlot{Hour: hr}
}
hs.Mon += v.MonN[i]
j := int(m % slots)
if n.MonSt[j] < m {
n.MonSt[j], n.MonN[j] = m, v.MonN[i]
}
}
n.Dom = make(map[string]*domData, len(v.Dom))
for name, d := range v.Dom {
if d == nil {
continue
}
nd := &domData{Last: d.Last}
for i, m := range d.MinSt {
if m == 0 {
continue
}
j := int(m % anMinutes)
nd.MinSt[j], nd.MinReq[j], nd.MinPages[j] = m, d.MinReq[i], d.MinPages[i]
}
for _, h := range d.Hours {
if h.Hour != 0 {
nd.Hours[int(h.Hour%hourSlots)] = h
}
}
for _, dd := range d.Days {
if dd.Day != 0 {
nd.Days[int(dd.Day%anDays)] = dd
}
}
n.Dom[name] = nd
}
return n
}
// spreadDays estimates the per-day counters of an old record from its totals.
func spreadDays(r *IPRec) {
var tot uint32
for _, n := range r.Counts {
tot += n
}
if tot == 0 || r.Last == 0 {
return
}
last := r.Last / 86400
nd := int(last - r.First/86400 + 1)
nd = max(1, min(nd, 30))
r.DayBase, r.DayEst, r.Days = last, true, 0
r.DayCats = make([][core.NumCats]uint16, nd)
for c, n := range r.Counts {
base, rem := n/uint32(nd), int(n%uint32(nd))
for k := 0; k < nd; k++ {
v := base
if k < rem {
v++
}
r.DayCats[k][c] = uint16(min(v, 65535))
}
}
for k := 0; k < nd; k++ {
for _, v := range r.DayCats[k] {
if v > 0 {
r.Days |= 1 << uint(k)
break
}
}
}
}