prediction

package
v2.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultThreshold = 0.2

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

type Model struct {
	// contains filtered or unexported fields
}

Model holds conditional probability data: P(TargetPort | GivenPort). The outer key is the known open port, the inner key is the predicted port.

func DefaultModel

func DefaultModel() *Model

DefaultModel returns a model seeded with well-known port correlation patterns derived from common service co-occurrence on Internet hosts. Probabilities represent P(target | given), the likelihood that a host with "given" port open also has "target" port open.

func NewModel

func NewModel() *Model

NewModel creates an empty model.

func (*Model) GetCorrelations

func (m *Model) GetCorrelations(givenPort int) map[int]float64

GetCorrelations returns all P(target | given) entries for a given port. The returned map is a copy safe for concurrent use.

func (*Model) Merge

func (m *Model) Merge(other *Model)

Merge adds correlations from another model, keeping the higher probability when both models have data for the same pair. Safe against cross-merge deadlocks: the source is snapshot-copied before acquiring the destination lock.

func (*Model) Predict

func (m *Model) Predict(openPorts []int, threshold float64) []PortPrediction

Predict returns ports likely to be open given a set of known open ports. For each candidate port, the maximum conditional probability across all known ports is used (matching GPS's approach). Results are sorted by descending confidence and filtered by the threshold.

func (*Model) Prioritize

func (m *Model) Prioritize(candidates []int, openPorts []int) []PortPrediction

Prioritize ranks candidate ports by their likelihood of being open, given a set of known open ports. For each candidate, the maximum conditional probability across all known open ports is used. All candidates are returned sorted by descending priority; candidates with no correlation data receive a score of 0.

func (*Model) Set

func (m *Model) Set(given, target int, probability float64)

Set stores P(target | given) in the model.

func (*Model) SetBidirectional

func (m *Model) SetBidirectional(portA, portB int, probAGivenB, probBGivenA float64)

SetBidirectional stores the probability in both directions.

func (*Model) Stats

func (m *Model) Stats() (sourcePorts, totalEntries int)

Stats returns the number of source ports and total correlation entries.

func (*Model) Train

func (m *Model) Train(hostPorts map[string][]int)

Train builds correlation data from observed scan results. Each entry maps an IP to the set of open ports found on that host. This computes P(PortA | PortB) = count(hosts with both A and B) / count(hosts with B).

type PortPrediction

type PortPrediction struct {
	Port       int
	Confidence float64
}

PortPrediction is a predicted port with its confidence score.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL