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>
90 lines
2.0 KiB
Go
90 lines
2.0 KiB
Go
package app
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log/slog"
|
|
"net/netip"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/intel"
|
|
)
|
|
|
|
const (
|
|
maxTorFile = 8 << 20
|
|
maxTorExits = 100000
|
|
)
|
|
|
|
// LoadTorExits reads a file with one address per line (blank lines and #
|
|
// comments are skipped, invalid lines ignored, at most 100000 addresses).
|
|
func LoadTorExits(path string) ([]netip.Addr, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
if st, err := f.Stat(); err != nil || !st.Mode().IsRegular() {
|
|
return nil, errors.New("not a regular file")
|
|
} else if st.Size() > maxTorFile {
|
|
return nil, fmt.Errorf("file larger than %d bytes", maxTorFile)
|
|
}
|
|
var out []netip.Addr
|
|
sc := bufio.NewScanner(f)
|
|
sc.Buffer(make([]byte, 0, 4096), 4096)
|
|
for sc.Scan() && len(out) < maxTorExits {
|
|
l := strings.TrimSpace(sc.Text())
|
|
if i := strings.IndexByte(l, '#'); i >= 0 {
|
|
l = strings.TrimSpace(l[:i])
|
|
}
|
|
if a, err := netip.ParseAddr(l); err == nil && a.Zone() == "" {
|
|
out = append(out, a.Unmap())
|
|
}
|
|
}
|
|
return out, sc.Err()
|
|
}
|
|
|
|
// watchTorExits loads the list now and again every interval when the file
|
|
// changed. An empty path keeps the feature off.
|
|
func watchTorExits(ctx context.Context, path string, every time.Duration, log *slog.Logger) {
|
|
if path == "" {
|
|
return
|
|
}
|
|
var lastMod time.Time
|
|
var lastSize int64 = -1
|
|
load := func() {
|
|
st, err := os.Stat(path)
|
|
if err != nil {
|
|
log.Warn("tor exit list unavailable", "err", err)
|
|
return
|
|
}
|
|
if st.ModTime().Equal(lastMod) && st.Size() == lastSize {
|
|
return
|
|
}
|
|
addrs, err := LoadTorExits(path)
|
|
if err != nil {
|
|
log.Warn("tor exit list unreadable", "err", err)
|
|
return
|
|
}
|
|
intel.SetTorExits(addrs)
|
|
lastMod, lastSize = st.ModTime(), st.Size()
|
|
log.Info("tor exit list loaded", "n", len(addrs))
|
|
}
|
|
load()
|
|
go func() {
|
|
t := time.NewTicker(every)
|
|
defer t.Stop()
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case <-t.C:
|
|
load()
|
|
}
|
|
}
|
|
}()
|
|
}
|