helpers

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultUserAgent = "Mozilla/5.0 (compatible; SNItch/1.4; +https://github.com/cirosec/SNItch)"

DefaultUserAgent is the User-Agent sent on every outbound HTTP(S) request when the user does not override it via --user-agent. Go's default ("Go-http-client/1.1") is trivially fingerprintable and is blocked by some WAFs/CDNs, which would otherwise corrupt HTTP status and title results.

Variables

This section is empty.

Functions

func CanonicalCertName added in v1.4.0

func CanonicalCertName(name string) string

CanonicalCertName normalizes a certificate name for display and comparison: IP literals (including bracketed IPv6 like "[::1]") become their canonical form so they deduplicate against the certificate's IP SANs; any other name is returned unchanged.

func CanonicalHostname added in v1.4.0

func CanonicalHostname(name string) (string, bool)

CanonicalHostname returns the canonical form of a hostname: trimmed, without trailing dots, lowercased, with IDN U-labels converted to punycode A-labels. A leading "*." wildcard prefix is preserved and canonicalized with the name. ok is false when the result is not a syntactically valid hostname; in that case no name is returned.

func CenterString

func CenterString(str string, width int, symbol string) string

func CertEmailAddresses added in v1.4.0

func CertEmailAddresses(cert *x509.Certificate) []string

CertEmailAddresses returns every email address a certificate carries: SAN rfc822Name entries plus the legacy emailAddress attribute in the subject and issuer DNs. These often name the device vendor and are otherwise invisible to SNItch's DNS-SAN-only parsing.

func CertEmailDomains added in v1.4.0

func CertEmailDomains(cert *x509.Certificate) []string

CertEmailDomains returns the deduplicated domains of all email addresses in a certificate (see CertEmailAddresses). Only domains that are syntactically valid hostnames are returned.

func CertHostnames added in v1.4.0

func CertHostnames(cert *x509.Certificate) []string

func CertOrganizations added in v1.4.0

func CertOrganizations(cert *x509.Certificate) []string

CertOrganizations returns the organization (O) values of the subject and issuer DNs, deduplicated. Intended for display only: organization names are free text and must not be treated as hostnames.

func CertURIHosts added in v1.4.0

func CertURIHosts(cert *x509.Certificate) []string

CertURIHosts returns the hostnames of every URI SAN entry, deduplicated. Such URIs (e.g. a provisioning or management endpoint) can reveal a hostname that the DNS SANs omit.

func ChunkBy

func ChunkBy[T any](items []T, chunkSize int) (chunks [][]T)

func Contains

func Contains(s []string, e string) bool

func ContainsFold added in v1.4.0

func ContainsFold(s []string, e string) bool

func DNSDomainInArray

func DNSDomainInArray(d []string, domain string) bool

DNSDomainInArray reports whether domain is covered by any entry in d. Matching is case-insensitive and ignores trailing dots. A wildcard entry ("*.example.com") covers exactly one label (RFC 6125): it matches "foo.example.com" but neither "a.b.example.com" nor "example.com".

func EmailDomain added in v1.4.0

func EmailDomain(email string) (string, bool)

EmailDomain returns the domain part of an email address, or ok=false when it carries no usable domain. Only the domain is returned: the local part is a mailbox, not a hostname.

func EncodingVariants added in v1.4.0

func EncodingVariants(host string) []string

EncodingVariants returns de-duplicated alternative encodings of host that a TLS server might treat differently from the literal hostname. The input itself is never included. A trailing dot, uppercased form and the IDN A-label/U-label counterparts are considered.

func ExpandCIDR

func ExpandCIDR(cidr string) ([]string, error)

func FQDNToSLD

func FQDNToSLD(FQDN string) (string, error)

func GetLabelByLevelFromFQDN

func GetLabelByLevelFromFQDN(fqdn string, level int) (string, string)

func GetURLPath

func GetURLPath(rawURL string) string

GetURLPath extracts the path and query from a URL string, stripping scheme and host. This is used to compare redirect URLs from catch-all servers that echo back the requested hostname but redirect to the same path.

func IsCIDR

func IsCIDR(potentialCIDR string) bool

func IsIPLiteral added in v1.4.0

func IsIPLiteral(name string) bool

IsIPLiteral reports whether name is an IP address, accepting both bare and bracketed (IPv6) forms. Certificate SANs sometimes carry IP addresses in DNS-type entries, e.g. "127.0.0.1" or "[::1]".

func IsPortOpen

func IsPortOpen(host string, port string, timeout time.Duration) bool

func IsValidHostname added in v1.4.0

func IsValidHostname(name string) bool

IsValidHostname reports whether name is syntactically a valid DNS hostname (RFC 1123, plus underscore-bearing labels such as "_dmarc.example.com" that occur in real SANs and DNS), optionally prefixed with "*." for a wildcard. It deliberately does not require a public suffix, so single-label names ("synology", "localhost") and internal names ("host.corp.local") are accepted as long as they are well-formed; SNItch is tolerant and after information.

func MetaSplit

func MetaSplit(s []string, sep string) []string

func ParseListFile

func ParseListFile(path string) ([]string, error)

func RandStringBytes

func RandStringBytes(n int) string

RandStringBytes generates a random string of n length

func RemoveDuplicate

func RemoveDuplicate[T string | int](sliceList []T) []T

func RemoveEmpty

func RemoveEmpty[T string](s []T) []T

func ResolveUserAgent added in v1.4.0

func ResolveUserAgent(userAgent string) string

ResolveUserAgent returns the configured user agent, falling back to DefaultUserAgent when none was supplied.

func SanitizeHostname added in v1.4.0

func SanitizeHostname(name string) (string, bool)

CertHostnames returns the names a certificate may be matched against under a tolerant, legacy-compatible interpretation: its SAN DNS entries plus its CommonName. Modern clients ignore CN whenever SANs are present, but SNItch is looking for information rather than strict certificate correctness, so a CN-only certificate still surfaces the hostname it identifies. SanitizeHostname returns the canonical form of a candidate name (see CanonicalHostname) and reports whether it is a usable hostname. Names that fail validation must not be fed into the scan queue or used to build tree nodes.

func SetUserAgent added in v1.4.0

func SetUserAgent(req *http.Request, userAgent string)

SetUserAgent sets the User-Agent header on req to the resolved user agent. It always sets a non-empty value so that Go's fingerprintable default is never sent.

func SortDomains

func SortDomains(domains []string)

func SortIPAddresses

func SortIPAddresses(ipAddresses []string) []string

func SplitIntoCidrAndPort

func SplitIntoCidrAndPort(cidrWithPort string) (string, int, error)

func WildcardOrFullMatch

func WildcardOrFullMatch(hostname string, matchHostList []string) bool

WildcardOrFullMatch reports whether hostname is covered by an ignore-style match list. Entries are compared case-insensitively and without trailing dots. A "*.<domain>" entry matches the domain itself and every subdomain below it. A wildcard suffix without a label boundary ("*example.com") never matches, and a bare "*" matches nothing: use an explicit domain instead.

Types

This section is empty.

Jump to

Keyboard shortcuts

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