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

+58
View File
@@ -0,0 +1,58 @@
package rdns
import (
"context"
"errors"
"testing"
)
func TestFCrDNS(t *testing.T) {
r := New()
calls := 0
r.lookup = func(_ context.Context, ip string) ([]string, error) {
calls++
switch ip {
case "66.249.66.1":
return []string{"crawl-66-249-66-1.googlebot.com."}, nil
case "6.6.6.6": // claims to be google, forward does not confirm
return []string{"fake.googlebot.com."}, nil
case "7.7.7.7": // reverse name outside the allowed domains
return []string{"host.evil.example."}, nil
case "157.55.39.1":
return []string{"msnbot-157-55-39-1.search.msn.com."}, nil
}
return nil, errors.New("nxdomain")
}
r.forward = func(_ context.Context, name string) ([]string, error) {
switch name {
case "crawl-66-249-66-1.googlebot.com":
return []string{"66.249.66.1"}, nil
case "fake.googlebot.com":
return []string{"1.2.3.4"}, nil
case "msnbot-157-55-39-1.search.msn.com":
return []string{"157.55.39.1"}, nil
}
return nil, errors.New("nxdomain")
}
g := []string{"googlebot.com", "google.com"}
if !r.FCrDNS("66.249.66.1", g) {
t.Fatal("real googlebot must verify")
}
if r.FCrDNS("6.6.6.6", g) || r.FCrDNS("7.7.7.7", g) || r.FCrDNS("8.8.8.8", g) {
t.Fatal("impostors must fail")
}
if r.FCrDNS("66.249.66.1", []string{"search.msn.com"}) {
t.Fatal("a Google address is not Bing")
}
if !r.FCrDNS("157.55.39.1", []string{"search.msn.com"}) {
t.Fatal("bingbot")
}
n := calls
r.FCrDNS("66.249.66.1", g)
if calls != n {
t.Fatal("results must be cached")
}
if r.FCrDNS("10.0.0.1", g) || r.FCrDNS("garbage", g) || r.FCrDNS("fe80::1%eth0", g) {
t.Fatal("private and invalid addresses are never looked up")
}
}
+87
View File
@@ -3,6 +3,7 @@ package rdns
import (
"context"
"errors"
"net"
"net/netip"
"strings"
@@ -10,6 +11,11 @@ import (
"time"
)
type fcrEntry struct {
ok bool
exp time.Time
}
type entry struct {
name string
exp time.Time
@@ -21,6 +27,8 @@ type Resolver struct {
Timeout time.Duration
MaxSize int
lookup func(ctx context.Context, ip string) ([]string, error)
forward func(ctx context.Context, name string) ([]string, error)
fcr map[string]fcrEntry
mu sync.Mutex
cache map[string]entry
@@ -33,9 +41,88 @@ func New() *Resolver {
r := &Resolver{TTL: 24 * time.Hour, Timeout: 2 * time.Second, MaxSize: 4000,
cache: map[string]entry{}, pending: map[string]bool{}, queue: make(chan string, 256)}
r.lookup = func(ctx context.Context, ip string) ([]string, error) { return net.DefaultResolver.LookupAddr(ctx, ip) }
r.forward = func(ctx context.Context, name string) ([]string, error) {
return net.DefaultResolver.LookupHost(ctx, name)
}
r.fcr = map[string]fcrEntry{}
return r
}
// FCrDNS checks forward-confirmed reverse DNS for a crawler that claims to be
// one: the reverse name must end in one of suffixes (each given as
// "googlebot.com") and a forward lookup of that name must give the address
// back. It is synchronous with a short timeout (1.5 s) and cached for 24 h.
func (r *Resolver) FCrDNS(ip string, suffixes []string) bool {
a, err := netip.ParseAddr(ip)
if err != nil || a.Zone() != "" || a.IsPrivate() || a.IsLoopback() || a.IsUnspecified() {
return false
}
a = a.Unmap()
key := a.String() + "|" + strings.Join(suffixes, ",")
r.mu.Lock()
if e, ok := r.fcr[key]; ok && time.Now().Before(e.exp) {
r.mu.Unlock()
return e.ok
}
r.mu.Unlock()
ok, transient := r.fcrdns(a, suffixes)
ttl := r.TTL
if transient {
ttl = time.Minute // a timeout or a server failure says nothing: look again soon
}
r.mu.Lock()
if len(r.fcr) >= r.MaxSize {
r.fcr = map[string]fcrEntry{}
}
r.fcr[key] = fcrEntry{ok, time.Now().Add(ttl)}
r.mu.Unlock()
return ok
}
// isFinal reports whether a DNS error is an answer (the name does not exist)
// rather than a transient failure.
func isFinal(err error) bool {
var de *net.DNSError
return errors.As(err, &de) && de.IsNotFound
}
func (r *Resolver) fcrdns(a netip.Addr, suffixes []string) (ok, transient bool) {
ctx, cancel := context.WithTimeout(context.Background(), 1500*time.Millisecond)
defer cancel()
names, err := r.lookup(ctx, a.String())
if err != nil {
return false, !isFinal(err)
}
for i, n := range names {
if i >= 3 {
break
}
n = strings.ToLower(strings.TrimSuffix(n, "."))
match := false
for _, s := range suffixes {
if n == s || strings.HasSuffix(n, "."+s) {
match = true
}
}
if !match {
continue
}
addrs, err := r.forward(ctx, n)
if err != nil {
if !isFinal(err) {
transient = true
}
continue
}
for _, x := range addrs {
if b, err := netip.ParseAddr(x); err == nil && b.Unmap() == a {
return true, false
}
}
}
return false, transient
}
// Lookup returns the cached name ("" when unknown or not resolvable yet) and
// queues the address for resolution. It never blocks.
func (r *Resolver) Lookup(ip string) string {
+36
View File
@@ -0,0 +1,36 @@
package rdns
import (
"context"
"errors"
"net"
"testing"
"time"
)
func TestFCrDNSTransientFailureIsNotCachedForADay(t *testing.T) {
r := New()
r.lookup = func(context.Context, string) ([]string, error) { return nil, errors.New("i/o timeout") }
if r.FCrDNS("66.249.66.1", []string{"googlebot.com"}) {
t.Fatal("a timeout is not a confirmation")
}
var exp time.Time
for _, e := range r.fcr {
exp = e.exp
}
if time.Until(exp) > 2*time.Minute {
t.Fatalf("a transient failure must be retried soon, expires in %v", time.Until(exp))
}
// the name really does not exist: that answer is final
r2 := New()
r2.lookup = func(context.Context, string) ([]string, error) {
return nil, &net.DNSError{Err: "no such host", IsNotFound: true}
}
r2.FCrDNS("66.249.66.2", []string{"googlebot.com"})
for _, e := range r2.fcr {
exp = e.exp
}
if time.Until(exp) < 23*time.Hour {
t.Fatalf("NXDOMAIN keeps the long TTL: %v", time.Until(exp))
}
}