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
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:
1 parent
8f1ac462d1
commit
b7462c14fa
325 files changed
+19117
-1307
No files matched your search
@@ -0,0 +1,197 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/evlog"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/server"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/tail"
|
||||
)
|
||||
|
||||
const (
|
||||
scratch = "/tmp/claude-1000/-home-lucas-Documents-Pessoal-keys/cd25aef5-8f8d-45f2-8ce0-f6644a45cb62/scratchpad"
|
||||
tokV4 = "user-token-0123456789-abcdefghijklmnop"
|
||||
)
|
||||
|
||||
// ingestLogs feeds the three log files through the runner, like a backfill.
|
||||
func ingestLogs(t *testing.T, st *store.Store, dir string) {
|
||||
t.Helper()
|
||||
c := Config{Name: st.Name(), Ignore: DefaultIgnore, MonitorUA: DefaultMonitorUA, Retention: 720 * time.Hour, TrustedProxy: DefaultTrustedProxy,
|
||||
TraefikLog: filepath.Join(dir, "access.log"), AuthLog: filepath.Join(dir, "auth.log"), Fail2banLog: filepath.Join(dir, "fail2ban.log")}
|
||||
r, err := NewRunner(c, st, slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, s := range r.Sources {
|
||||
if _, err := os.Stat(s.path); err != nil {
|
||||
continue
|
||||
}
|
||||
if err := tail.ReadAll(s.path, maxLine, r.handle(s), func() {}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func newLogged(t *testing.T) *store.Store {
|
||||
st := store.New(store.Config{Name: "edge-1", Version: "t", Retention: 720 * time.Hour})
|
||||
l, err := evlog.Open(evlog.Options{Dir: filepath.Join(t.TempDir(), "events")})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st.SetEventLog(l)
|
||||
return st
|
||||
}
|
||||
|
||||
func detail(t *testing.T, st *store.Store, ip string) map[string]any {
|
||||
h := server.New(server.Options{Token: tokV4, Version: "t", Store: st})
|
||||
r := httptest.NewRequest("GET", "/api/v1/ip/"+ip, nil)
|
||||
r.Header.Set("Authorization", "Bearer "+tokV4)
|
||||
r.RemoteAddr = "198.51.100.1:1"
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, r)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("%s: %d %s", ip, w.Code, w.Body)
|
||||
}
|
||||
var m map[string]any
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func sum(series map[string]any) (total float64, buckets int) {
|
||||
var rows [][]any
|
||||
for _, v := range series {
|
||||
rows = append(rows, v.([]any))
|
||||
}
|
||||
if len(rows) == 0 {
|
||||
return
|
||||
}
|
||||
for i := range rows[0] {
|
||||
var b float64
|
||||
for _, r := range rows {
|
||||
b += r[i].(float64)
|
||||
}
|
||||
total += b
|
||||
if b > 0 {
|
||||
buckets++
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func num(m map[string]any, k string) float64 { f, _ := m[k].(float64); return f }
|
||||
|
||||
// checkConsistent asserts that every section of the detail view of the most
|
||||
// hostile address of a data set tells the same story.
|
||||
func checkConsistent(t *testing.T, st *store.Store, wantEvents bool) {
|
||||
t.Helper()
|
||||
ips := st.AllIPs(store.Ranges["30d"], false)
|
||||
if len(ips) == 0 {
|
||||
t.Fatal("no addresses")
|
||||
}
|
||||
top := ips[0].IP
|
||||
d := detail(t, st, top)
|
||||
counts := d["counts"].(map[string]any)
|
||||
first, last := num(d, "first"), num(d, "last")
|
||||
tm := d["time"].(map[string]any)
|
||||
if ad, span := num(tm, "active_days"), num(tm, "span_days"); ad < 1 || ad > span || span != float64(int((last-first)/86400)+1) {
|
||||
t.Errorf("%s: active_days %v span_days %v first %v last %v", top, ad, span, first, last)
|
||||
}
|
||||
ssh := d["ssh"].(map[string]any)
|
||||
if num(ssh, "fails") != num(counts, "ssh-fail") {
|
||||
t.Errorf("%s: ssh.fails %v vs counter %v", top, ssh["fails"], counts["ssh-fail"])
|
||||
}
|
||||
if num(counts, "ssh-fail") > 0 && len(ssh["users"].([]any)) == 0 && num(d, "events") == 0 {
|
||||
t.Errorf("%s: ssh failures but no users", top)
|
||||
}
|
||||
if jails, _ := d["jails"].([]any); len(jails) > 0 {
|
||||
active := 0
|
||||
for _, b := range d["bans"].([]any) {
|
||||
if b.(map[string]any)["active"] == true {
|
||||
active++
|
||||
}
|
||||
}
|
||||
if active != len(jails) {
|
||||
t.Errorf("%s: %d active bans for %d jails: %v", top, active, len(jails), d["bans"])
|
||||
}
|
||||
}
|
||||
if len(d["sessions"].([]any)) == 0 {
|
||||
t.Errorf("%s: no sessions for an address with %v events", top, counts)
|
||||
}
|
||||
if len(d["techniques"].([]any)) == 0 || len(d["families"].([]any)) == 0 {
|
||||
t.Errorf("%s: techniques/families empty: %v / %v", top, d["techniques"], d["families"])
|
||||
}
|
||||
if len(d["events"].([]any)) == 0 {
|
||||
t.Errorf("%s: events empty", top)
|
||||
}
|
||||
tl := d["timeline"].(map[string]any)
|
||||
total, buckets := sum(tl["series"].(map[string]any))
|
||||
if total == 0 {
|
||||
t.Errorf("%s: timeline is empty", top)
|
||||
}
|
||||
if wantEvents {
|
||||
if d["timeline_source"] != "events" || d["sessions_source"] != "events" || d["events_source"] != "events" {
|
||||
t.Errorf("%s: sources %v %v %v", top, d["timeline_source"], d["sessions_source"], d["events_source"])
|
||||
}
|
||||
lg := d["log"].(map[string]any)
|
||||
logEvents, n := num(lg, "events"), num(lg, "sessions_events")
|
||||
if n != logEvents || total != logEvents || num(tm, "sessions_n") != num(lg, "sessions_n") {
|
||||
t.Errorf("%s: sessions %v timeline %v log %v must agree", top, n, total, logEvents)
|
||||
}
|
||||
if tm["active_days"].(float64) > 1 && buckets < 2 {
|
||||
t.Errorf("%s: timeline in %d bucket(s) for %v active days", top, buckets, tm["active_days"])
|
||||
}
|
||||
// the timeline sits at the hours of the events, not at the time of the ingestion
|
||||
step, start := num(tl, "step"), num(tl, "start")
|
||||
for i, v := range tl["series"].(map[string]any)["scanner"].([]any) {
|
||||
if v.(float64) > 0 {
|
||||
if at := start + float64(i)*step; at < first-3600 || at > last+3600 {
|
||||
t.Errorf("%s: bar at %v outside [%v, %v]", top, at, first, last)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if d["sessions_source"] != "counters" || d["events_source"] != "counters" {
|
||||
t.Errorf("%s: without a registry the sections must say counters: %v %v", top, d["sessions_source"], d["events_source"])
|
||||
}
|
||||
// a snapshot restored next to an empty registry (events before the registry existed)
|
||||
if wantEvents {
|
||||
p := filepath.Join(t.TempDir(), "s.gob")
|
||||
if err := st.Save(p, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st2 := newLogged(t)
|
||||
if _, err := st2.Load(p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
checkConsistent(t, st2, false)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPDetailConsistentOnSyntheticLogs(t *testing.T) {
|
||||
dirs := map[string]string{"ui-shell": scratch + "/ui-shell/logs", "demo": scratch + "/demo/logs"}
|
||||
ran := 0
|
||||
for name, dir := range dirs {
|
||||
if _, err := os.Stat(filepath.Join(dir, "access.log")); err != nil {
|
||||
continue
|
||||
}
|
||||
ran++
|
||||
t.Run(name, func(t *testing.T) {
|
||||
st := newLogged(t)
|
||||
ingestLogs(t, st, dir)
|
||||
checkConsistent(t, st, true)
|
||||
})
|
||||
}
|
||||
if ran == 0 {
|
||||
t.Skip("synthetic data sets not available")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user