package main import ( "fmt" "math/rand" "net/netip" "os" "path/filepath" "time" ) // Dados de demonstração da análise de saída (egress): um log no formato do // kernel/rsyslog com o prefixo "URUTAU-EGRESS: " e o mapa ip -> contêiner. Origens // privadas (10.x/172.x); destinos só nas faixas reservadas de documentação. const ( ipCiberlab = "172.18.0.20" // workload scanner: rajadas de varredura ipBeacon = "10.0.3.15" // beacon regular (60 s) para um IP que também ataca a entrada ipMiner = "10.0.3.22" // porta de mineração 3333 ipWeb = "10.0.3.5" ipAPI = "10.0.3.6" ipC2 = "203.0.113.45" // mesmo atacante dos logs de entrada ipPool = "198.51.100.200" ) func egressLine(t time.Time, src, dst string, dport int, proto string, sport int) string { return fmt.Sprintf("%s edge-1 kernel: [%d.%06d] URUTAU-EGRESS: IN=br-demo OUT=enp0s6 MAC=02:42:ac:12:00:01 SRC=%s DST=%s LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=%d DF PROTO=%s SPT=%d DPT=%d WINDOW=64240 RES=0x00 SYN URGP=0", t.UTC().Format("2006-01-02T15:04:05.000000+00:00"), 1000+t.Unix()%100000, t.Nanosecond()/1000, src, dst, t.Unix()%65000, proto, sport, dport) } func writeEgress(dir string) error { if err := os.MkdirAll(dir, 0o755); err != nil { return err } now := time.Now().UTC() r := rand.New(rand.NewSource(7)) var ls []line add := func(t time.Time, src, dst string, dport int) { ls = append(ls, line{t, egressLine(t, src, dst, dport, "TCP", 30000+r.Intn(30000))}) } // tráfego normal (443) a poucos destinos, nas últimas 30 h web := []string{"198.18.10.10", "198.18.10.11", "198.51.100.30", "203.0.113.80", "192.0.2.80"} for t := now.Add(-30 * time.Hour); t.Before(now); t = t.Add(time.Duration(40+r.Intn(120)) * time.Second) { src := ipWeb if r.Intn(3) == 0 { src = ipAPI } add(t, src, web[r.Intn(len(web))], 443) } // beacon: 60 s +- jitter, nas últimas 5 h for t := now.Add(-5 * time.Hour); t.Before(now); t = t.Add(time.Duration(60000+r.Intn(5000)-2500) * time.Millisecond) { add(t, ipBeacon, ipC2, 8443) } // mineração: ligações repetidas ao pool, porta 3333 for t := now.Add(-3 * time.Hour); t.Before(now); t = t.Add(time.Duration(20+r.Intn(40)) * time.Minute) { for k := 0; k < 3; k++ { add(t.Add(time.Duration(k)*time.Second), ipMiner, ipPool, 3333) } } // ciberlab: rajadas de varredura em faixas reservadas for _, ago := range []time.Duration{26 * time.Hour, 20 * time.Hour, 14 * time.Hour, 9 * time.Hour, 5 * time.Hour, 2 * time.Hour, 25 * time.Minute} { start := now.Add(-ago) for i := 0; i < 400; i++ { dst := netip.AddrFrom4([4]byte{198, byte(18 + r.Intn(2)), byte(r.Intn(256)), byte(1 + r.Intn(254))}).String() port := []int{22, 80, 443, 3389, 8080, 445}[r.Intn(6)] add(start.Add(time.Duration(i)*150*time.Millisecond), ipCiberlab, dst, port) } } // uma resolução 2001:db8 para o exemplo IPv6 ls = append(ls, line{now.Add(-time.Hour), egressLine(now.Add(-time.Hour), "fd00::5", "2001:db8::53", 443, "TCP", 40000)}) if err := writeLines(filepath.Join(dir, "egress.log"), ls, now); err != nil { return err } m := fmt.Sprintf("%s ciberlab\n%s shop-beacon\n%s worker-miner\n%s web-frontend\n%s api-backend\nfd00::5 web-frontend\n", ipCiberlab, ipBeacon, ipMiner, ipWeb, ipAPI) return os.WriteFile(filepath.Join(dir, "containers.map"), []byte(m), 0o644) }