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
@@ -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