Documentation
¶
Overview ¶
Package surface is the external-surface scan of the scan module, the exposure.Runner behind "Scan now" of External exposure (S-EXP-1). It follows LEGAL §3: active probes only on verified assets.
- The box's own public IP (a verified IP target): a TCP connect to a fixed list of ports (commonPorts), then one GET of "/" on the open web ports and a TLS handshake on the TLS ports (admin pages, the Server header, certificates).
- A verified domain: its names from certificate-transparency logs (crt.sh), the apex's MX and NS hosts under it and the common names of content/wordlist that resolve, each resolved (A, AAAA, CNAME) through the box's resolver, classed and listed. A name that points at a public address gets HTTP checks by name only: one GET of "/" on port 80 and on 443 (with the certificate of 443). The addresses are never port-scanned, unless one is itself a verified IP target that may be scanned now (the caller decides, through exposure).
Nothing else is sent: no exploit, no login, no path but "/", no redirect followed, no UDP. Every probe is written to the probe log (ProbeLog) before it goes out, and again with its answer.
It is the Go standard library only: a TCP connect does what a port scan needs from the box's own network without raw sockets, pcap or cgo, so the ProjectDiscovery libraries once planned are not needed. It runs in core (the box's outgoing HTTPS is there already); the scan container stays for nmap and nuclei.
Everything a target sends back is untrusted (SYS-6): reads are bounded in size and time, pages are matched as text, certificates are parsed by crypto/x509, names by a strict rule. Every probe goes to an address that Public accepted, checked again at the dial.
Index ¶
Constants ¶
const ( ClassBox = "box" ClassPublic = "public" ClassPrivate = "private" )
The kinds of a name's address (exposure INV-27: whatever serves a name, a CDN or not, does not matter): box is this box's own verified, current IP (exposure's ScannableIP); public any other public address; private an address that is not public, never dialed.
const ( SourceCT = "ct" // a certificate-transparency log (crt.sh) SourceDNS = "dns" // the domain itself SourceMX = "mx" // a mail host of the apex, under the domain SourceNS = "ns" // a name server of the apex, under the domain SourceWordlist = "wordlist" // a common name that resolves )
Where a name was found.
const ( WordlistWildcard = "wildcard" // the domain answers any name WordlistNoAnswer = "no_answer" // the wildcard check got no clear answer (time-out, server failure): skipped, fail closed WordlistCut = "cut" // the DNS phase reached dnsBudget before every common name was tried WordlistChosen = "chosen" // the scope is the names chosen: the common names are not tried for the others )
Why the common names were not all tried (Result.Wordlist); "" when they were.
Variables ¶
var ErrCT = errors.New("surface: the certificate-transparency search did not answer")
ErrCT means the certificate-transparency search gave no usable answer (down, slow, not JSON). The scan stops: a snapshot without the subdomains would say they are gone.
var ErrDNS = errors.New("surface: the DNS resolver gave no answer for the domain")
ErrDNS means the box's resolver gave no clear answer for the domain itself (time-out, server failure, or the DNS phase ran out of time before it): the scan stops, as for ErrCT, because a snapshot without the names would say they are gone.
var ErrNotPublic = errors.New("surface: the address is not a public address the box may scan")
ErrNotPublic means the target IP is not one the scan may probe.
var ErrTooLong = errors.New("surface: the scan did not finish in time")
ErrTooLong means the scan did not finish within scanTimeout; nothing of it is kept.
var ErrTooManyNames = errors.New("surface: the domain has more names than one scan reads")
ErrTooManyNames means the domain has more names in the CT logs than one scan reads (maxNames, or an answer over maxCTBody). The scan stops rather than keep a part: which part is kept would change from day to day, and the comparison of two days would show names, ports and pages as new or gone that never changed.
var Every = Names{Find: true}
Every is the scan of every name found under a domain.
Functions ¶
This section is empty.
Types ¶
type Addr ¶
Addr is one address of a name with its kind (ClassBox, ClassPublic or ClassPrivate). Contacted: the check by name (GET / on 80 and 443) went to this address, the name's first public IPv4.
type Admin ¶
Admin is an admin page that answered. Danger: close it now; otherwise restrict it by IP.
type Cert ¶
Cert is the certificate a TLS port showed. Host is the name (or IP) asked for, with ":port" unless the port is 443.
type Config ¶
type Config struct {
// Public says whether an address may be probed (exposure.IsPublicIPv4: no private, loopback, link-local, CGNAT, multicast,
// documentation or reserved address). A name that resolves to anything else is listed, never probed.
Public func(netip.Addr) bool
Probes ProbeLog
// Dial opens every connection to a target (the port scan, the pages, the TLS handshakes); nil: a net.Dialer. Tests pass an
// in-memory one.
Dial func(ctx context.Context, network, address string) (net.Conn, error)
Resolver Resolver // nil: net.DefaultResolver
CT *http.Client // the certificate-transparency search; nil: a client that verifies TLS and follows no redirect
Log *slog.Logger
}
Config is what New needs. Public, Probes and Log are required.
type Host ¶
Host is a name under the domain (exposure INV-27): where it was found, its final CNAME, its addresses with their kind, and IP, the first of its IPv4 addresses (zero when it has none: an IPv6-only name, or a CNAME that leads nowhere).
type Names ¶
type Names struct {
// Scans says the scan probes a name (nil: every name found); the domain itself always. A name it refuses is listed in Skipped,
// never resolved nor probed, and does not count against maxNames.
Scans func(name string) bool
// Find: look for names under the domain (certificate logs, MX and NS, common names). Without it, only the domain and Chosen.
Find bool
// Choose: the scope is the names chosen. With too many names under the domain to list them, the scan falls back to Chosen
// (Result.NamesCut) instead of refusing.
Choose bool
// Chosen are names under the domain looked up and probed whether or not they are found this time (the names chosen).
Chosen []string
}
Names is which names under a domain one scan reaches: the scope of the target and the names its child targets scan themselves.
type Port ¶
type Port struct {
IP netip.Addr
Port int
Service string
Product string
Title string
Server string
Location string
CertNames []string
HTTP bool // the page request got an HTTP answer, even one with no title, header or redirect
}
Port is an open TCP port. Product is what its page names (a fingerprint, else the Server header), or empty. Title, Server and Location are what the page request read on it (the page's title, the Server header, where it redirects without the query), and CertNames the names of the certificate it showed: all empty on a port that gave no page, so a port with any of them answered HTTP.
type Probe ¶
type Probe struct {
ID string // unique, set by the scanner
Addr netip.Addr // where it went
Label string // the name asked for, or the IP
Kind string // "tcp", "http", "https", "tls", or "dns" (one row a domain scan for its lookups; Addr is then not set)
Request string // what was sent: "TCP connect to 99 ports", "GET https://www.acme.example/"; after, the open ports too
Answered bool // false until something answered
}
Probe is one line of the probe log (LEGAL §3: target, time, what was sent), kept 90 days by the scan module (scan INV-7).
type ProbeLog ¶
ProbeLog keeps the probe log. Record is called with the probes before they go out (Answered false) and again with the same IDs after; an error before stops the scan, so nothing is probed that is not logged.
type Resolver ¶
type Resolver interface {
LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, 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)
}
Resolver looks up addresses, CNAME, MX and NS records through the box's own resolver; *net.Resolver satisfies it. Tests pass a fake: no test sends a DNS query.
type Result ¶
type Result struct {
Hosts []Host
Skipped []Host
NamesCut bool
Ports []Port
Admin []Admin
Certs []Cert
Wordlist string
Unresolved []string
}
Result is what one scan found. Wordlist: why a domain scan did not try every common name (WordlistWildcard, WordlistNoAnswer, WordlistCut), "" when it did. Unresolved: names whose address lookup gave no clear answer, sorted; they are not in Hosts, and exposure carries their earlier rows forward (INV-22, INV-27). Skipped: the names found that the scan was told not to reach (another target scans them, or the scope leaves them out), with their source only. NamesCut: the scope is the names chosen and the domain has more names than one scan lists, so only the chosen ones were looked up.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner runs scans. It holds no state between them.
func (*Scanner) Domain ¶
func (s *Scanner) Domain(ctx context.Context, domain string, names Names, mayScanPorts func(context.Context, netip.Addr) bool) (Result, error)
Domain scans a verified domain: its names from certificate transparency, the apex's MX and NS hosts under it and the common names that resolve (discover), each with its addresses, CNAME and class, listed; HTTP checks by name on 80 and 443 for the names on a public IPv4 address; a port scan only of the addresses that mayScanPorts accepts (exposure: a verified IP target that may be scanned now), which are also the ones of kind "box". One probe-log row of kind "dns" is written before the lookups. names is which names it reaches (Names): the others are listed in Skipped with no lookup, no check by name and no port scan through them. ErrCT when the search gives no answer, ErrTooManyNames when the domain has more names to scan than one scan reads, ErrTooLong past the time cap.