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

+133 -4
View File
@@ -61,9 +61,22 @@ type peerState struct {
latency int64
version string
exports map[string]store.PeerExport
extra map[string]*extraExport // on-demand windows
studies map[string]*studyCached
live bool
}
// extraExport is an export of a window outside the background set.
type extraExport struct {
at time.Time
e store.PeerExport
}
const (
extraTTL = 15 * time.Second
extraMax = 12 // cached on-demand exports per peer
)
// Hub polls peers and serves their latest summaries.
type Hub struct {
Peers []Peer
@@ -78,6 +91,10 @@ type Hub struct {
mu sync.RWMutex
state map[string]*peerState
// OnLive, when set, sees every sanitized peer event before it is published
// (it assigns the local id and registers it in the event log).
OnLive func(*store.LiveEvent)
}
// NewHub creates a hub; Interval defaults to 15 seconds.
@@ -88,7 +105,7 @@ func NewHub(peers []Peer, token string) *Hub {
tr.ResponseHeaderTimeout = 10 * time.Second
h.stream = &http.Client{Transport: tr, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
for _, p := range peers {
h.state[p.Name] = &peerState{exports: map[string]store.PeerExport{}}
h.state[p.Name] = &peerState{exports: map[string]store.PeerExport{}, extra: map[string]*extraExport{}}
}
return h
}
@@ -139,7 +156,7 @@ func (h *Hub) Refresh(ctx context.Context) {
exports := map[string]store.PeerExport{}
var lat time.Duration
var ferr error
for name := range store.Ranges {
for _, name := range store.BackgroundRanges {
var e store.PeerExport
d, err := h.get(ctx, p, "/api/v1/peer/export?range="+name, &e)
if err == nil {
@@ -172,6 +189,106 @@ func (h *Hub) Refresh(ctx context.Context) {
wg.Wait()
}
// fetchRange asks a peer for the export of a window and sanitizes it.
func (h *Hub) fetchRange(ctx context.Context, p Peer, rg store.Range) (store.PeerExport, error) {
var e store.PeerExport
path := "/api/v1/peer/export?range=" + url.QueryEscape(rg.Name)
if rg.Custom() {
path = fmt.Sprintf("/api/v1/peer/export?from=%d&to=%d", rg.From, rg.To)
}
if _, err := h.get(ctx, p, path, &e); err != nil {
return e, err
}
if err := e.SanitizeRange(rg); err != nil {
return e, err
}
e.Summary = rename(e.Summary, p.Name)
return e, nil
}
// exportsFor returns the exports of the online peers (or one) for a window:
// the cached background ones, or an on-demand fetch cached for 15 s.
func (h *Hub) exportsFor(ctx context.Context, rg store.Range, only string) map[string]store.PeerExport {
out := map[string]store.PeerExport{}
var mu sync.Mutex
var wg sync.WaitGroup
for _, p := range h.Peers {
if only != "" && only != p.Name {
continue
}
h.mu.RLock()
st := h.state[p.Name]
online := st.online
var cached *store.PeerExport
if !rg.Custom() {
if e, ok := st.exports[rg.Name]; ok {
cached = &e
}
}
if cached == nil {
if x := st.extra[rg.Key()]; x != nil && time.Since(x.at) < extraTTL {
e := x.e
cached = &e
}
}
h.mu.RUnlock()
if !online {
continue
}
if cached != nil {
out[p.Name] = *cached
continue
}
wg.Add(1)
go func(p Peer) {
defer wg.Done()
e, err := h.fetchRange(ctx, p, rg)
if err != nil {
return
}
h.mu.Lock()
st := h.state[p.Name]
if len(st.extra) >= extraMax {
st.extra = map[string]*extraExport{}
}
st.extra[rg.Key()] = &extraExport{at: time.Now(), e: e}
h.mu.Unlock()
mu.Lock()
out[p.Name] = e
mu.Unlock()
}(p)
}
wg.Wait()
return out
}
// SummariesFor returns the summaries of online peers for any window.
func (h *Hub) SummariesFor(ctx context.Context, rg store.Range, only string) []store.Summary {
m := h.exportsFor(ctx, rg, only)
var out []store.Summary
for _, p := range h.Peers {
if e, ok := m[p.Name]; ok {
out = append(out, e.Summary)
}
}
return out
}
// TrafficFor returns the analytics of online peers for any window and domain.
func (h *Hub) TrafficFor(ctx context.Context, rg store.Range, domain, only string) []store.TrafficData {
m := h.exportsFor(ctx, rg, only)
var out []store.TrafficData
for _, p := range h.Peers {
if e, ok := m[p.Name]; ok {
if t, ok := e.Traffic[domain]; ok {
t.Host = p.Name
out = append(out, t)
}
}
}
return out
}
// rename forces the configured peer name on every row of a remote summary.
func rename(s store.Summary, name string) store.Summary {
s.Host = name
@@ -248,6 +365,18 @@ func (h *Hub) Summaries(rangeName, only string) []store.Summary {
return out
}
// Peers lists the configured peer names (nil-safe).
func (h *Hub) PeerNames() []string {
if h == nil {
return nil
}
out := make([]string, 0, len(h.Peers))
for _, p := range h.Peers {
out = append(out, p.Name)
}
return out
}
// Has reports whether name is a configured peer.
func (h *Hub) Has(name string) bool {
for _, p := range h.Peers {
@@ -259,14 +388,14 @@ func (h *Hub) Has(name string) bool {
}
// IPDetail looks an address up in the cached exports of the online peers (the
// 7-day summary, which carries the full row). No request is made to the peer.
// 30-day summary, which carries the full row). No request is made to the peer.
func (h *Hub) IPDetail(ip string) []store.IPSummary {
h.mu.RLock()
defer h.mu.RUnlock()
var out []store.IPSummary
for _, p := range h.Peers {
st := h.state[p.Name]
e, ok := st.exports["7d"]
e, ok := st.exports["30d"]
if !ok || !st.online {
continue
}