Files
urutau/internal/server/v3_test.go
T
Lucas RayanandClaude Opus 5.5 b7462c14fa
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
feat: 1.2.0 attack intelligence, replay, 30-day history and new interface
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>
2026-11-14 21:45:59 -03:00

96 lines
4.0 KiB
Go

package server
import (
"encoding/json"
"net/http"
"path/filepath"
"testing"
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/evlog"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
)
type fakeRDNS struct{ calls *int }
func (fakeRDNS) Lookup(string) string { return "" }
func (f fakeRDNS) FCrDNS(ip string, suffixes []string) bool {
*f.calls++
return ip == "66.249.66.1" && suffixes[0] == "googlebot.com"
}
func TestIPDetailGapsClosed(t *testing.T) {
st := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour, AdminUsers: []string{"lucas"}})
l, _ := evlog.Open(evlog.Options{Dir: filepath.Join(t.TempDir(), "events")})
st.SetEventLog(l)
calls := 0
st.SetRDNS(fakeRDNS{&calls})
now := time.Now()
// a crawler that claims to be Googlebot: verified; a plain scanner: null
st.Ingest(core.Event{Time: now, IP: "66.249.66.1", Cat: core.Scanner, Source: "traefik", Method: "GET", Path: "/.env", Status: 404, UA: "Mozilla/5.0 (compatible; Googlebot/2.1)"})
st.Ingest(core.Event{Time: now, IP: "6.6.6.6", Cat: core.Scanner, Source: "traefik", Method: "GET", Path: "/.env", Status: 404, UA: "Googlebot/2.1"})
st.Ingest(core.Event{Time: now, IP: "1.1.1.1", Cat: core.Scanner, Source: "traefik", Method: "GET", Path: "/.env", Status: 404, UA: "curl/8"})
// a forged monitor, hostile enough to be listed
for i := 0; i < 7; i++ {
st.Ingest(core.Event{Time: now.Add(-time.Duration(i) * time.Minute), IP: "9.9.9.9", Cat: core.Exploit, Strong: true, Forged: true, Source: "traefik",
Method: "GET", Path: "/.git/config", Status: 404, UA: "Uptime-Kuma/1.0", Domain: "a.example"})
}
// SSH failures with an admin user among them
for _, u := range []string{"root", "lucas", "root"} {
st.Ingest(core.Event{Time: now, IP: "9.9.9.9", Cat: core.SSHFail, Source: "ssh", User: u})
}
// three addresses doing the same: a campaign
for _, ip := range []string{"20.0.0.1", "20.0.0.2", "20.0.0.3"} {
for _, p := range []string{"/wp-login.php", "/xmlrpc.php"} {
st.Ingest(core.Event{Time: now.Add(-time.Hour), IP: ip, Cat: core.Scanner, Source: "traefik", Method: "GET", Path: p, Status: 404, UA: "zgrab/0.x"})
}
}
h := New(Options{Token: userTok, Version: "t", Store: st})
auth := map[string]string{"Authorization": "Bearer " + userTok}
id := func(ip string) map[string]any {
return getJSON(t, h, "/api/v1/ip/"+ip, auth)["identity"].(map[string]any)
}
if id("66.249.66.1")["fcrdns_ok"] != true || id("6.6.6.6")["fcrdns_ok"] != false || id("1.1.1.1")["fcrdns_ok"] != nil {
t.Fatalf("fcrdns: %v %v %v", id("66.249.66.1"), id("6.6.6.6"), id("1.1.1.1"))
}
if calls == 0 || calls > 4 {
t.Fatalf("only claimants are verified: %d", calls)
}
d := getJSON(t, h, "/api/v1/ip/9.9.9.9", auth)
if d["tools"].(map[string]any)["forged"] != true {
t.Fatalf("forged: %v", d["tools"])
}
if getJSON(t, h, "/api/v1/ip/1.1.1.1", auth)["tools"].(map[string]any)["forged"] != false {
t.Fatal("forged must be false for others")
}
bl := d["blocklist"].(map[string]any)
since := bl["since"].(float64)
if bl["listed"] != true || since <= 0 || since > float64(now.Unix()) || since < float64(now.Add(-8*time.Minute).Unix()) {
t.Fatalf("blocklist %v", bl)
}
users := d["ssh"].(map[string]any)["users"].([]any)
adm := map[string]bool{}
for _, u := range users {
m := u.(map[string]any)
adm[m["user"].(string)] = m["admin"].(bool)
}
if len(adm) != 2 || !adm["lucas"] || adm["root"] {
t.Fatalf("ssh users %v", users)
}
rel := getJSON(t, h, "/api/v1/ip/20.0.0.1", auth)["related"].(map[string]any)
camps := rel["campaigns"].([]any)
if len(camps) != 1 || camps[0].(map[string]any)["ips_n"].(float64) != 3 {
t.Fatalf("campaigns %v", rel)
}
if rel["same_asn_n"] == nil || len(rel["same_prefix"].([]any)) != 2 {
t.Fatalf("related %v", rel)
}
var m map[string]any
w := do(h, "GET", "/api/v1/ip/9.9.9.9", cloneHdr(auth), nil)
json.Unmarshal(w.Body.Bytes(), &m)
if w.Code != http.StatusOK {
t.Fatal(w.Code)
}
}