Files
urutau/internal/intel/nettype.go
T
Lucas RayanandClaude Opus 5.5 b7462c14fa
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 27s
CI / Dependency audit (push) Successful in 18s
CI / Tests (Linux, race detector) (push) Successful in 58s
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 5s
feat: 1.2.0 attack intelligence, replay, 30-day history and new interface
Intelligence: attack families mapped to MITRE ATT&CK, network type from
ASN/rDNS without external APIs, request cadence, sessions with
recon/probe/exploit/access/banned stages, campaigns across IPs, verdict
with reasons, recommended actions, exposure detection (2xx with a body
on sensitive paths), STIX 2.1 export, FCrDNS for search engine bots,
optional Tor exit list.

Data: 30-day retention, twelve ranges plus custom from/to, an on-disk
event log (daily files, hourly gzip members, size cap, corruption and
disk-full tolerant), /events, /period, /metrics with stable per-hour
metrics, an extended /ip/{ip}, and peer /period merged on the hub.

Interface: layout system with fixed card sizes, range picker in the
URL, IP analysis page, Replay page, Geography down to state and city
(Natural Earth admin-1), Live page redesigned with stable metrics and a
reusable attack map. Demo data and documentation screenshots.

Security: bounded and deadline-limited period computations, linear
campaign clustering, singleflight caches, sanitized peer studies, event
query budgets, gzip bomb guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 21:45:59 -03:00

121 lines
4.3 KiB
Go

package intel
import (
"fmt"
"net/netip"
"regexp"
"strings"
"sync"
)
var (
torMu sync.RWMutex
torExits map[netip.Addr]struct{}
)
// SetTorExits loads (or clears, with nil/empty) the Tor exit list. It is off
// by default; the caller decides where the list comes from.
func SetTorExits(addrs []netip.Addr) {
m := make(map[netip.Addr]struct{}, len(addrs))
for _, a := range addrs {
m[a.Unmap()] = struct{}{}
}
torMu.Lock()
torExits = m
torMu.Unlock()
}
// IsTorExit reports whether ip is in the loaded Tor exit list.
func IsTorExit(ip netip.Addr) bool {
torMu.RLock()
defer torMu.RUnlock()
if len(torExits) == 0 {
return false
}
_, ok := torExits[ip.Unmap()]
return ok
}
func asnSet(v ...uint32) map[uint32]bool {
m := make(map[uint32]bool, len(v))
for _, x := range v {
m[x] = true
}
return m
}
var (
vpnASNs = asnSet(9009, 212238, 60068, 136787, 39351)
hostingASNs = asnSet(14061, 16509, 14618, 15169, 396982, 8075, 31898, 45102, 132203, 16276, 24940, 63949, 20473, 51167, 9009, 60781, 28753, 12876, 47583, 8560, 36352, 53667, 211252, 49870, 204428, 213371)
researchASNs = asnSet(398324, 398705, 398722, 211298, 10439, 202425, 63999, 135377, 396507)
cnASNs = asnSet(4134, 4837)
mobileASNs = asnSet(26615)
ispMobASNs = asnSet(28573, 26599, 18881)
brISPASNs = asnSet(7738, 8167, 16735, 53006, 28126, 7162, 27699, 14868, 4230, 263880)
vpnRDNS = regexp.MustCompile(`vpn|proxy|exit|relay`)
hostOrgRe = regexp.MustCompile(`(?i)hosting|cloud|server|datacenter|data center|vps|colo|digitalocean|ovh|hetzner|linode|akamai|amazon|google|microsoft|oracle|alibaba|tencent|contabo|vultr|leaseweb|choopa|m247|scaleway|hostinger|ionos|kamatera|cloudflare|\bhost\b|locaweb|hospedagem`)
hostRDNS = regexp.MustCompile(`(?i)compute|ec2|vps|server|static|cloud|host\d`)
mobileRe = regexp.MustCompile(`(?i)mobile|wireless|lte|4g|5g|gprs|cellular`)
resRDNS = regexp.MustCompile(`(?i)dsl|dynamic|dyn|pool|dhcp|cable|fibra|ftth|cpe|customer|user|\d+-\d+-\d+-\d+`)
ispBrRe = regexp.MustCompile(`(?i)provedor|fibra|telecomunicac|comunicac|internet|tecnologia em internet|\bnet\b`)
resOrgRe = regexp.MustCompile(`(?i)telecom|telecomunica|net |broadband|internet`)
maxFieldLen = 256
)
func clip(s string) string {
if len(s) > maxFieldLen {
return s[:maxFieldLen]
}
return s
}
// NetTypeIP is NetType preceded by the optional Tor exit list check.
func NetTypeIP(ip netip.Addr, asn uint32, asOrg, rdns string) (typ, reason string) {
if ip.IsValid() && IsTorExit(ip) {
return "tor", "tor-exit-list"
}
return NetType(asn, asOrg, rdns)
}
// NetType infers the kind of network behind an address from its ASN, AS
// organisation and reverse DNS. Types: vpn, research-scanner, isp-cn,
// hosting, mobile, isp/mobile, residential, unknown. reason says which rule
// fired. Tor detection needs the address: see NetTypeIP.
func NetType(asn uint32, asOrg, rdns string) (typ, reason string) {
asOrg, rdns = clip(asOrg), strings.ToLower(clip(rdns))
switch {
case vpnASNs[asn]:
return "vpn", fmt.Sprintf("asn:%d", asn)
case rdns != "" && vpnRDNS.MatchString(rdns):
return "vpn", "rdns:" + vpnRDNS.FindString(rdns)
case researchASNs[asn]:
return "research-scanner", fmt.Sprintf("asn:%d", asn)
case cnASNs[asn]:
return "isp-cn", fmt.Sprintf("asn:%d", asn)
case hostingASNs[asn]:
return "hosting", fmt.Sprintf("asn:%d", asn)
case mobileASNs[asn]:
return "mobile", fmt.Sprintf("asn:%d", asn)
case ispMobASNs[asn]:
return "isp/mobile", fmt.Sprintf("asn:%d", asn)
case brISPASNs[asn]:
return "residential", fmt.Sprintf("asn:%d", asn)
case asOrg != "" && hostOrgRe.MatchString(asOrg):
return "hosting", "asorg:" + strings.ToLower(hostOrgRe.FindString(asOrg))
case rdns != "" && hostRDNS.MatchString(rdns):
return "hosting", "rdns:" + strings.ToLower(hostRDNS.FindString(rdns))
case mobileRe.MatchString(asOrg) && asOrg != "":
return "mobile", "asorg:" + strings.ToLower(mobileRe.FindString(asOrg))
case rdns != "" && mobileRe.MatchString(rdns):
return "mobile", "rdns:" + mobileRe.FindString(rdns)
case rdns != "" && resRDNS.MatchString(rdns):
return "residential", "rdns:" + resRDNS.FindString(rdns)
case asOrg != "" && ispBrRe.MatchString(asOrg):
return "residential", "asorg:isp-br"
case asOrg != "" && resOrgRe.MatchString(asOrg):
return "residential", "asorg:" + strings.ToLower(resOrgRe.FindString(asOrg))
}
return "unknown", ""
}