utils

package
v0.0.189 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package utils provides utility functions used across the networkscan application.

Package utils provides stealth and timing utility functions for networkscan operations.

Package utils provides wordlist resolution utilities for the networkscan application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDelayWithJitter added in v0.0.68

func CalculateDelayWithJitter(baseDelaySeconds int, jitterPercent int) time.Duration

CalculateDelayWithJitter calculates sleep duration with optional jitter. baseDelaySeconds: base delay in seconds jitterPercent: jitter percentage (0-100) to apply random variance Returns: final delay duration with jitter applied

func CalculateStealthDelay added in v0.0.68

func CalculateStealthDelay(sleepPtr *int, jitterPtr *int) time.Duration

CalculateStealthDelay calculates a delay with jitter from optional sleep and jitter parameters. This is a convenience function that handles nil pointer checks. sleepPtr: optional pointer to sleep delay in seconds (can be nil) jitterPtr: optional pointer to jitter percentage 0-100 (can be nil) Returns: final delay duration with jitter applied, or 0 if no sleep specified

func DetectIPVersions added in v0.0.123

func DetectIPVersions(hosts []string) []string

DetectIPVersions analyzes a list of IP addresses and returns which IP versions are present. Returns a slice containing "4" for IPv4 and/or "6" for IPv6. This is used to configure scanners to support the appropriate IP versions.

func FormatHostPort added in v0.0.123

func FormatHostPort(host string, port int) string

FormatHostPort formats a host (IP address or hostname) and port into a valid address string. For IPv6 addresses, it wraps them in square brackets. For IPv4 and hostnames, it uses simple colon notation. This ensures compatibility with services expecting properly formatted network addresses.

func FormatLDAPURL added in v0.0.136

func FormatLDAPURL(host string, port int, useTLS bool) string

FormatLDAPURL constructs a properly formatted LDAP URL that handles IPv6 addresses.

func FormatRPCBinding added in v0.0.136

func FormatRPCBinding(host string, endpoint string) string

FormatRPCBinding constructs an ncacn_ip_tcp binding string. The string binding format uses '[' as the endpoint delimiter, so IPv6 colons in the network address are unambiguous: ncacn_ip_tcp:2001:db8::1[135]

func GenerateRandomString added in v0.0.61

func GenerateRandomString(length int) string

GenerateRandomString generates a random string of specified length using alphanumeric characters. This is useful for creating temporary file/directory names for testing purposes.

func GenerateUsernamesByScheme added in v0.0.61

func GenerateUsernamesByScheme(scheme pentest.UsernameScheme) ([]string, error)

GenerateUsernamesByScheme generates usernames based on the specified scheme

func GenerateUsernamesWithLimit added in v0.0.61

func GenerateUsernamesWithLimit(scheme pentest.UsernameScheme, limit int) ([]string, error)

GenerateUsernamesWithLimit generates a limited number of usernames based on the scheme

func GetDefaultPortForService added in v0.0.51

func GetDefaultPortForService(service pentestfern.SprayTargetService) int

GetDefaultPortForService returns the default port for a given service type

func GetEntriesFromTXTFiles added in v0.0.35

func GetEntriesFromTXTFiles(paths []string) ([]string, error)

GetEntriesFromTXTFiles reads and combines entries from multiple text files. It takes a list of file paths, reads each file line by line, and returns a combined list of all entries. Each line in the input files becomes a separate entry. Returns an error if any file cannot be opened or read.

func GetIPs added in v0.0.68

func GetIPs(host string) ([]net.IP, error)

GetIPs resolves a hostname to IP addresses

func GetPasswordWordlists added in v0.0.145

func GetPasswordWordlists(passwordLists []pentestfern.WordlistType) ([]string, error)

GetPasswordWordlists loads password wordlists based on the config.

func GetUsernameSchemeDescription added in v0.0.61

func GetUsernameSchemeDescription(scheme pentest.UsernameScheme) string

GetUsernameSchemeDescription returns a human-readable description of the scheme

func GetUsernameWordlists added in v0.0.145

func GetUsernameWordlists(usernameLists []pentestfern.WordlistType) ([]string, error)

GetUsernameWordlists loads username wordlists based on the config.

func IncIP added in v0.0.68

func IncIP(ip net.IP)

IncIP increments an IP address

func IsIPv6 added in v0.0.136

func IsIPv6(host string) bool

IsIPv6 returns true if the host string is an IPv6 address.

func ParseHostPort added in v0.0.51

func ParseHostPort(target string, defaultPort int) (string, int)

ParseHostPort parses a target string into host and port components. If no port is provided, uses the specified default port. Returns the host and port as separate values.

func ParsePort added in v0.0.50

func ParsePort(portStr string) int

ParsePort converts a port string to an integer. Returns 0 if the port string is invalid or out of range (1-65535).

