feat: 1.4.0 second firewall, egress analysis and HTML report
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 16s
CI / Tests (Linux, race detector) (push) Successful in 1m3s
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 3s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 16s
CI / Tests (Linux, race detector) (push) Successful in 1m3s
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 3s
Optional second firewall (URUTAU_ENFORCE off/observe/on) through the host fail2ban, outbound traffic analysis (beaconing, mining, spam, DNS bypass, unauthorised scans) with authorised scanner workloads, host kit in deploy/host and a printable HTML report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3adaa007ec
commit
c33cca22e3
59 files changed
+7364
-24
No files matched your search
@@ -0,0 +1,105 @@
|
||||
// Package egress analyses the outbound connections of the host and its
|
||||
// containers (nftables "URUTAU-EGRESS: " log lines) to spot a compromised
|
||||
// workload: beaconing, C2, mining, spam, unauthorised scanning.
|
||||
//
|
||||
// Central principle: traffic shaped like a scan (fan-out) is suppressed only
|
||||
// for workloads with role=scanner. Traffic that is not scan shaped is judged
|
||||
// the same for every workload, the scanner included.
|
||||
package egress
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/netip"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const marker = "URUTAU-EGRESS:"
|
||||
|
||||
// Event is one new outbound connection.
|
||||
type Event struct {
|
||||
Time time.Time
|
||||
Src, Dst netip.Addr
|
||||
Proto string // tcp, udp, icmp, or the lowercased PROTO value
|
||||
SPort, DPort uint16
|
||||
In, Out string
|
||||
Host bool // IN= empty: output of the host itself
|
||||
}
|
||||
|
||||
// ErrNotEgress marks a line that is not an egress log line.
|
||||
var ErrNotEgress = errors.New("not an egress line")
|
||||
|
||||
// ParseLine parses a kernel/rsyslog line. now is only used to infer the year
|
||||
// of the "Nov 14 22:01:02" rsyslog format (and as the time of a line whose
|
||||
// timestamp is unreadable).
|
||||
func ParseLine(b []byte, now time.Time) (Event, error) {
|
||||
line := string(b)
|
||||
i := strings.Index(line, marker)
|
||||
if i < 0 {
|
||||
return Event{}, ErrNotEgress
|
||||
}
|
||||
ev := Event{Time: parseTS(line[:i], now)}
|
||||
var haveSrc, haveDst bool
|
||||
for _, f := range strings.Fields(line[i+len(marker):]) {
|
||||
k, v, ok := strings.Cut(f, "=")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "IN":
|
||||
ev.In = v
|
||||
case "OUT":
|
||||
ev.Out = v
|
||||
case "SRC":
|
||||
a, err := netip.ParseAddr(v)
|
||||
if err != nil {
|
||||
return Event{}, errors.New("bad SRC")
|
||||
}
|
||||
ev.Src, haveSrc = a.Unmap(), true
|
||||
case "DST":
|
||||
a, err := netip.ParseAddr(v)
|
||||
if err != nil {
|
||||
return Event{}, errors.New("bad DST")
|
||||
}
|
||||
ev.Dst, haveDst = a.Unmap(), true
|
||||
case "PROTO":
|
||||
p := strings.ToLower(v)
|
||||
if strings.HasPrefix(p, "icmp") {
|
||||
p = "icmp"
|
||||
}
|
||||
ev.Proto = p
|
||||
case "SPT":
|
||||
n, _ := strconv.ParseUint(v, 10, 16)
|
||||
ev.SPort = uint16(n)
|
||||
case "DPT":
|
||||
n, _ := strconv.ParseUint(v, 10, 16)
|
||||
ev.DPort = uint16(n)
|
||||
}
|
||||
}
|
||||
if !haveSrc || !haveDst || ev.Proto == "" {
|
||||
return Event{}, errors.New("incomplete egress line")
|
||||
}
|
||||
ev.Host = ev.In == ""
|
||||
return ev, nil
|
||||
}
|
||||
|
||||
func parseTS(prefix string, now time.Time) time.Time {
|
||||
f := strings.Fields(prefix)
|
||||
if len(f) == 0 {
|
||||
return now
|
||||
}
|
||||
if t, err := time.Parse(time.RFC3339Nano, f[0]); err == nil {
|
||||
return t
|
||||
}
|
||||
if len(f) >= 3 {
|
||||
if t, err := time.ParseInLocation("Jan 2 15:04:05", f[0]+" "+f[1]+" "+f[2], now.Location()); err == nil {
|
||||
t = t.AddDate(now.Year(), 0, 0)
|
||||
if t.After(now.Add(48 * time.Hour)) {
|
||||
t = t.AddDate(-1, 0, 0)
|
||||
}
|
||||
return t
|
||||
}
|
||||
}
|
||||
return now
|
||||
}
|
||||
Reference in new issue
Block a user