feat: 1.4.3 Tor lists and classification, egress provider and peer allowlist
Release / Publish tags (push) Successful in 17s
Release / Plan (reuse the published image?) (push) Successful in 6s
Release / ci (push) Successful in 59s
Release / Build image (amd64) (push) Successful in 24s
Release / Build image (arm64) (push) Successful in 1m29s
CI / Format and vet (push) Successful in 26s
CI / Tests (Linux, race detector) (push) Successful in 33s
CI / Dependency audit (push) Successful in 33s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 4s
Release / Publish tags (push) Successful in 17s
Release / Plan (reuse the published image?) (push) Successful in 6s
Release / ci (push) Successful in 59s
Release / Build image (amd64) (push) Successful in 24s
Release / Build image (arm64) (push) Successful in 1m29s
CI / Format and vet (push) Successful in 26s
CI / Tests (Linux, race detector) (push) Successful in 33s
CI / Dependency audit (push) Successful in 33s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 4s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ec46fb94ff
commit
045ed53e43
15 files changed
+584
-25
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -548,3 +549,59 @@ func TestBeaconDuringContinuousScan(t *testing.T) {
|
||||
t.Fatal("fanSeen unbounded")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeaconProviderAndCDN(t *testing.T) {
|
||||
geo := func(s string) (string, string, string) {
|
||||
switch s {
|
||||
case "192.0.2.10":
|
||||
return "US", "AS31898", "Oracle Corporation"
|
||||
case "192.0.2.20":
|
||||
return "US", "AS13335", "Cloudflare"
|
||||
}
|
||||
return "BR", "AS2", "y"
|
||||
}
|
||||
bad := func(a netip.Addr) (bool, string) { return a == ip("192.0.2.30"), "known attacker" }
|
||||
e := newEng(t, Config{Geo: geo, BadDst: bad, ProviderASNs: func() []string { return []string{"AS31898"} }})
|
||||
rnd := rand.New(rand.NewSource(2))
|
||||
for _, src := range []string{"10.0.3.5"} {
|
||||
feedBeacon(e, src, "192.0.2.10", 443, t0, 50, 60*time.Second, 0.05, rnd)
|
||||
feedBeacon(e, src, "192.0.2.20", 443, t0, 50, 60*time.Second, 0.05, rnd)
|
||||
}
|
||||
// the host itself towards the provider network
|
||||
for i := 0; i < 50; i++ {
|
||||
ev := mk(t0.Add(time.Duration(i)*60*time.Second), "10.0.3.5", "192.0.2.10", "tcp", 8443)
|
||||
ev.Host = true
|
||||
e.IngestEvent(ev)
|
||||
ev2 := mk(t0.Add(time.Duration(i)*60*time.Second), "10.0.3.5", "192.0.2.30", "tcp", 8443)
|
||||
ev2.Host = true
|
||||
e.IngestEvent(ev2)
|
||||
}
|
||||
r := rep(e)
|
||||
var inf, cont, cdn, hi bool
|
||||
for _, f := range r.Findings {
|
||||
switch {
|
||||
case f.Kind == "infra" && f.Dst == "192.0.2.10" && f.Workload == "host" && f.Severity == "info" && strings.Contains(f.Detail, "provider service (Oracle Corporation)"):
|
||||
inf = true
|
||||
case f.Kind == "beacon" && f.Dst == "192.0.2.10" && f.Severity == "medium":
|
||||
cont = true // container to the provider ASN: evaluated normally
|
||||
case f.Kind == "beacon" && f.Dst == "192.0.2.20" && f.Severity == "low" && strings.Contains(f.Detail, "API"):
|
||||
cdn = true
|
||||
case f.Kind == "beacon" && f.Dst == "192.0.2.30" && f.Severity == "high":
|
||||
hi = true
|
||||
}
|
||||
}
|
||||
if !inf || !cont || !cdn || !hi {
|
||||
t.Fatalf("infra=%v container=%v cdn=%v bad=%v: %+v", inf, cont, cdn, hi, r.Findings)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTorRelayFinding(t *testing.T) {
|
||||
e := newEng(t, Config{Workloads: "sc=10.0.5.0/24:scanner", TorRelay: func(a netip.Addr) bool { return a == ip("192.0.2.77") }})
|
||||
e.IngestEvent(mk(t0, "10.0.3.5", "192.0.2.77", "tcp", 443))
|
||||
e.IngestEvent(mk(t0, "10.0.5.2", "192.0.2.77", "tcp", 443)) // scanner outside a burst
|
||||
e.IngestEvent(mk(t0, "10.0.3.5", "192.0.2.78", "tcp", 443))
|
||||
f := kinds(rep(e), "tor")
|
||||
if len(f) != 2 || f[0].Severity != "high" || f[0].Dst != "192.0.2.77" {
|
||||
t.Fatalf("tor: %+v", f)
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,13 @@ type Config struct {
|
||||
// destination is a known attacker or Tor exit (and why).
|
||||
Geo func(ip string) (cc, asn, org string)
|
||||
BadDst func(netip.Addr) (bool, string)
|
||||
Now func() time.Time
|
||||
// TorRelay says whether an address is a Tor relay (a connection to one is
|
||||
// a "tor" finding).
|
||||
TorRelay func(netip.Addr) bool
|
||||
// ProviderASNs ("AS31898") are the hosting provider's own networks: a
|
||||
// beacon from the host itself to them is informational ("infra").
|
||||
ProviderASNs func() []string
|
||||
Now func() time.Time
|
||||
// Learn is the per-workload learning time before new_geo (default 24h).
|
||||
Learn time.Duration
|
||||
// ResolvConf lists resolv.conf files whose nameservers are allowed resolvers
|
||||
@@ -700,6 +706,9 @@ func (e *Engine) checks(ws *wstate, ev Event, dport uint16, t int64, ds *dstStat
|
||||
e.addFinding("bad_dst", "high", ws.name, dst, dport, ev.Proto, t, 0, 0, why, 1)
|
||||
}
|
||||
}
|
||||
if e.cfg.TorRelay != nil && e.cfg.TorRelay(ev.Dst) {
|
||||
e.addFinding("tor", "high", ws.name, dst, dport, ev.Proto, t, 0, 0, "connection to a Tor relay", 1)
|
||||
}
|
||||
if ev.Proto == "tcp" {
|
||||
if sev, why := suspiciousPort(dport, ws.role); why != "" {
|
||||
e.addFinding("port", sev, ws.name, dst, dport, ev.Proto, t, 0, 0, why, 1)
|
||||
@@ -744,7 +753,15 @@ func suspiciousPort(port uint16, role string) (sev, why string) {
|
||||
|
||||
func (e *Engine) beacon(ws *wstate, ev Event, dport uint16, dns bool, p *pairState, ds *dstStat) {
|
||||
if p.flagged {
|
||||
if f := e.addFinding("beacon", "", ws.name, ev.Dst.String(), dport, ev.Proto, p.last, p.interval, p.cv, "", 1); f != nil {
|
||||
kind := "beacon"
|
||||
if ev.Host && e.cfg.Geo != nil {
|
||||
if _, asn, _ := e.cfg.Geo(ev.Dst.String()); e.providerASN(asn) {
|
||||
if _, ok := e.findings[fmt.Sprintf("infra|%s|%s|%d", ws.name, ev.Dst, dport)]; ok {
|
||||
kind = "infra"
|
||||
}
|
||||
}
|
||||
}
|
||||
if f := e.addFinding(kind, "", ws.name, ev.Dst.String(), dport, ev.Proto, p.last, p.interval, p.cv, "", 1); f != nil {
|
||||
if n := len(f.Samples); n == 0 || f.Samples[n-1] != p.last {
|
||||
if n >= MaxSamples {
|
||||
f.Samples = append(f.Samples[:0], f.Samples[1:]...)
|
||||
@@ -802,15 +819,27 @@ func (e *Engine) beacon(ws *wstate, ev Event, dport uint16, dns bool, p *pairSta
|
||||
if mad < cv {
|
||||
jit = mad
|
||||
}
|
||||
sev := "medium"
|
||||
sev, kind := "medium", "beacon"
|
||||
why := fmt.Sprintf("regular connections every %.0f s (jitter %.0f%%)", med, jit*100)
|
||||
bad := false
|
||||
if e.cfg.BadDst != nil {
|
||||
if bad, r := e.cfg.BadDst(ev.Dst); bad {
|
||||
sev, why = "high", why+"; destination: "+r
|
||||
if b, r := e.cfg.BadDst(ev.Dst); b {
|
||||
bad, sev, why = true, "high", why+"; destination: "+r
|
||||
}
|
||||
}
|
||||
if !bad && e.cfg.Geo != nil {
|
||||
_, asn, org := e.cfg.Geo(ev.Dst.String())
|
||||
switch {
|
||||
case ev.Host && e.providerASN(asn):
|
||||
sev, kind = "info", "infra"
|
||||
why = fmt.Sprintf("%s; provider service (%s)", why, org)
|
||||
case commonCloudASNs[asn]:
|
||||
sev = "low"
|
||||
why += "; large CDN/cloud network: regular connections are common for API calls"
|
||||
}
|
||||
}
|
||||
p.flagged, p.interval, p.cv = true, med, jit
|
||||
f := e.addFinding("beacon", sev, ws.name, ev.Dst.String(), dport, ev.Proto, p.last, med, jit, why, 0)
|
||||
f := e.addFinding(kind, sev, ws.name, ev.Dst.String(), dport, ev.Proto, p.last, med, jit, why, 0)
|
||||
if f != nil {
|
||||
f.Count, f.First = int(p.total), p.first
|
||||
f.Samples = make([]int64, 0, MaxSamples)
|
||||
@@ -820,6 +849,25 @@ func (e *Engine) beacon(ws *wstate, ev Event, dport uint16, dns bool, p *pairSta
|
||||
}
|
||||
}
|
||||
|
||||
// commonCloudASNs are large CDNs/clouds whose regular connections usually are
|
||||
// API calls.
|
||||
var commonCloudASNs = map[string]bool{"AS13335": true, "AS15169": true, "AS14618": true, "AS16509": true, "AS8075": true, "AS20940": true, "AS54113": true}
|
||||
|
||||
func (e *Engine) providerASN(asn string) bool {
|
||||
if asn == "" {
|
||||
return false
|
||||
}
|
||||
if e.cfg.ProviderASNs == nil {
|
||||
return false
|
||||
}
|
||||
for _, a := range e.cfg.ProviderASNs() {
|
||||
if strings.EqualFold(a, asn) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func median(v []float64) float64 {
|
||||
s := append([]float64(nil), v...)
|
||||
sort.Float64s(s)
|
||||
@@ -833,7 +881,7 @@ func median(v []float64) float64 {
|
||||
return (s[n/2-1] + s[n/2]) / 2
|
||||
}
|
||||
|
||||
var sevRank = map[string]int{"low": 1, "medium": 2, "high": 3}
|
||||
var sevRank = map[string]int{"info": 0, "low": 1, "medium": 2, "high": 3}
|
||||
|
||||
func (e *Engine) addFinding(kind, sev, wl, dst string, dport uint16, proto string, t int64, iv, jit float64, detail string, inc int) *Finding {
|
||||
key := fmt.Sprintf("%s|%s|%s|%d", kind, wl, dst, dport)
|
||||
|
||||
Reference in new issue
Block a user