func ParseTargetHosts added in v0.0.68

func ParseTargetHosts(target string) ([]string, error)

ParseTargetHosts expands CIDR ranges and hostnames into individual IP addresses

func ParseTargetHostsWithMapping added in v0.0.78

func ParseTargetHostsWithMapping(target string) ([]string, map[string]string, error)

ParseTargetHostsWithMapping expands CIDR ranges and hostnames into individual IP addresses and returns a mapping from IP addresses back to their original hostnames (if resolved from FQDNs)

func ParseWordlistTypes added in v0.0.51

func ParseWordlistTypes(wordlistStrings []string) ([]pentestfern.WordlistType, error)

ParseWordlistTypes converts string slice to WordlistType enums

Types

type EtcdActionParser added in v0.0.180

type EtcdActionParser struct{}

EtcdActionParser handles etcd-specific action parsing

func GetEtcdParser added in v0.0.180

func GetEtcdParser() *EtcdActionParser

GetEtcdParser returns the singleton etcd action parser

func (*EtcdActionParser) ContainsAction added in v0.0.180

func (p *EtcdActionParser) ContainsAction(actions []etcdfern.PentestEtcdAction, target etcdfern.PentestEtcdAction) bool

func (*EtcdActionParser) GetValidActions added in v0.0.180

func (p *EtcdActionParser) GetValidActions() []string

func (*EtcdActionParser) ParseActions added in v0.0.180

func (p *EtcdActionParser) ParseActions(actionStrings []string) ([]etcdfern.PentestEtcdAction, error)

type FTPActionParser added in v0.0.150

type FTPActionParser struct{}

FTPActionParser handles FTP-specific action parsing

func GetFTPParser added in v0.0.150

func GetFTPParser() *FTPActionParser

GetFTPParser returns the singleton FTP action parser

func (*FTPActionParser) ContainsAction added in v0.0.150

func (p *FTPActionParser) ContainsAction(actions []ftpfern.PentestFtpAction, target ftpfern.PentestFtpAction) bool

func (*FTPActionParser) GetValidActions added in v0.0.150

func (p *FTPActionParser) GetValidActions() []string

func (*FTPActionParser) ParseActions added in v0.0.150

func (p *FTPActionParser) ParseActions(actionStrings []string) ([]ftpfern.PentestFtpAction, error)

type IMAPActionParser added in v0.0.177

type IMAPActionParser struct{}

IMAPActionParser handles IMAP-specific action parsing for the pentest service imap command (Mode B: AUTH + LIST_FOLDERS + FETCH_HEADERS + SEARCH).

func GetIMAPParser added in v0.0.177

func GetIMAPParser() *IMAPActionParser

GetIMAPParser returns the singleton IMAP action parser.

func (*IMAPActionParser) ContainsAction added in v0.0.177

func (p *IMAPActionParser) ContainsAction(actions []imapfern.PentestImapAction, target imapfern.PentestImapAction) bool

func (*IMAPActionParser) GetValidActions added in v0.0.177

func (p *IMAPActionParser) GetValidActions() []string

func (*IMAPActionParser) ParseActions added in v0.0.177

func (p *IMAPActionParser) ParseActions(actionStrings []string) ([]imapfern.PentestImapAction, error)

type LDAPActionParser added in v0.0.54

type LDAPActionParser struct{}

LDAPActionParser handles LDAP-specific action parsing

func GetLDAPParser added in v0.0.54

func GetLDAPParser() *LDAPActionParser

GetLDAPParser returns the singleton LDAP action parser

func (*LDAPActionParser) ContainsAction added in v0.0.54

func (p *LDAPActionParser) ContainsAction(actions []ldapfern.PentestLdapAction, target ldapfern.PentestLdapAction) bool

func (*LDAPActionParser) GetValidActions added in v0.0.54

func (p *LDAPActionParser) GetValidActions() []string

func (*LDAPActionParser) ParseActions added in v0.0.54

func (p *LDAPActionParser) ParseActions(actionStrings []string) ([]ldapfern.PentestLdapAction, error)

type MSRPCActionParser added in v0.0.80

type MSRPCActionParser struct{}

MSRPCActionParser handles MSRPC-specific action parsing

func GetMSRPCParser added in v0.0.80

func GetMSRPCParser() *MSRPCActionParser

GetMSRPCParser returns the singleton MSRPC action parser

func (*MSRPCActionParser) ContainsAction added in v0.0.80

func (p *MSRPCActionParser) ContainsAction(actions []msrpcfern.PentestMsrpcAction, target msrpcfern.PentestMsrpcAction) bool

func (*MSRPCActionParser) GetValidActions added in v0.0.80

func (p *MSRPCActionParser) GetValidActions() []string

func (*MSRPCActionParser) ParseActions added in v0.0.80

