Documentation
¶
Overview ¶
Package namefind finds the host names under a domain (PRD-022, internal).
No single source knows every name, so a run combines several and keeps, for each name, which source reported it. Then every name is resolved and a short list of ports is tried, so the caller can show what is really there before anything is added or scanned.
The package decides nothing about what may be reached: the caller passes the address check and the dial function (the server's Guard), and every connection goes through them.
Index ¶
Constants ¶
const ( SourceDomain = "domain" // the domain itself SourceStored = "stored" // names in certificates already in the store SourceDNS = "dns" // the domain's own DNS records SourceCT = "ct" // Certificate Transparency search (sends the domain to a third party) SourceWordlist = "wordlist" // guessing common labels SourceList = "list" // a list the operator supplied )
Source ids, in the order they are reported.
const ( DefaultMaxNames = 50000 DefaultQPS = 50 )
Limits of one run.
Variables ¶
var ( WebPorts = []int{443, 8443, 22} MailPort = 25 )
WebPorts are tried on every name that resolves; MailPort only on names an MX record gave.
var AllSources = []string{SourceStored, SourceDNS, SourceCT, SourceWordlist, SourceList}
AllSources lists every source a caller may ask for, in report order.
Functions ¶
func Labels ¶
func Labels() []string
Labels is the built-in list of labels tried by the word-list source.
func NormalizeDomain ¶
NormalizeDomain lower-cases a domain and checks its shape. It accepts "example.com", "Example.COM." and "*.example.com"; it refuses addresses, single labels and anything with a scheme, a port or a path.
Types ¶
type CTSearcher ¶
type CTSearcher interface {
// Name is the service asked, for the report.
Name() string
// Search returns every name in certificates issued for the domain or a name under it.
// Wildcard names are returned as they are ("*.example.com").
Search(ctx context.Context, domain string) ([]string, error)
}
CTSearcher finds names in Certificate Transparency logs. A search tells the service which domain is being asked about, so the caller only supplies one when the operator turned it on.
type CrtSh ¶
type CrtSh struct {
// Client makes the request (default: a client with a two-minute timeout).
Client *http.Client
// URL replaces https://crt.sh/ (tests).
URL string
}
CrtSh searches crt.sh, Sectigo's public search over the logs. It is free and needs no key; it limits each address to a few requests a minute and can time out on a very large domain.
type Name ¶
type Name struct {
Name string `json:"name"`
// Sources are the ids of the sources that reported the name.
Sources []string `json:"sources"`
// Addresses are what the name resolves to; empty when it does not resolve.
Addresses []string `json:"addresses"`
// CNAME is the canonical name when the name is an alias.
CNAME string `json:"cname,omitempty"`
// External says the canonical name is outside the domain: the service is hosted elsewhere.
External bool `json:"external"`
// Ports are the ports that accepted a connection.
Ports []int `json:"ports"`
// Refused is why the name may not be connected to (the scan scope or a blocked address).
Refused string `json:"refused,omitempty"`
// Mail says an MX record names this host.
Mail bool `json:"mail,omitempty"`
// Wildcard says the name resolves only to what the zone answers for any name under the
// domain. It may be a real site on that server or no site at all: DNS cannot tell them apart,
// and a port that answers there answers for every name.
Wildcard bool `json:"wildcard,omitempty"`
}
Name is one host name under the domain and what the run learned about it.
type Options ¶
type Options struct {
// Domain is the registered or delegated domain to look under, such as "example.com".
Domain string
// Sources are the source ids to use. The domain itself is always included.
Sources []string
// Stored are names from certificates the caller already holds (SourceStored).
Stored []string
// List are names the operator supplied (SourceList).
List []string
// CT searches Certificate Transparency (SourceCT). Nil means the source is unavailable.
CT CTSearcher
Resolver Resolver
// CheckIP says whether host may be connected to at ip; an error is the reason it may not.
CheckIP func(host string, ip net.IP) error
// Dial opens a TCP connection to address:port. It is only called with an address CheckIP
// allowed for the name being checked.
Dial func(ctx context.Context, address string, port int) (net.Conn, error)
// MaxNames stops collecting (default 50,000). QPS limits DNS queries per second (default 50).
MaxNames int
QPS int
// SkipPorts leaves out the port checks (names and addresses only).
SkipPorts bool
// Progress, when set, is told the stage and how far it is. It is called from several goroutines.
Progress func(stage string, done, total int)
}
Options configures a run.
type Resolver ¶
type Resolver interface {
LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)
LookupCNAME(ctx context.Context, host string) (string, error)
LookupMX(ctx context.Context, name string) ([]*net.MX, error)
LookupNS(ctx context.Context, name string) ([]*net.NS, error)
LookupTXT(ctx context.Context, name string) ([]string, error)
LookupSRV(ctx context.Context, service, proto, name string) (string, []*net.SRV, error)
}
Resolver is the part of net.Resolver a run uses; tests supply their own.
type Result ¶
type Result struct {
Domain string `json:"domain"`
Names []Name `json:"names"`
Sources []SourceReport `json:"sources"`
// Wildcard says the zone answers for any name under the domain, with WildcardAddresses. Names
// that resolve only there are marked; guessed names that only matched it were dropped.
Wildcard bool `json:"wildcard"`
WildcardAddresses []string `json:"wildcardAddresses"`
// WildcardCerts are wildcard names seen in certificates: names behind them cannot be listed.
WildcardCerts []string `json:"wildcardCerts"`
// Truncated says collecting stopped at MaxNames.
Truncated bool `json:"truncated"`
// Outside counts supplied names that were not under the domain and were left out.
Outside int `json:"outside"`
}
Result is the outcome of a run.
type SourceReport ¶
type SourceReport struct {
ID string `json:"id"`
// Status is "ran", "off" (not asked for or not available) or "failed".
Status string `json:"status"`
// Found is how many names under the domain the source reported.
Found int `json:"found"`
// Detail is the reason for "off" or "failed", or a note about what ran.
Detail string `json:"detail,omitempty"`
}
SourceReport says what became of one source.