Documentation
¶
Overview ¶
Package discover implements network discovery for the scan nodes.
This is a plant-floor inventory tool. Everything in it is bounded by an operator-configured CIDR allowlist, because the nodes are reachable by anyone who can edit a flow, and "it is on an isolated network" is an assumption that stops being true the day somebody bridges a VLAN.
Index ¶
Constants ¶
const ( PortModbus = 502 PortOPCUA = 4840 PortEtherNetIP = 44818 PortBACnet = 47808 PortS7 = 102 PortFINS = 9600 PortHTTP = 80 PortHTTPS = 443 PortSSH = 22 PortMQTT = 1883 )
Well-known OT ports. These are what a discovery sweep is actually looking for on a plant floor; a generic 1-65535 scan is both slower and less useful.
const MaxSweepHosts = 4096
MaxSweepHosts caps a single sweep.
A /16 is 65,534 addresses. Allowing one node to enqueue that many probes would saturate an OT link that is often 100Mb and shared with the process traffic that actually matters.
Variables ¶
var DefaultPorts = []int{ PortSSH, PortHTTP, PortS7, PortHTTPS, PortModbus, PortMQTT, PortOPCUA, PortFINS, PortEtherNetIP, PortBACnet, }
DefaultPorts is the sweep used when a node does not narrow it.
var ErrDisabled = fmt.Errorf("discovery is disabled; enable it and list the " +
"networks the scan nodes may probe")
ErrDisabled is returned when discovery is off.
Functions ¶
func Hosts ¶
Hosts expands a prefix into the addresses to probe, excluding the network and broadcast addresses for IPv4 prefixes shorter than /31.
func Interfaces ¶
Interfaces reports the host's network interfaces.
In macvlan mode this is how a flow learns the address it was given on the OT VLAN, which it needs in order to know what to sweep.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector accumulates results from concurrent probes.
type Device ¶
type Device struct {
Address string `json:"address"`
MAC string `json:"mac,omitempty"`
Hostname string `json:"hostname,omitempty"`
Vendor string `json:"vendor,omitempty"`
Ports []int `json:"ports,omitempty"`
Protocol string `json:"protocol,omitempty"`
Details map[string]any `json:"details,omitempty"`
Source string `json:"source"`
Extra map[string]string `json:"extra,omitempty"`
}
Device is one thing found on the network.
func Sweep ¶
Sweep probes every address in a range and returns what answered.
TCP connect rather than raw SYN. A connect scan needs no elevated capability, works identically inside a container with capabilities dropped, and — more importantly on a plant floor — completes the handshake rather than leaving half-open connections on a PLC whose TCP stack may have a connection table of eight.
type ErrOutOfScope ¶
type ErrOutOfScope struct{ Target string }
ErrOutOfScope is returned for a target outside the allowlist.
func (*ErrOutOfScope) Error ¶
func (e *ErrOutOfScope) Error() string
type Identification ¶
Identification is what a protocol probe learned about a device.
type Options ¶
type Options struct {
// Timeout bounds one probe.
Timeout time.Duration
// Concurrency bounds simultaneous probes. OT links are frequently 100Mb and
// shared with the process traffic that matters, so this defaults low: a
// discovery scan must never be the reason a line stutters.
Concurrency int
// Ports to probe on each host.
Ports []int
// ResolveNames does a reverse DNS lookup per responding host.
ResolveNames bool
// Identify runs the protocol-specific identification probes against ports
// that answered.
Identify bool
}
Options tune a sweep.
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope decides what the scan nodes are permitted to probe.
func NewScope ¶
NewScope builds a scope from the configured CIDRs.
An enabled scope with no CIDRs is an error rather than "everything". The permissive reading of an empty list is how a tool meant to inventory one factory segment ends up scanning a corporate network.
func (*Scope) CheckHost ¶
CheckHost resolves a host and reports whether every address it resolves to is in scope.
Every address, not any: a name that resolves to one in-scope and one out-of-scope address must be refused, or DNS becomes the way around the allowlist.
func (*Scope) CheckPrefix ¶
CheckPrefix reports whether an entire range may be swept.
The range must be fully contained in an allowed prefix. Overlap is not enough: sweeping 10.0.0.0/8 because 10.20.30.0/24 is allowed would be exactly the failure this exists to prevent.