func (p *MSRPCActionParser) ParseActions(actionStrings []string) ([]msrpcfern.PentestMsrpcAction, error)

type MSSQLActionParser added in v0.0.174

type MSSQLActionParser struct{}

MSSQLActionParser handles MSSQL-specific action parsing

func GetMSSQLParser added in v0.0.174

func GetMSSQLParser() *MSSQLActionParser

GetMSSQLParser returns the singleton MSSQL action parser

func (*MSSQLActionParser) ContainsAction added in v0.0.174

func (p *MSSQLActionParser) ContainsAction(actions []mssqlfern.PentestMssqlAction, target mssqlfern.PentestMssqlAction) bool

func (*MSSQLActionParser) GetValidActions added in v0.0.174

func (p *MSSQLActionParser) GetValidActions() []string

func (*MSSQLActionParser) ParseActions added in v0.0.174

func (p *MSSQLActionParser) ParseActions(actionStrings []string) ([]mssqlfern.PentestMssqlAction, error)

type MongoDBActionParser added in v0.0.170

type MongoDBActionParser struct{}

MongoDBActionParser handles MongoDB-specific action parsing

func GetMongoDBParser added in v0.0.170

func GetMongoDBParser() *MongoDBActionParser

GetMongoDBParser returns the singleton MongoDB action parser

func (*MongoDBActionParser) ContainsAction added in v0.0.170

func (*MongoDBActionParser) GetValidActions added in v0.0.170

func (p *MongoDBActionParser) GetValidActions() []string

func (*MongoDBActionParser) ParseActions added in v0.0.170

func (p *MongoDBActionParser) ParseActions(actionStrings []string) ([]mongodbfern.PentestMongodbAction, error)

type MySQLActionParser added in v0.0.178

type MySQLActionParser struct{}

MySQLActionParser handles MySQL-specific action parsing

func GetMySQLParser added in v0.0.178

func GetMySQLParser() *MySQLActionParser

GetMySQLParser returns the singleton MySQL action parser

func (*MySQLActionParser) ContainsAction added in v0.0.178

func (p *MySQLActionParser) ContainsAction(actions []mysqlfern.PentestMysqlAction, target mysqlfern.PentestMysqlAction) bool

func (*MySQLActionParser) GetValidActions added in v0.0.178

func (p *MySQLActionParser) GetValidActions() []string

func (*MySQLActionParser) ParseActions added in v0.0.178

func (p *MySQLActionParser) ParseActions(actionStrings []string) ([]mysqlfern.PentestMysqlAction, error)

type NetErrorCategory added in v0.0.189

type NetErrorCategory string

NetErrorCategory is a stable, coarse classification of a failed outbound connection/probe. It is the closest thing to an "error code" an operator can filter and triage on when a scan never reaches the target — the common shape when egress is blocked by a firewall or routed through a restricted network.

const (
	NetErrorDNS           NetErrorCategory = "dns_resolution_failed"
	NetErrorConnRefused   NetErrorCategory = "connection_refused"
	NetErrorConnReset     NetErrorCategory = "connection_reset"
	NetErrorTimeout       NetErrorCategory = "timeout"
	NetErrorTLS           NetErrorCategory = "tls_error"
	NetErrorNoRouteToHost NetErrorCategory = "no_route_to_host"
	NetErrorNetworkDown   NetErrorCategory = "network_unreachable"
	NetErrorCanceled      NetErrorCategory = "canceled"
	NetErrorOther         NetErrorCategory = "network_error"
)

type NetErrorDetail added in v0.0.189

type NetErrorDetail struct {
	Category NetErrorCategory
	Cause    string
	Op       string
	Network  string
	Address  string
}

NetErrorDetail is an operator-facing description of a failed connection. Cause is always the fully unwrapped error string (never a reflected struct), and the remaining fields name the layer that failed.

func ClassifyNetError added in v0.0.189

func ClassifyNetError(err error) NetErrorDetail

ClassifyNetError unwraps a Go network error (typically *net.OpError wrapping *net.DNSError / x509 / tls / syscall errors, possibly nested in *url.Error) into a stable category plus the underlying cause and the failing layer, so a probe that never reaches the target reports *why* (dns/refused/reset/no-route/ tls/timeout) instead of an opaque struct dump.

func (NetErrorDetail) String added in v0.0.189

func (d NetErrorDetail) String() string

String renders the detail as a single human-readable line.

type PostgresActionParser added in v0.0.175

type PostgresActionParser struct{}

PostgresActionParser handles Postgres-specific action parsing

func GetPostgresParser added in v0.0.175

func GetPostgresParser() *PostgresActionParser

GetPostgresParser returns the singleton Postgres action parser

func (*PostgresActionParser) ContainsAction added in v0.0.175

func (*PostgresActionParser) GetValidActions added in v0.0.175

