Skip to content

In-scope CNAME, MX and NS targets are never tested as candidates #432

Closed

Description

@TMHSDigital

Summary

Names that the target's own DNS answers point at (CNAME, MX and NS targets inside the target domain) are written out as record values but never tested as candidates. A name like lb-7.int.example.com, reached only through app.example.com CNAME lb-7.int.example.com, is missed unless a wordlist happens to contain it. Add an opt-in follow-up pass that tests those in-scope targets.

Where

  • internal/dns/resolver.go:23 (Record{Type, Value}): the values are kept on each result.
  • internal/candidates/candidates.go:17 (sources wordlist, axfr, permute): nothing records-derived.
  • internal/cli/permute.go:31 (mainPassNames) and internal/cli/permute.go:65 (runPermutationPass): the existing follow-up pass that a records pass could mirror.

Details

Outside internal/dns and internal/output, the only code that reads Record.Value is the MCP report (internal/cli/mcp_report.go:89, :175), which formats it for display. No scan, candidate or permute code feeds a record value back into the candidate list, so in-scope hostnames that the zone itself names are reported as data and then dropped.

Impact

Users scanning with -type A,AAAA,CNAME (or MX/NS) see in-scope hostnames in the output that were never checked themselves, so their own records, takeover hints and internal-address flags are missing. These names are often the ones no wordlist contains (load balancers, per-region hosts, mail relays).

Suggested fix

  • Add -follow-records (default off, like -permute). After the main pass, collect the CNAME, MX and NS values of found names. Keep the ones that are under the target and not ruled out by -exclude. Drop names that were already candidates or found.
  • Scan them as a guarded pass, the way runPermutationPass does (preflight, wildcard filtering, -rate, -max-queries, -max-duration), with a new records source in candidates so sources says where each name came from.
  • Make the pass repeat to a small fixed depth (or until it finds nothing new), because a followed name can itself point at another in-scope name.
  • Later, SPF include:/a:/mx: hostnames from TXT records and SRV targets (Add SRV record lookups and opt-in service-name discovery (-srv) #419) could feed the same pass.

Open question: should the pass run by default when the type list already contains CNAME? Starting opt-in keeps query counts unchanged for existing users.

Acceptance criteria

  • A lab or dnstest zone where x CNAME y.target and y is not in the wordlist: with the new flag, y is reported with source records; without the flag, output is unchanged.
  • Out-of-scope and -excluded targets are never queried.
  • The pass counts toward -max-queries/-max-duration, appears in -stats, and resumes correctly.

Getting started

  • Relevant files: internal/cli/permute.go, internal/candidates/candidates.go, internal/cli/session.go
  • How to run tests: go test ./...
  • Related docs: docs/cli.md, README "Finding more names"

Filed by repo-audit/feature-ideas at 090df0a. Severity: medium. Effort: M. audit-key: enhancement|internal/cli/permute.go|follow-record-targets

Activity

  1. added
    enhancement
    area: scan
    severity: medium
    on Nov 18, 2026
  2. TMHSDigital commented on Nov 19, 2026

    @TMHSDigital
    OwnerAuthor

    Fixed in 7ea4e94 with -follow-records, off by default. The open question resolved as opt-in, so query counts don't change for existing users.

    • Where it runs: in the scan engine instead of as a separate pass. When a name is found, its CNAME, MX and NS targets under the target that -exclude allows go to the dispatcher, the same way a found parent does under -recursive.
    • Queueing: the dispatcher queues each target once, unless the scan tests it anyway (a wordlist entry, or an entry under a parent queued for expansion). It hands targets out before the remaining candidates.
    • Depth: a found target's own records are followed in turn, so chains repeat until nothing new turns up. Targets are not expanded by -recursive.
    • Budgets: targets count against -max-queries and -max-duration, so they show in the totals, the verdict and skipped_by_cap. Out-of-target and excluded targets are never queried.
    • Output: results carry sources: ["records"], and -stats counts them per target as records_found. The -dry-run notes mention the flag.
    • Resume: a resumed scan queues the targets of the results it restored. Results keep their records whenever the flag is on.
    • Library: pkg/subenum has Config.FollowRecords.
    • Not done: SPF include: hosts and SRV targets. -follow-records is now the place they could plug in.

    Verified with go test ./..., -race on internal/scan, and golangci-lint v2.15.0. Tests cover target extraction (MX preference, scope, exclusions, dedupe), the dispatcher's queueing (candidates skipped, recursion not repeating a followed name, budget counting), an engine run following a CNAME chain against a local DNS server, and a CLI run with the records source, records_found and an excluded MX target never asked. They also check that output without the flag is unchanged, and a resume that finds the target of a restored result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: scanenhancementseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions