subenum

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: GPL-3.0 Imports: 21 Imported by: ? modules, 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

Overview

Package subenum embeds subenum's subdomain enumeration engine in other Go programs. It is the same engine the command-line tool runs: a worker pool over a wordlist, wildcard fingerprinting and filtering, per-second query pacing, retries, a reliability guard and per-outcome accounting.

Scan is the simplest entry point and returns everything a finished scan found. Run streams results, notices and progress as they happen.

Only enumerate domains you own or have permission to test. Simulate produces synthetic results without sending any DNS queries, which is what examples and tests should use.

This package follows semantic versioning from v1.0.0. Until then it may change between minor releases; the command-line interface is stable.

Example

Scan runs an enumeration to completion and hands back everything it found. Simulate invents the results, so this example sends no DNS queries; drop it and give a Resolver to scan a domain you are allowed to test.

package main

import (
	"context"
	"fmt"
	"log"
	"sort"

	"github.com/TMHSDigital/subenum/pkg/subenum"
)

func main() {
	results, stats, err := subenum.Scan(context.Background(), subenum.Config{
		Domain:   "example.com",
		Words:    []string{"www", "mail", "api"},
		Simulate: true,
		HitRate:  100,
		Seed:     1,
	})
	if err != nil {
		log.Fatal(err)
	}

	names := make([]string, 0, len(results))
	for _, r := range results {
		names = append(names, r.Name)
	}
	sort.Strings(names)
	for _, n := range names {
		fmt.Println(n)
	}
	fmt.Printf("resolved %d of %d candidates\n", stats.Found, stats.Total())

}
Output:
api.example.com
mail.example.com
www.example.com
resolved 3 of 3 candidates

Index

Examples

Constants

View Source
const (
	DefaultResolver    = "8.8.8.8:53"
	DefaultConcurrency = 100
	DefaultTimeout     = time.Second
	DefaultAttempts    = 1
	DefaultHitRate     = 15
)

Defaults applied to a Config's zero values. They are the command line's defaults too; TestDefaultsMatchTheCLI keeps them in step.

View Source
const (
	VerdictComplete   = scan.VerdictComplete   // a name missing from the results most likely does not exist
	VerdictDegraded   = scan.VerdictDegraded   // some names were not tested or got no answer
	VerdictUnreliable = scan.VerdictUnreliable // too many lookups failed: a missing name means nothing
)

Verdicts a finished scan can get from Stats.Verdict, the same ones the CLI's run-quality report gives.

Variables

View Source
var ErrNoWords = errors.New("subenum: wordlist has no usable entries")

ErrNoWords is returned when a Config's wordlist has no usable entries.

Functions

func DefaultWords

func DefaultWords() []string

DefaultWords returns the bundled wordlist: the most common subdomain labels, from SecLists' top-5000 list, already normalized and deduplicated. Config.Words defaults to it. The returned slice is a fresh copy, safe to append to or filter.

func Permutations added in v0.11.0

func Permutations(seeds, words []string) []string

Permutations returns second-pass candidates for names a scan already found, the same ones the CLI's -permute tries: api suggests api-dev, dev-api, dev.api, api2 and so on. Each seed is a name relative to the apex, such as "api" for api.example.com or "api.us" for api.us.example.com; its leftmost label is permuted and the rest kept. words are combined with each seed label; nil selects the CLI's built-in list of environment, version and role names. Candidates that are not valid DNS names are left out. The result is relative to the apex, like Config.Words, sorted and duplicate-free, so it can be passed as the Words of a follow-up scan. It sends no DNS queries.

Example

Permutations suggests the names most likely to sit next to ones a scan already found. Its output is relative to the apex, so it can feed the Words of a second scan. Pass nil words for the CLI's built-in list.

package main

import (
	"fmt"

	"github.com/TMHSDigital/subenum/pkg/subenum"
)

func main() {
	for _, name := range subenum.Permutations([]string{"api"}, []string{"dev"}) {
		fmt.Println(name)
	}

}
Output:
api-dev
api1
api2
api3
dev-api
dev.api

func Run

func Run(ctx context.Context, cfg Config) (<-chan Event, error)

Run starts a scan and streams its events. The channel ends with exactly one KindDone event and is then closed, so a range loop over it always sees the final Stats. Problems with cfg itself are reported before the scan starts, as an error and no channel.

Read the channel until it closes, or cancel ctx: the usual `for ev := range events { ... break ... }` with a deferred cancel is safe. While ctx is live, an unread channel pauses the scan once its buffer fills. Once ctx is cancelled the scan stops and never waits for the caller: results nobody reads may be dropped, and a caller that keeps reading still gets KindDone with the counts so far. Every goroutine the scan started exits within about a second of cancellation, whether or not the channel is read (#112).

Example

Run streams events while the scan is still going, which is what a long scan or a progress display wants. The channel always ends with one KindDone event carrying the final counts.

package main

import (
	"context"
	"fmt"
	"sort"
	"time"

	"github.com/TMHSDigital/subenum/pkg/subenum"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	events, err := subenum.Run(ctx, subenum.Config{
		Domain:   "example.com",
		Words:    []string{"www", "dev", "stage", "api"},
		Simulate: true,
		HitRate:  100,
		Seed:     1,
	})
	if err != nil {
		fmt.Println("cannot start:", err)
		return
	}

	var names []string
	var stats subenum.Stats
	for ev := range events {
		switch ev.Kind {
		case subenum.KindResult:
			names = append(names, ev.Result.Name)
		case subenum.KindNotice:
			fmt.Printf("notice (%s): %s\n", ev.Notice, ev.Message)
		case subenum.KindError:
			fmt.Println("error:", ev.Message)
		case subenum.KindDone:
			stats = ev.Stats
		}
	}

	sort.Strings(names)
	fmt.Println("found:", len(names))
	for _, n := range names {
		fmt.Println(" ", n)
	}
	fmt.Println("did not exist:", stats.NXDomain)

}
Output:
found: 4
  api.example.com
  dev.example.com
  stage.example.com
  www.example.com
did not exist: 0

func Scan

func Scan(ctx context.Context, cfg Config) ([]Result, Stats, error)

Scan runs a scan to completion and returns everything it found, in the order the names resolved.

An error means the results are incomplete or absent: the context was cancelled, the domain is a wildcard zone and Force is not set, the resolver failed its preflight check, or too many lookups were failing and the reliability guard stopped the scan. The results and Stats gathered up to that point come back alongside it, so a partial scan can still be reported.

Types

type Change added in v0.11.0

type Change struct {
	Name     string
	Previous []Record
	Current  []Record
}

Change is a name found in both runs whose records differ.

type Changes added in v0.11.0

type Changes struct {
	// Added are names in the current results that the previous ones lack.
	Added []string

	// Removed are previous names the current results lack. A name can be
	// missing because it no longer exists, but also because it was not a
	// candidate this time or its lookup failed, so look these up again
	// before treating them as gone: the command line reports a name removed
	// only after a fresh NXDOMAIN, and only for a complete run.
	Removed []string

	// Changed are names in both whose records differ.
	Changed []Change
}

Changes is how one set of results differs from an earlier one; see Diff. Every list is sorted by name.

func Diff added in v0.11.0

func Diff(previous, current []Result, types []string) Changes

Diff compares current results with previous ones, such as last week's Scan of the same domain, the way the command line's -diff and -diff-records do. Names are compared case-insensitively and without a trailing dot.

Records are compared as sets, over the record types in types (every type when types is nil); pass the Config.Types both scans used, so a type only one of them looked up is not reported as a change. When either side has a CNAME and CNAME is compared, only the CNAME targets count: a re-pointed alias is a change, while the addresses behind a CDN alias rotate and are not. A previous result without records, such as one read from a plain list of names, is never reported as changed. Diff sends no DNS queries.

Example

Diff compares two scans of the same domain, here last week's results with today's. Pass the record types both scans looked up.

package main

import (
	"fmt"

	"github.com/TMHSDigital/subenum/pkg/subenum"
)

func main() {
	lastWeek := []subenum.Result{
		{Name: "www.example.com", Records: []subenum.Record{{Type: "A", Value: "192.0.2.1"}}},
		{Name: "blog.example.com", Records: []subenum.Record{{Type: "CNAME", Value: "blog.host.example"}}},
		{Name: "old.example.com", Records: []subenum.Record{{Type: "A", Value: "192.0.2.2"}}},
	}
	today := []subenum.Result{
		{Name: "www.example.com", Records: []subenum.Record{{Type: "A", Value: "192.0.2.1"}}},
		{Name: "blog.example.com", Records: []subenum.Record{{Type: "CNAME", Value: "unclaimed.example"}}},
		{Name: "api.example.com", Records: []subenum.Record{{Type: "A", Value: "192.0.2.3"}}},
	}
	changes := subenum.Diff(lastWeek, today, []string{"A", "AAAA", "CNAME"})
	fmt.Println("added:", changes.Added)
	fmt.Println("missing, to re-check:", changes.Removed)
	for _, c := range changes.Changed {
		fmt.Println("changed:", c.Name, c.Previous, "->", c.Current)
	}

}
Output:
added: [api.example.com]
missing, to re-check: [old.example.com]
changed: blog.example.com [{CNAME blog.host.example}] -> [{CNAME unclaimed.example}]

type Config

type Config struct {
	// Domain is the apex to enumerate under, for example "example.com". A
	// URL, a trailing dot, a port or an internationalized name are
	// normalized the way the command line normalizes them.
	Domain string

	// Words are the subdomain labels to try, one label per entry ("www"),
	// or a dotted path to enumerate deeper ("api.eu"). Blank entries, "#"
	// comments, duplicates and entries too long to form a legal name are
	// dropped. Nil uses DefaultWords.
	Words []string

	// Resolver is the DNS server every lookup goes to: "ip:port",
	// "tls://host[:853]" for DNS over TLS, or "https://host/path" for DNS
	// over HTTPS. Empty means DefaultResolver.
	Resolver string

	// ResolverPool spreads candidate lookups over several resolvers ("ip",
	// "ip:port", "tls://host[:port]" or "https://host/path", as Resolver
	// takes them), which is faster but less trustworthy
	// than one server. Every name a pool member reports is re-checked
	// against Resolver, and only Resolver's answer is reported. Preflight
	// and wildcard probes always use Resolver.
	ResolverPool []string

	// RatePerResolver caps the DNS queries per second sent to each
	// ResolverPool member; Rate still caps the total, so the stricter limit
	// wins. 0 is unlimited. Ignored without a ResolverPool.
	RatePerResolver int

	// Concurrency is the number of workers looking up names at once.
	Concurrency int

	// Timeout bounds one lookup of one record type.
	Timeout time.Duration

	// Attempts is the number of tries per name. 1 does not retry. Only
	// failures (timeouts, SERVFAIL, REFUSED) are retried, never an answer
	// saying the name does not exist.
	Attempts int

	// Rate caps DNS queries per second on the wire across all workers,
	// counting every record type, retry and wildcard probe. 0 is
	// unlimited. Pace scans of resolvers you do not own.
	Rate int

	// Types are the record types to look up: "A", "AAAA", "CNAME", "NS",
	// "MX", "TXT", "SRV" and "HTTPS". Nil looks up A and AAAA. CNAME, NS,
	// SRV and HTTPS (an AliasMode target) are what populate Result.Takeover.
	Types []string

	// Recursive enumerates Words again under every name that is found,
	// down to Depth levels.
	Recursive bool

	// Depth is the deepest level a recursive scan reaches. 1, the default,
	// does not recurse. Each level multiplies the candidate count by
	// len(Words), or by len(RecursiveWords) when it is set, so set
	// MaxQueries as well.
	Depth int

	// FollowRecords also looks up the names under the domain that a found
	// name's CNAME, MX or NS records point at, once each, unless they are
	// already candidates, within MaxQueries. Their results' Sources are
	// "records" (#432).
	FollowRecords bool

	// RecursiveWords are the labels a recursive scan tries under each name
	// it finds, at depth 2 and below, cleaned like Words. Nil uses Words;
	// a short list makes deep recursion affordable (#403).
	RecursiveWords []string

	// MaxQueries caps how many candidate names are tested. 0 is unlimited.
	MaxQueries int

	// MaxDuration is a time budget, counted from when Run starts but not
	// including the preflight and wildcard probes sent before the first
	// candidate lookup, so Run can take longer than MaxDuration. Once it
	// runs out no new name is looked up, lookups already under way finish,
	// and the names left are counted in Stats.Skipped with Stats.Expired
	// set. 0 is unlimited.
	MaxDuration time.Duration

	// AutoRate keeps a scan going when its resolver starts failing: when
	// more than a fifth of the last 200 lookups failed, the query rate is
	// halved (from the rate reached so far when Rate is 0), up to six times
	// and down to 5 per second, and raised again once lookups succeed. A
	// KindNotice event with NoticeRate reports each change. Only when it
	// can slow down no further does the reliability guard apply.
	AutoRate bool

	// RetryInconclusive looks up once more, after every candidate has been
	// tried, each name whose lookup timed out, was refused or failed. The
	// retry goes to Resolver. A name that then resolves is reported like any
	// other, but not expanded by Recursive. Stats.Retried and
	// Stats.Recovered count the pass; Stats.Inconclusive lists the names
	// still without an answer, with or without it.
	RetryInconclusive bool

	// Sources propose extra candidates before the scan, such as
	// CertificateTransparency(), WaybackMachine(), CertSpotter() and
	// ZoneTransfer(): their
	// names are added after Words and looked up like any other, so a stale
	// name is never reported. Each is asked once; one that fails sends a KindNotice event
	// with NoticeSource and the scan goes on without it. Ignored when
	// Simulate is set.
	Sources []Source

	// TakeoverProviders adds takeover-prone services to the built-in list
	// that Result.Takeover's "provider:<name>" hints come from. An entry for
	// a suffix already listed replaces it, and a Name of "-" removes the
	// suffix. The longest matching suffix wins.
	TakeoverProviders []TakeoverProvider

	// TakeoverProvidersOnly uses TakeoverProviders alone, without the
	// built-in list.
	TakeoverProvidersOnly bool

	// Exclude lists names that are out of scope and are never queried.
	// "mail.example.com" excludes one name; "*.corp.example.com" excludes
	// a whole branch.
	Exclude []string

	// Force scans a domain whose DNS answers every name (a wildcard zone)
	// instead of refusing. Results matching the wildcard fingerprint are
	// still dropped and counted in Stats.WildcardFiltered.
	Force bool

	// NoAbort keeps scanning when more than a fifth of lookups fail.
	// Without it the scan stops early and Stats.Aborted is set, because a
	// resolver that is failing cannot be distinguished from a domain whose
	// names do not exist. With it, Run still sends the reliability
	// warning as a KindError event, but the scan finishes and Scan
	// returns no error for it.
	NoAbort bool

	// Simulate invents results instead of sending DNS queries, for demos,
	// examples and tests. HitRate and Seed apply only to simulated scans.
	Simulate bool

	// HitRate is the percentage of names a simulated scan reports as
	// resolved, 1 to 100.
	HitRate int

	// Seed makes a simulated scan reproducible: the same seed and words
	// give the same results. 0 picks a random seed.
	Seed uint64

	// Verbose logs every lookup through Logf.
	Verbose bool

	// Logf receives verbose lines when Verbose is set. Nil writes them to
	// standard error.
	Logf func(format string, args ...any)
}

Config describes one scan. Every zero value selects the default above, so Config{Domain: "example.com"} is a complete configuration.

Example

A zero Config is a complete one: every field falls back to the same default the command line uses.

package main

import (
	"fmt"

	"github.com/TMHSDigital/subenum/pkg/subenum"
)

func main() {
	cfg := subenum.Config{Domain: "example.com"}

	fmt.Println("resolver:", subenum.DefaultResolver)
	fmt.Println("workers:", subenum.DefaultConcurrency)
	fmt.Println("timeout:", subenum.DefaultTimeout)
	fmt.Println("attempts:", subenum.DefaultAttempts)
	fmt.Println("words:", len(subenum.DefaultWords()))
	fmt.Println("domain:", cfg.Domain)

}
Output:
resolver: 8.8.8.8:53
workers: 100
timeout: 1s
attempts: 1
words: 5000
domain: example.com
Example (Recursive)

Recursion enumerates the wordlist again under each name it finds. Every level multiplies the candidate count by the size of the wordlist, so cap it with MaxQueries and pace it with Rate.

package main

import (
	"context"
	"fmt"
	"log"
	"sort"

	"github.com/TMHSDigital/subenum/pkg/subenum"
)

func main() {
	results, stats, err := subenum.Scan(context.Background(), subenum.Config{
		Domain:     "example.com",
		Words:      []string{"dev", "api"},
		Recursive:  true,
		Depth:      2,
		MaxQueries: 100,
		Rate:       50,
		Exclude:    []string{"*.dev.example.com"},
		Simulate:   true,
		HitRate:    100,
		Seed:       1,
	})
	if err != nil {
		log.Fatal(err)
	}

	names := make([]string, 0, len(results))
	for _, r := range results {
		names = append(names, r.Name)
	}
	sort.Strings(names)
	for _, n := range names {
		fmt.Println(n)
	}
	fmt.Println("out of scope, never queried:", stats.Excluded)

}
Output:
api.api.example.com
api.example.com
dev.api.example.com
dev.example.com
out of scope, never queried: 2

func (Config) Validate added in v0.11.0

func (c Config) Validate() error

Validate reports the error Run would return for cfg, without starting a scan or sending a query: an invalid Domain, Types or Exclude pattern, an empty word list, and the other problems with the config itself.

type Event

type Event struct {
	Kind Kind

	// Result is the subdomain found, on KindResult.
	Result Result

	// Notice categorizes a KindNotice event.
	Notice Notice

	// Message is the human-readable text of a KindNotice or KindError
	// event.
	Message string

	// Processed, Total and Found report progress on KindProgress. Total
	// grows during a recursive scan as new branches are queued, so treat
	// it as an estimate.
	Processed int64
	Total     int64
	Found     int64

	// Stats is the final accounting, on KindDone.
	Stats Stats

	// Stopped is set on KindDone when the scan ended before testing any
	// candidate, after a KindError (the domain is out of scope, a wildcard
	// zone without Force, a failed resolver check) or because ctx was
	// cancelled during those checks. Stats then covers only the checks.
	Stopped bool

	// Fatal is set on a KindError that ends the scan. The one KindError
	// without it is the reliability guard's warning under Config.NoAbort.
	Fatal bool

	// Failed is set on KindDone when the scan failed: a fatal KindError
	// was sent, or the reliability guard stopped the scan. A scan cancelled
	// through the context has not failed.
	Failed bool
}

Event is one update from a running scan.

type Kind

type Kind int

Kind says which fields of an Event are set.

const (
	// KindResult reports one resolved subdomain in Event.Result.
	KindResult Kind = iota
	// KindProgress reports how far the scan has got, in Event.Processed,
	// Event.Total and Event.Found.
	KindProgress
	// KindNotice reports something worth telling the user, in
	// Event.Message, categorized by Event.Notice.
	KindNotice
	// KindError reports in Event.Message a problem serious enough to stop
	// the scan: the domain is out of scope, the resolver failed a
	// preflight check, the domain is a wildcard zone and Force is not
	// set, or the reliability guard gave up. Few or no results follow.
	// The exception is the reliability guard under Config.NoAbort: its
	// warning arrives as a KindError, and the scan then runs to the end.
	// Event.Fatal tells the two apart.
	KindError
	// KindDone is always the last event, and reports Event.Stats. It
	// arrives whether the scan completed, never started, was stopped by
	// the reliability guard or was cancelled through the context.
	KindDone
)

Event kinds.

func (Kind) String

func (k Kind) String() string

String names a kind.

type Notice

type Notice int

Notice categorizes a KindNotice event, so a consumer can act on it without reading the message.

const (
	// NoticeNone is the zero value, used by events that are not notices.
	NoticeNone Notice = iota
	// NoticeWildcard means the domain answers every name, or that the
	// wildcard check itself failed under Force.
	NoticeWildcard
	// NoticeCap means MaxQueries or MaxDuration was reached and candidates
	// were skipped.
	NoticeCap
	// NoticeCeiling means a recursive scan could generate a very large
	// number of queries.
	NoticeCeiling
	// NoticeSkip means one recursive branch was not expanded.
	NoticeSkip
	// NoticeRate means AutoRate changed the query rate.
	NoticeRate
	// NoticeSource means a Config.Sources lookup failed; the scan went on
	// without that source's names.
	NoticeSource
)

Notice categories.

func (Notice) String

func (n Notice) String() string

String names a notice category.

type Record

type Record struct {
	Type  string // "A", "AAAA", "CNAME", "NS", "MX", "TXT", "SRV" or "HTTPS"
	Value string // an address, a CNAME target, a name server, "<preference> <host>" (MX), a text (TXT), "<priority> <weight> <port> <target>" (SRV) or "<priority> <target> [alpn=<ids>] [port=<n>]" (HTTPS)
}

Record is one DNS record behind a result.

type Result

type Result struct {
	// Name is the full subdomain, such as "www.example.com".
	Name string

	// Records are the records it resolved to. A result found through a
	// CNAME carries the alias and the addresses it leads to.
	Records []Record

	// Takeover is a hint that a CNAME (or an AliasMode HTTPS record)
	// points somewhere unclaimed:
	// "dangling" (the target does not resolve), "provider:<name>" (the
	// target belongs to a known hosting provider) or "dangling:<name>"
	// (both); or "dangling-ns" when the name is delegated to a name server
	// that does not resolve, or "dangling-srv" when an SRV target does not
	// resolve. It is derived only from DNS, so it is a lead to verify by
	// hand, not a finding. Empty unless Types includes "CNAME", "NS", "SRV"
	// or "HTTPS".
	Takeover string

	// Internal names the most notable non-public scope among the
	// addresses: "loopback", "unspecified", "link-local", "private"
	// (RFC 1918 or fc00::/7) or "cgnat" (100.64.0.0/10). A public name
	// that answers with one leaks internal addressing. Empty when every
	// address is public, and always empty in a simulated scan.
	Internal string

	// Partial is set when a lookup of one of Types failed (timeout,
	// refusal or other error) on every attempt while another type
	// answered, so Records may lack records of the failed type.
	Partial bool

	// Sources names what proposed the name (#273): "records" alone for a
	// name FollowRecords took from another result's records (#432),
	// otherwise "wordlist" for Words
	// (and, with Recursive, an entry below a found name), and each of
	// Config.Sources that returned it. A source is named by its Name()
	// string method when it has one ("ct", "wayback" and "certspotter" for
	// the built-in ones), else as "Sources[i]", its index in Config.Sources. Several
	// sources are listed in the order of Config.Sources, after "wordlist".
	Sources []string
}

Result is a subdomain that resolved.

type Source added in v0.11.0

type Source interface {
	// Names returns names under domain, relative to it ("api", "dev.api").
	// Names that are not valid in DNS are dropped by the scan.
	Names(ctx context.Context, domain string) ([]string, error)
}

Source proposes names under a domain for Config.Sources (#193). The passive sources below do not query the domain's DNS; ZoneTransfer asks its name servers. Implement it to seed scans from your own inventory or another passive index.

func CertSpotter added in v0.12.0

func CertSpotter() Source

CertSpotter returns the source behind the CLI's -sources certspotter: names in Certificate Transparency logs through SSLMate Cert Spotter, a second CT index for when crt.sh is down (#416). No API key is needed; one in CERTSPOTTER_API_KEY raises the small unauthenticated hourly quota. It reads up to 10 pages, one HTTPS request each, per scan.

func CertificateTransparency added in v0.11.0

func CertificateTransparency() Source

CertificateTransparency returns the source behind the CLI's -ct: names in Certificate Transparency logs, through crt.sh. One HTTPS request per scan, no API key.

func NSECWalk added in v0.12.0

func NSECWalk(opts ZoneOptions) Source

NSECWalk returns the source behind the CLI's -nsec-walk (#437): the names an NSEC walk lists when the domain's zone is signed with plain NSEC, from ProbeZone with WalkNSEC set but no transfer. The walk asks the domain's own name server, paced by opts.Rate (not Config.Rate) and capped by opts.MaxQueries; Config.Exclude applies to it. An NSEC3 or unsigned zone gives no names and no error.

func WaybackMachine added in v0.11.0

func WaybackMachine() Source

WaybackMachine returns the source behind the CLI's -sources wayback: hostnames in the Wayback Machine's index of archived URLs. One HTTPS request per scan, no API key.

func ZoneTransfer added in v0.11.0

func ZoneTransfer(opts ZoneOptions) Source

ZoneTransfer returns the source behind the CLI's -axfr: the names a full zone transfer gives, from ProbeZone. Unlike the passive sources it queries the domain's own name servers, and those queries are not paced by Config.Rate. A domain whose name servers all refuse gives no names and no error.

type Stats

type Stats struct {
	// Outcomes. Each candidate name lands in exactly one of these.
	Found            int64 // resolved and reported
	NXDomain         int64 // the resolver said the name does not exist
	Timeout          int64 // no answer in time
	Refused          int64 // the resolver refused to answer
	Other            int64 // any other failure, such as SERVFAIL
	WildcardFiltered int64 // resolved, but matched the wildcard fingerprint

	QueriesSent int64 // DNS queries sent, retries included; 0 when simulated
	Skipped     int64 // candidates left untested because MaxQueries or MaxDuration was reached
	Excluded    int64 // candidates left untested because Exclude covered them
	Takeover    int64 // results carrying a Takeover hint
	Internal    int64 // results with an Internal address scope
	Partial     int64 // results marked Partial

	// ParentChecks counts the names that failed with SERVFAIL, with NS
	// among Types, whose delegation was asked of the zone's own name
	// servers, and ParentQueries the queries that took; QueriesSent
	// includes them. A subzone whose every name server is gone is found
	// this way, as a Result with a dangling-ns Takeover hint.
	ParentChecks  int64
	ParentQueries int64

	PoolHits    int64 // names a ResolverPool member reported
	Confirmed   int64 // of those, the ones Resolver confirmed
	Unconfirmed int64 // of those, the ones Resolver said do not exist

	// Aborted reports that the reliability guard stopped the scan early,
	// so the results are incomplete and the negatives mean nothing.
	Aborted bool

	// Expired reports that MaxDuration ran out before every candidate was
	// tested; Skipped counts the ones left.
	Expired bool

	// Wildcard reports that the domain answers every name. Only Force
	// lets such a scan run.
	Wildcard bool

	// WildcardFingerprint is the answer the wildcard gives, learned from
	// random probes. Empty when there is no wildcard.
	WildcardFingerprint []Record

	// Retried counts the names Config.RetryInconclusive looked up again,
	// and Recovered the ones that then got an answer; the outcome counters
	// above already count those under their new outcome.
	Retried   int64
	Recovered int64

	// Inconclusive lists, sorted, the names whose lookup still timed out,
	// was refused or failed when the scan ended: their existence is
	// unknown. Feed them to another scan to try again.
	Inconclusive []string

	// RateBackoffs counts how often AutoRate halved the rate, and
	// FinalRate is the rate in queries per second when the scan ended
	// (0 = unlimited). Both are 0 without AutoRate.
	RateBackoffs int64
	FinalRate    int64
}

Stats accounts for every candidate name a finished scan looked up.

func (Stats) Total

func (s Stats) Total() int64

Total returns the number of candidate names that were looked up and classified.

func (Stats) Verdict added in v0.11.0

func (s Stats) Verdict(interrupted bool) (verdict, reason string)

Verdict says how far the results of a finished scan can be trusted, by the rules of the CLI's run-quality report: VerdictComplete, VerdictDegraded or VerdictUnreliable, with the reason in plain words. interrupted reports that the scan was cancelled before it ended. The reason names Config fields, such as MaxQueries.

type TakeoverProvider added in v0.11.0

type TakeoverProvider struct {
	Suffix string
	Name   string
}

TakeoverProvider is a takeover-prone service for Config.TakeoverProviders: CNAME targets under Suffix (".example-cdn.net", the leading dot optional) belong to Name ("example-cdn": lowercase letters, digits and hyphens).

type ZoneInfo added in v0.11.0

type ZoneInfo struct {
	// Names are the names the transfers gave, relative to the domain
	// ("api", "dev.api"), sorted. They have not been resolved.
	Names []string

	// TransferAllowed lists the name servers that allowed a zone transfer.
	// Anyone can list such a zone; transfers should be limited to the
	// zone's secondaries.
	TransferAllowed []string

	// Denial is how the zone proves a name does not exist: "nsec" (plain
	// NSEC, so anyone can list every name by walking the zone), "nsec3",
	// "none" (no DNSSEC), or "" when no name server answered the probe.
	Denial string

	// Walked are the names the NSEC walk listed, relative to the domain,
	// sorted, with ZoneOptions.WalkNSEC. They have not been resolved.
	Walked []string

	// WalkStop says why the NSEC walk stopped before it listed the whole
	// zone (a loop in the chain, MaxQueries, a failed query), or why it did
	// not run (an NSEC3 or unsigned zone); "" when it listed every name or
	// was not asked for.
	WalkStop string
}

ZoneInfo is what ProbeZone learned about a domain's zone.

func ProbeZone added in v0.11.0

func ProbeZone(ctx context.Context, domain string, opts ZoneOptions) (ZoneInfo, error)

ProbeZone does what the CLI's -axfr does before a scan: it looks up domain's name servers through opts.Resolver and asks each for a full zone transfer (AXFR), and one of them how the zone proves a name does not exist. Like the CLI, it asks at most 8 name servers and 2 addresses of each. Most servers refuse transfers, which is the correct configuration and not an error. The queries go to the domain's own name servers and are not paced; it sends about four per name server.

The error reports an invalid domain or option, a name server lookup that failed, or a cancelled ctx.

type ZoneOptions added in v0.11.0

type ZoneOptions struct {
	// Resolver finds the domain's name servers and their addresses, in the
	// forms Config.Resolver accepts. Empty means DefaultResolver. The
	// transfers themselves go to the name servers.
	Resolver string

	// Timeout bounds one lookup and the DNSSEC probe. A transfer is given
	// at least 10 seconds. Zero means DefaultTimeout.
	Timeout time.Duration

	// WalkNSEC makes ProbeZone also walk a zone the probe finds signed
	// with plain NSEC, as the CLI's -nsec-walk does, and list its names in
	// ZoneInfo.Walked (#437). The walk asks the name server that answered
	// the probe, one query per name.
	WalkNSEC bool

	// Rate paces the NSEC walk's queries, per second. Zero sends them
	// unpaced.
	Rate int

	// MaxQueries caps the NSEC walk's queries. Zero means the built-in cap
	// of 10,000.
	MaxQueries int
}

ZoneOptions configures ProbeZone and ZoneTransfer.

Jump to

Keyboard shortcuts

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