func (p *PostgresActionParser) GetValidActions() []string

func (*PostgresActionParser) ParseActions added in v0.0.175

func (p *PostgresActionParser) ParseActions(actionStrings []string) ([]postgresfern.PentestPostgresAction, error)

type RedisActionParser added in v0.0.166

type RedisActionParser struct{}

RedisActionParser handles Redis-specific action parsing

func GetRedisParser added in v0.0.166

func GetRedisParser() *RedisActionParser

GetRedisParser returns the singleton Redis action parser

func (*RedisActionParser) ContainsAction added in v0.0.166

func (p *RedisActionParser) ContainsAction(actions []redisfern.PentestRedisAction, target redisfern.PentestRedisAction) bool

func (*RedisActionParser) GetValidActions added in v0.0.166

func (p *RedisActionParser) GetValidActions() []string

func (*RedisActionParser) ParseActions added in v0.0.166

func (p *RedisActionParser) ParseActions(actionStrings []string) ([]redisfern.PentestRedisAction, error)

type SMBActionParser added in v0.0.51

type SMBActionParser struct{}

SMBActionParser handles SMB-specific action parsing

func GetSMBParser added in v0.0.51

func GetSMBParser() *SMBActionParser

GetSMBParser returns the singleton SMB action parser

func (*SMBActionParser) ContainsAction added in v0.0.51

func (p *SMBActionParser) ContainsAction(actions []smbfern.PentestSmbAction, target smbfern.PentestSmbAction) bool

func (*SMBActionParser) GetValidActions added in v0.0.51

func (p *SMBActionParser) GetValidActions() []string

func (*SMBActionParser) ParseActions added in v0.0.51

func (p *SMBActionParser) ParseActions(actionStrings []string) ([]smbfern.PentestSmbAction, error)

type SNMPActionParser added in v0.0.188

type SNMPActionParser struct{}

SNMPActionParser handles SNMP-specific action parsing

func GetSNMPParser added in v0.0.188

func GetSNMPParser() *SNMPActionParser

GetSNMPParser returns the singleton SNMP action parser

func (*SNMPActionParser) ContainsAction added in v0.0.188

func (p *SNMPActionParser) ContainsAction(actions []snmpfern.PentestSnmpAction, target snmpfern.PentestSnmpAction) bool

func (*SNMPActionParser) GetValidActions added in v0.0.188

func (p *SNMPActionParser) GetValidActions() []string

func (*SNMPActionParser) ParseActions added in v0.0.188

func (p *SNMPActionParser) ParseActions(actionStrings []string) ([]snmpfern.PentestSnmpAction, error)

type SSHActionParser added in v0.0.51

type SSHActionParser struct{}

SSHActionParser handles SSH-specific action parsing

func GetSSHParser added in v0.0.51

func GetSSHParser() *SSHActionParser

GetSSHParser returns the singleton SSH action parser

func (*SSHActionParser) ContainsAction added in v0.0.51

func (p *SSHActionParser) ContainsAction(actions []sshfern.PentestSshAction, target sshfern.PentestSshAction) bool

func (*SSHActionParser) GetValidActions added in v0.0.51

func (p *SSHActionParser) GetValidActions() []string

func (*SSHActionParser) ParseActions added in v0.0.51

func (p *SSHActionParser) ParseActions(actionStrings []string) ([]sshfern.PentestSshAction, error)

type TelnetActionParser added in v0.0.51

type TelnetActionParser struct{}

TelnetActionParser handles Telnet-specific action parsing

func GetTelnetParser added in v0.0.51

func GetTelnetParser() *TelnetActionParser

GetTelnetParser returns the singleton Telnet action parser

func (*TelnetActionParser) ContainsAction added in v0.0.51

func (*TelnetActionParser) GetValidActions added in v0.0.51

func (p *TelnetActionParser) GetValidActions() []string

func (*TelnetActionParser) ParseActions added in v0.0.51

func (p *TelnetActionParser) ParseActions(actionStrings []string) ([]telnetfern.PentestTelnetAction, error)

type WinRMActionParser added in v0.0.115

type WinRMActionParser struct{}

WinRMActionParser handles WinRM-specific action parsing

func GetWinRMParser added in v0.0.115

func GetWinRMParser() *WinRMActionParser

GetWinRMParser returns the singleton WinRM action parser

func (*WinRMActionParser) ContainsAction added in v0.0.115

func (p *WinRMActionParser) ContainsAction(actions []winrmfern.PentestWinrmAction, target winrmfern.PentestWinrmAction) bool

func (*WinRMActionParser) GetValidActions added in v0.0.115

func (p *WinRMActionParser) GetValidActions() []string

func (*WinRMActionParser) ParseActions added in v0.0.115

func (p *WinRMActionParser) ParseActions(actionStrings []string) ([]winrmfern.PentestWinrmAction, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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