Release / Publish tags (push) Successful in 18s
Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Successful in 1m47s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 28s
CI / Format and vet (push) Successful in 23s
CI / Tests (Linux, race detector) (push) Successful in 1m24s
CI / Dependency audit (push) Successful in 24s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 5s
Backend pagination with one pager for sessions, IPs, campaigns and events; network probe source (port-scan, T1046, second firewall reason port-scan); host kit logs inbound probes; urutau call on the report cover. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package enforce
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
|
)
|
|
|
|
func probe(ip string, at time.Time, port uint16) core.Event {
|
|
return core.Event{Time: at, IP: ip, Cat: core.Scanner, Source: "probe", Proto: "tcp", Port: port}
|
|
}
|
|
|
|
func TestPortScanBan(t *testing.T) {
|
|
r := newRig(t, ModeOn, nil)
|
|
for i := 0; i < 9; i++ {
|
|
r.e.process(probe("203.0.114.60", r.now.Add(-time.Duration(i)*time.Second), uint16(1000+i)), "")
|
|
}
|
|
// the same port again does not add up
|
|
r.e.process(probe("203.0.114.60", r.now, 1000), "")
|
|
if len(r.lines(t)) != 0 {
|
|
t.Fatal("banned below 10 distinct ports")
|
|
}
|
|
r.e.process(probe("203.0.114.60", r.now, 3389), "")
|
|
if l := r.lines(t); len(l) != 1 || !strings.Contains(l[0], "reason=port-scan") {
|
|
t.Fatalf("%q", l)
|
|
}
|
|
}
|
|
|
|
func TestPortScanExcludedAndOld(t *testing.T) {
|
|
r := newRig(t, ModeOn, nil)
|
|
for i := 0; i < 12; i++ { // trusted network
|
|
r.e.process(probe("45.1.1.1", r.now, uint16(2000+i)), "")
|
|
}
|
|
for i := 0; i < 12; i++ { // outside the window
|
|
r.e.process(probe("203.0.114.61", r.now.Add(-time.Hour), uint16(2000+i)), "")
|
|
}
|
|
if len(r.lines(t)) != 0 {
|
|
t.Fatal("excluded or old probes banned")
|
|
}
|
|
}
|
|
|
|
func TestPortScanReasonValid(t *testing.T) {
|
|
if !ValidReason(ReasonPortScan) {
|
|
t.Fatal("port-scan reason not valid")
|
|
}
|
|
}
|