feat: 1.4.6 unban from the UI, operator allows, day-counter fallback for long windows
Release / Publish tags (push) Successful in 16s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Successful in 1m47s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 23s
CI / Format and vet (push) Successful in 27s
CI / Tests (Linux, race detector) (push) Successful in 1m20s
CI / Dependency audit (push) Successful in 31s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 5s
Release / Publish tags (push) Successful in 16s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Successful in 1m47s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 23s
CI / Format and vet (push) Successful in 27s
CI / Tests (Linux, race detector) (push) Successful in 1m20s
CI / Dependency audit (push) Successful in 31s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 5s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1ef5a0ce9f
commit
da333d70f1
25 files changed
+841
-33
No files matched your search
@@ -14,6 +14,32 @@ type RosterRow struct {
|
||||
Level core.Level
|
||||
Jails []string
|
||||
Last int64
|
||||
Est Tally24 // 24 h estimate from the per-day counters (the registry may not cover the whole window)
|
||||
}
|
||||
|
||||
// dayEstimate estimates the SSH and web malicious events of the last 24 h from
|
||||
// the per-day counters: today plus the share of yesterday still inside the window.
|
||||
func dayEstimate(r *IPRec, nowU int64) Tally24 {
|
||||
if len(r.DayCats) == 0 {
|
||||
return Tally24{}
|
||||
}
|
||||
today := nowU / 86400
|
||||
frac := 1 - float64(nowU%86400)/86400
|
||||
var t Tally24
|
||||
for k := int64(0); k <= 1; k++ {
|
||||
i := int(r.DayBase - (today - k))
|
||||
if i < 0 || i >= len(r.DayCats) {
|
||||
continue
|
||||
}
|
||||
w := 1.0
|
||||
if k == 1 {
|
||||
w = frac
|
||||
}
|
||||
c := r.DayCats[i]
|
||||
t.SSH += int(float64(c[core.SSHFail.Index()])*w + 0.999)
|
||||
t.Web += int(float64(c[core.Scanner.Index()]+c[core.Exploit.Index()]+c[core.BruteForce.Index()])*w + 0.999)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// Tally24 counts the malicious events of one address in a window.
|
||||
@@ -31,7 +57,7 @@ func (s *Store) AttackRoster(from int64) []RosterRow {
|
||||
}
|
||||
strong := r.Strong || attackKinds(r.Counts) >= 2
|
||||
out = append(out, RosterRow{IP: ip, Score: round1(r.Score), Level: core.LevelOf(r.Score, strong, r.adminAt(nowU)),
|
||||
Jails: append([]string(nil), r.Jails...), Last: r.Last})
|
||||
Jails: append([]string(nil), r.Jails...), Last: r.Last, Est: dayEstimate(r, nowU)})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -72,7 +98,7 @@ func (s *Store) AttackTallies(from int64) map[string]Tally24 {
|
||||
return nil
|
||||
}
|
||||
m := map[string]*Tally24{}
|
||||
s.elog.Scan(evlog.Filter{From: from, Cats: tallyCats}, 256<<20, false, func(r evlog.Rec, _ []byte) bool {
|
||||
s.elog.Scan(evlog.Filter{From: from, Cats: tallyCats}, 4<<30, false, func(r evlog.Rec, _ []byte) bool {
|
||||
tallyAdd(m, r)
|
||||
return true
|
||||
})
|
||||
@@ -85,11 +111,17 @@ func (s *Store) AttackTallies(from int64) map[string]Tally24 {
|
||||
|
||||
// AttackTally is AttackTallies for one address.
|
||||
func (s *Store) AttackTally(ip string, from int64) Tally24 {
|
||||
var est Tally24
|
||||
s.mu.RLock()
|
||||
if r := s.ips[KeyOf(ip)]; r != nil {
|
||||
est = dayEstimate(r, s.now().Unix())
|
||||
}
|
||||
s.mu.RUnlock()
|
||||
if s.elog == nil {
|
||||
return Tally24{}
|
||||
return est
|
||||
}
|
||||
m := map[string]*Tally24{}
|
||||
s.elog.Scan(evlog.Filter{From: from, IP: ip, Cats: tallyCats}, 64<<20, false, func(r evlog.Rec, _ []byte) bool {
|
||||
s.elog.Scan(evlog.Filter{From: from, IP: ip, Cats: tallyCats}, 1<<30, false, func(r evlog.Rec, _ []byte) bool {
|
||||
tallyAdd(m, r)
|
||||
return true
|
||||
})
|
||||
@@ -98,5 +130,6 @@ func (s *Store) AttackTally(ip string, from int64) Tally24 {
|
||||
t.SSH += v.SSH
|
||||
t.Web += v.Web
|
||||
}
|
||||
t.SSH, t.Web = max(t.SSH, est.SSH), max(t.Web, est.Web)
|
||||
return t
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
||||
)
|
||||
|
||||
func TestTalliesFromRealRegistry(t *testing.T) {
|
||||
s := store30("oracle")
|
||||
l := openLog(t)
|
||||
s.SetEventLog(l)
|
||||
for i := 0; i < 41; i++ {
|
||||
s.Ingest(core.Event{Time: t0.Add(-time.Duration(20+i) * time.Minute), IP: "43.139.48.108", Cat: core.SSHFail, Source: "ssh", User: "root"})
|
||||
}
|
||||
for i := 0; i < 30; i++ {
|
||||
s.Ingest(core.Event{Time: t0.Add(-time.Duration(30+i) * time.Minute), IP: "129.213.151.234", Cat: core.Scanner, Source: "traefik",
|
||||
Domain: "a.example", Method: "GET", Path: "/.env", Status: 404, UA: "curl/8"})
|
||||
}
|
||||
l.Flush()
|
||||
from := t0.Add(-24 * time.Hour).Unix()
|
||||
m := s.AttackTallies(from)
|
||||
if m["43.139.48.108"].SSH != 41 || m["129.213.151.234"].Web != 30 {
|
||||
t.Fatalf("tallies: %+v", m)
|
||||
}
|
||||
if x := s.AttackTally("43.139.48.108", from); x.SSH != 41 {
|
||||
t.Fatalf("one: %+v", x)
|
||||
}
|
||||
rows := s.AttackRoster(from)
|
||||
got := map[string]bool{}
|
||||
for _, r := range rows {
|
||||
got[r.IP] = true
|
||||
}
|
||||
if !got["43.139.48.108"] || !got["129.213.151.234"] {
|
||||
t.Fatalf("roster: %+v", rows)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user