Documentation
¶
Overview ¶
Package resolvers implements primitives to resolve various identifiers against external data
Copyright (c) Philipp Mieden. SPDX-License-Identifier: GPL-3.0-or-later
Index ¶
- Constants
- Variables
- func ExternalPopularityPath(path, managed string) (string, error)
- func GeoProviderOrder(raw string) ([]string, error)
- func GetJA4DBSize() int
- func GetJA4HDBSize() int
- func GetJA4SDBSize() int
- func GetJA4TDBSize() int
- func GetJA4TSDBSize() int
- func GetJA4TScanDBSize() int
- func GetJA4XDBSize() int
- func Init(c Config, quietMode bool)
- func InitDHCPFingerprintAPIKey()
- func InitDHCPFingerprintDB()
- func InitDNSWhitelist() error
- func InitLocalDNS()
- func InitServiceDB()
- func IsPopularHTTPHost(host string) bool
- func IsPrivateIP(ip net.IP) bool
- func IsWhitelistedDomain(domain string) bool
- func LoadDHCPCatalogue(path string) error
- func LoadDomainPopularityList(path, format, managed string) (*DomainPopularityList, PopularityStats, error)
- func LoadMACCatalogue(path string) error
- func LoadManagedDomainPopularityList(dir string) (*DomainPopularityList, PopularityStats, error)
- func LookupDHCPFingerprint(key string, _ string, _ []string) (*dhcpResult, error)
- func LookupDHCPFingerprintLocal(key string) string
- func LookupDNSNameLocal(ip string) string
- func LookupDNSNames(ip string) []string
- func LookupGeolocation(addr string) (string, string)
- func LookupJA4(string) string
- func LookupJA4H(string) string
- func LookupJA4S(string) string
- func LookupJA4T(string) string
- func LookupJA4TS(string) string
- func LookupJA4TScan(string) string
- func LookupJA4X(string) string
- func LookupManufacturer(mac string) string
- func LookupServiceByPort(port int, protocol string) string
- func OpenGeoDatabase(path, provider, kind string) (*maxminddb.Reader, error)
- func ParseGeoProviders(raw string) ([]string, error)
- func SaveFingerprintDB()
- func SaveGeoProviderOrder(raw string) error
- func SetLogger(lg *zap.Logger)
- func SetPerfTracker(pt *performance.Tracker)
- func ValidatePopularityFormat(format string) error
- type Config
- type DeviceCatalogueStatus
- type DomainPopularityList
- type GeoContext
- type GeoProviderFiles
- type GeoProviderStatus
- type JA4Entry
- type PopularityStats
Constants ¶
const DefaultGeoProviders = "dbip,geolite2"
const ManagedPopularityFile = "netapi-top1m.csv"
const MaxPopularityBytes = 128 << 20
const MaxPopularityRows = 1_000_000
Variables ¶
var ( // CurrentConfig holds the current configuration. CurrentConfig Config // ConfigRootPath points to the path for storing the netcap configuration and databases. // usually: /usr/local/etc/netcap ConfigRootPath string // DataBaseFolderPath points to the 'dbs' folder for storing the netcap databases. // usually: /usr/local/etc/netcap/dbs DataBaseFolderPath string // DataBaseBuildPath points to the build folder for db generation artifacts, // that are not tracked in version control. // usually: /usr/local/etc/netcap/build DataBaseBuildPath string )
var DefaultConfig = Config{ ReverseDNS: false, LocalDNS: false, MACDB: true, ServiceDB: true, GeolocationDB: true, DHCPDB: true, JA4DB: ja4plusadapter.Enabled, }
DefaultConfig is an example configuration.
var ErrDHCPEnrichmentDisabled = errors.New("DHCP fingerprint enrichment disabled: no admitted reviewed offline catalogue; packet decoding remains available")
var ErrGeolocationDBMissing = errors.New("geolocation database not found")
Functions ¶
func ExternalPopularityPath ¶
ExternalPopularityPath resolves symlinks, including existing ancestors of a missing managed directory, before checking containment.
func GeoProviderOrder ¶
Explicit CLI/config values override the environment, saved UI order and default.
func GetJA4DBSize ¶
func GetJA4DBSize() int
func GetJA4HDBSize ¶
func GetJA4HDBSize() int
func GetJA4SDBSize ¶
func GetJA4SDBSize() int
func GetJA4TDBSize ¶
func GetJA4TDBSize() int
func GetJA4TSDBSize ¶
func GetJA4TSDBSize() int
func GetJA4TScanDBSize ¶
func GetJA4TScanDBSize() int
func GetJA4XDBSize ¶
func GetJA4XDBSize() int
func Init ¶
Init can be used to initialize the resolvers package according to the provided configuration.
func InitDHCPFingerprintAPIKey ¶
func InitDHCPFingerprintAPIKey()
func InitDHCPFingerprintDB ¶
func InitDHCPFingerprintDB()
func InitDNSWhitelist ¶
func InitDNSWhitelist() error
InitDNSWhitelist loads each configuration once; failures never retain stale entries.
func InitLocalDNS ¶
func InitLocalDNS()
InitLocalDNS initializes reverse dns resolution via local hosts mapping.
func InitServiceDB ¶
func InitServiceDB()
InitServiceDB initializes the ports to service names mapping. TODO: include service names for other transport protocols
func IsPopularHTTPHost ¶
func IsPrivateIP ¶
IsPrivateIP can be used whether an address belongs to private address space.
func IsWhitelistedDomain ¶
IsWhitelistedDomain is a legacy name for popularity suppression only.
func LoadDHCPCatalogue ¶
LoadDHCPCatalogue accepts a local trusted override or installer-verified path. Failed refreshes retain the previous immutable catalogue.
func LoadDomainPopularityList ¶
func LoadDomainPopularityList(path, format, managed string) (*DomainPopularityList, PopularityStats, error)
LoadDomainPopularityList reads an explicit local file only: rank-domain has no header, netapi requires NetAPI_Rank,Domain, majestic its 12-column header.
func LoadMACCatalogue ¶
func LoadManagedDomainPopularityList ¶ added in v0.16.0
func LoadManagedDomainPopularityList(dir string) (*DomainPopularityList, PopularityStats, error)
LoadManagedDomainPopularityList validates the dedicated NetAPI member only.
func LookupDHCPFingerprint ¶
func LookupDNSNameLocal ¶
LookupDNSNameLocal retrieves the DNS names associated with an IP addr.
func LookupDNSNames ¶
LookupDNSNames retrieves the DNS names associated with an IP address.
func LookupGeolocation ¶
func LookupJA4H ¶
func LookupJA4S ¶
func LookupJA4T ¶
func LookupJA4TS ¶
func LookupJA4TScan ¶
func LookupJA4X ¶
func LookupManufacturer ¶
LookupManufacturer returns a registered organization, not a device identity.
func LookupServiceByPort ¶
LookupServiceByPort looks up the service name associated with a given port and protocol.
func ParseGeoProviders ¶
func SaveFingerprintDB ¶
func SaveFingerprintDB()
Retired API/cache entry points perform no file or network I/O.
func SaveGeoProviderOrder ¶
func SetPerfTracker ¶
func SetPerfTracker(pt *performance.Tracker)
SetPerfTracker sets the performance tracker for resolver operations
Types ¶
type Config ¶
type Config struct {
DomainPopularityList string
DomainPopularityFormat string
DisableDomainPopularity bool
// Controls whether ip addresses are resolved through the default OS resolver
ReverseDNS bool
// Controls if ip addresses are resolved locally through a provided hosts mapping
LocalDNS bool
// Enables MAC address vendor lookups
MACDB bool
// Enables resolving port numbers to service names
ServiceDB bool
// Enables IP geolocation and ASN lookups.
GeolocationDB bool
GeoProviders string
// Enables DHCP fingerprint lookups
DHCPDB bool
// Enables JA4+ fingerprint lookups
JA4DB bool
}
Config contains settings for the resolvers package.
type DeviceCatalogueStatus ¶
type DeviceCatalogueStatus struct {
Scope string `json:"scope"`
Kind string `json:"kind"`
State string `json:"state"`
Version string `json:"version,omitempty"`
Reason string `json:"reason,omitempty"`
Attribution string `json:"attribution"`
SourceURL string `json:"source_url"`
LicenseURL string `json:"license_url"`
DownloadFile string `json:"download_file"`
NoticesFile string `json:"notices_file"`
}
func DeviceCatalogueStatuses ¶
func DeviceCatalogueStatuses() []DeviceCatalogueStatus
DeviceCatalogueStatuses is a read-only source summary for API/Pro consumers. It never resolves a channel, reads a file or performs network I/O.
func InstalledDeviceCatalogueStatuses ¶
func InstalledDeviceCatalogueStatuses() []DeviceCatalogueStatus
InstalledDeviceCatalogueStatuses reports admission without changing capture state.
type DomainPopularityList ¶
type DomainPopularityList struct {
// contains filtered or unexported fields
}
func (*DomainPopularityList) ContainsDNS ¶
func (l *DomainPopularityList) ContainsDNS(name string) bool
ContainsDNS reports popularity, never safety. PRIVATE PSL rules isolate tenants.
func (*DomainPopularityList) ContainsHTTP ¶
func (l *DomainPopularityList) ContainsHTTP(host string) bool
type GeoContext ¶
func LookupGeoContext ¶
func LookupGeoContext(addr string) GeoContext
type GeoProviderFiles ¶
func GeoFiles ¶
func GeoFiles(name string) GeoProviderFiles
type GeoProviderStatus ¶
type GeoProviderStatus struct {
Name string `json:"name"`
Selected bool `json:"selected"`
Available bool `json:"available"`
Loaded bool `json:"loaded"`
CityFile string `json:"cityFile"`
ASNFile string `json:"asnFile"`
CityBuild string `json:"cityBuild,omitempty"`
ASNBuild string `json:"asnBuild,omitempty"`
Error string `json:"error,omitempty"`
}
func GeoProviderStatuses ¶
func GeoProviderStatuses(raw string) ([]GeoProviderStatus, error)
type JA4Entry ¶
type JA4Entry struct {
Application string `json:"application"`
Library string `json:"library"`
Device string `json:"device"`
OS string `json:"os"`
UserAgentString string `json:"user_agent_string"`
CertificateAuthority string `json:"certificate_authority"`
ObservationCount int `json:"observation_count"`
Verified bool `json:"verified"`
Notes string `json:"notes"`
JA4Fingerprint string `json:"ja4_fingerprint"`
JA4FingerprintString string `json:"ja4_fingerprint_string"`
JA4SFingerprint string `json:"ja4s_fingerprint"`
JA4HFingerprint string `json:"ja4h_fingerprint"`
JA4XFingerprint string `json:"ja4x_fingerprint"`
JA4TFingerprint string `json:"ja4t_fingerprint"`
JA4TSFingerprint string `json:"ja4ts_fingerprint"`
JA4TScanFingerprint string `json:"ja4tscan_fingerprint"`
}
JA4Entry preserves the public resolver API for records created by JA4+ opt-in builds. Official builds do not load or index JA4+ databases.
func LookupJA4Entry ¶
func LookupJA4HEntry ¶
func LookupJA4SEntry ¶
func LookupJA4TEntry ¶
func LookupJA4TSEntry ¶
func LookupJA4TScanEntry ¶
func LookupJA4XEntry ¶
func (*JA4Entry) GetDescription ¶
type PopularityStats ¶
type PopularityStats struct{ Rows, Loaded, Duplicates, Invalid, Skipped int }
PopularityStats includes rejected input; failed loads never publish partial data.