Skip to content

Commit 1281a45

Browse files
TMHSDigitalclaude
andcommitted
fix: normalize target domains identically in every entry point
Adds validate.NormalizeDomain, used by the positional domain, -dL and the TUI form: trim, lowercase, drop the trailing dot, strip a URL scheme/path, :port or leading *. with a note, convert IDNs to punycode (golang.org/x/net/idna, pinned to v0.50.0 to keep go 1.24.2), and allow underscores like wordlist entries do. Fixes #54 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 843a8c0 commit 1281a45

9 files changed

Lines changed: 173 additions & 15 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- The preflight lookup of the target domain is retried up to `-attempts`, so one dropped packet no longer aborts the scan (#57).
1717
- `-max-queries` now stops memory growth in recursive mode: once the cap is reached, remaining and future candidates are counted as skipped without being built or recorded (#51).
1818
- No default command sends DNS traffic at a domain you did not name. `docker compose up`, `make simulate*` and `examples/demo.sh` run in simulation mode; `make run`, `run-verbose`, `run-custom` and `docker-run` require `DOMAIN=` and stop with a message without it; `demo.sh -l <domain>` opts into a live run. `demo.sh` now uses `set -euo pipefail`, `docker-run` uses `$(CURDIR)` so it works under Windows make, and `.PHONY` lists every target (#81).
19+
- Target domains are normalized the same way in the positional argument, `-dL` and the TUI: trimmed, lowercased, trailing dot dropped, so `Example.COM.` no longer yields `api.Example.COM.`. A pasted URL, path, `:port` or leading `*.` is stripped with a one-line note, IDNs such as `bücher.de` are converted to punycode, underscores are accepted as in wordlist entries, and an email address gets a targeted hint instead of `invalid domain format` (#54).
1920
- Release binaries are built with `CGO_ENABLED=0 -trimpath -s -w`, so `subenum-linux-amd64` is statically linked again and CI fails if a Linux asset is not (#46).
2021

2122
## [0.8.0] - 2026-10-04

‎go.mod‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/charmbracelet/bubbles v1.0.0
77
github.com/charmbracelet/bubbletea v1.3.10
88
github.com/charmbracelet/lipgloss v1.1.0
9+
golang.org/x/net v0.50.0
910
)
1011

1112
require (
@@ -29,6 +30,6 @@ require (
2930
github.com/muesli/termenv v0.16.0 // indirect
3031
github.com/rivo/uniseg v0.4.7 // indirect
3132
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
32-
golang.org/x/sys v0.38.0 // indirect
33-
golang.org/x/text v0.3.8 // indirect
33+
golang.org/x/sys v0.41.0 // indirect
34+
golang.org/x/text v0.34.0 // indirect
3435
)

‎go.sum‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
4646
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
4747
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
4848
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
49+
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
50+
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
4951
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5052
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
51-
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
52-
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
53-
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
54-
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
53+
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
54+
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
55+
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
56+
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=

‎internal/tui/form.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,14 @@ func expandHome(path string) string {
351351

352352
// validate checks all inputs and returns a scan config or an error string.
353353
func (m *formModel) validate() (formValues, string) {
354-
domain := strings.TrimSpace(m.inputs[0].Value())
355-
if domain == "" {
354+
rawDomain := strings.TrimSpace(m.inputs[0].Value())
355+
if rawDomain == "" {
356356
return formValues{}, "Domain is required"
357357
}
358-
if err := validate.Domain(domain); err != nil {
358+
// Same normalization as the CLI, so a pasted URL or Example.COM. scans
359+
// (and saves) the same canonical domain (#54).
360+
domain, _, err := validate.NormalizeDomain(rawDomain)
361+
if err != nil {
359362
return formValues{}, err.Error()
360363
}
361364
wl := expandHome(strings.TrimSpace(m.inputs[1].Value()))

‎internal/tui/form_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,19 @@ func TestValidateMaxQueriesAndNoAbort(t *testing.T) {
162162
t.Errorf("focus after Force = %d, want No Abort toggle", m.focus)
163163
}
164164
}
165+
166+
// TestValidateNormalizesDomain covers #54 for the TUI: a pasted URL or mixed
167+
// case domain scans the same canonical name as the CLI.
168+
func TestValidateNormalizesDomain(t *testing.T) {
169+
for _, in := range []string{"https://Example.COM/", "Example.COM.", "example.com"} {
170+
m := newFormModel(savedConfig{})
171+
m.inputs[0].SetValue(in)
172+
vals, errStr := m.validate()
173+
if errStr != "" {
174+
t.Fatalf("%q: unexpected error %q", in, errStr)
175+
}
176+
if vals.domain != "example.com" {
177+
t.Errorf("%q: domain = %q, want example.com", in, vals.domain)
178+
}
179+
}
180+
}

‎internal/validate/validate.go‎

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ package validate
55
import (
66
"fmt"
77
"net"
8+
"net/url"
89
"regexp"
910
"strconv"
1011
"strings"
12+
13+
"golang.org/x/net/idna"
1114
)
1215

1316
// exampleDNSServer is shown in the DNS server format error message.
1417
const exampleDNSServer = "8.8.8.8:53"
1518

1619
var (
17-
labelRegex = regexp.MustCompile(`^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`)
20+
labelRegex = regexp.MustCompile(`^[a-zA-Z0-9_]([a-zA-Z0-9_-]{0,61}[a-zA-Z0-9_])?$`)
1821
tldRegex = regexp.MustCompile(`^([a-zA-Z]{2,}|xn--[a-zA-Z0-9-]{1,59})$`)
1922
)
2023

@@ -35,9 +38,65 @@ func DNSServer(server string) error {
3538
return nil
3639
}
3740

41+
// NormalizeDomain turns a target as users type or paste it into the canonical
42+
// form every entry point scans: trimmed, lowercase, no trailing dot, IDNs in
43+
// punycode. It also strips a URL scheme and path, a :port and a leading "*.",
44+
// returning a one-line note for each so the caller can say what it did (#54).
45+
// The result is checked with Domain.
46+
func NormalizeDomain(input string) (domain string, notes []string, err error) {
47+
s := strings.TrimSpace(input)
48+
if strings.Contains(s, "@") {
49+
return "", nil, fmt.Errorf("%q looks like an email address; pass just the domain", input)
50+
}
51+
if i := strings.Index(s, "://"); i >= 0 {
52+
u, perr := url.Parse(s)
53+
if perr != nil || u.Hostname() == "" {
54+
return "", nil, fmt.Errorf("%q looks like a URL but has no host; pass just the domain", input)
55+
}
56+
s = u.Hostname()
57+
notes = append(notes, fmt.Sprintf("%q looks like a URL; scanning host %s", input, s))
58+
} else if i := strings.IndexAny(s, "/?#"); i >= 0 {
59+
s = s[:i]
60+
notes = append(notes, fmt.Sprintf("ignoring the path in %q; scanning host %s", input, s))
61+
}
62+
if host, port, serr := net.SplitHostPort(s); serr == nil {
63+
if _, perr := strconv.Atoi(port); perr == nil {
64+
s = host
65+
notes = append(notes, fmt.Sprintf("ignoring port %s; DNS enumeration has no ports", port))
66+
}
67+
}
68+
if strings.HasPrefix(s, "*.") {
69+
s = s[2:]
70+
notes = append(notes, fmt.Sprintf("ignoring the leading *. wildcard; scanning %s", s))
71+
}
72+
s = strings.ToLower(strings.TrimSuffix(s, "."))
73+
if !isASCII(s) {
74+
ascii, ierr := idna.Lookup.ToASCII(s)
75+
if ierr != nil {
76+
return "", nil, fmt.Errorf("invalid internationalized domain %q: %v", input, ierr)
77+
}
78+
notes = append(notes, fmt.Sprintf("using the punycode form %s for %s", ascii, s))
79+
s = ascii
80+
}
81+
if err := Domain(s); err != nil {
82+
return "", nil, err
83+
}
84+
return s, notes, nil
85+
}
86+
87+
func isASCII(s string) bool {
88+
for i := 0; i < len(s); i++ {
89+
if s[i] >= 0x80 {
90+
return false
91+
}
92+
}
93+
return true
94+
}
95+
3896
// Domain checks that domain is non-empty, within the 253-character limit, and
3997
// conforms to DNS naming rules: 1-63 characters per label, and a TLD that is
40-
// either alphabetic (2+) or a punycode xn-- prefix.
98+
// either alphabetic (2+) or a punycode xn-- prefix. Labels other than the TLD
99+
// may contain underscores (_dmarc, _domainkey), as wordlist entries can.
41100
func Domain(domain string) error {
42101
if len(domain) == 0 {
43102
return fmt.Errorf("domain cannot be empty")

‎internal/validate/validate_test.go‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,47 @@ func TestDomain(t *testing.T) {
8888
})
8989
}
9090
}
91+
92+
// TestNormalizeDomain covers #54: every common way of writing a target
93+
// normalizes to the same canonical domain.
94+
func TestNormalizeDomain(t *testing.T) {
95+
tests := []struct {
96+
in, want string
97+
notes int
98+
wantErr string
99+
}{
100+
{in: "example.com", want: "example.com"},
101+
{in: " Example.COM. ", want: "example.com"},
102+
{in: "https://example.com/", want: "example.com", notes: 1},
103+
{in: "HTTPS://Example.com:8443/login?x=1", want: "example.com", notes: 1},
104+
{in: "example.com/path", want: "example.com", notes: 1},
105+
{in: "example.com:443", want: "example.com", notes: 1},
106+
{in: "*.example.com", want: "example.com", notes: 1},
107+
{in: "bücher.de", want: "xn--bcher-kva.de", notes: 1},
108+
{in: "_dmarc.example.com", want: "_dmarc.example.com"},
109+
{in: "user@example.com", wantErr: "email address"},
110+
{in: "https:///nohost", wantErr: "no host"},
111+
{in: "localhost", wantErr: "invalid domain format"},
112+
{in: "", wantErr: "empty"},
113+
}
114+
for _, tt := range tests {
115+
t.Run(tt.in, func(t *testing.T) {
116+
got, notes, err := NormalizeDomain(tt.in)
117+
if tt.wantErr != "" {
118+
if err == nil || !strings.Contains(err.Error(), tt.wantErr) {
119+
t.Fatalf("err = %v, want it to mention %q", err, tt.wantErr)
120+
}
121+
return
122+
}
123+
if err != nil {
124+
t.Fatalf("unexpected error: %v", err)
125+
}
126+
if got != tt.want {
127+
t.Errorf("got %q, want %q", got, tt.want)
128+
}
129+
if len(notes) != tt.notes {
130+
t.Errorf("notes = %q, want %d", notes, tt.notes)
131+
}
132+
})
133+
}
134+
}

‎main.go‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,14 @@ func validateFlags(f cliFlags, positionals []string, fs *flag.FlagSet, out *outp
250250
if f.domainList != "" {
251251
return "", true // targets come from loadTargets
252252
}
253-
domain := positionals[0]
254-
if err := validate.Domain(domain); err != nil {
253+
domain, notes, err := validate.NormalizeDomain(positionals[0])
254+
if err != nil {
255255
out.Error("%v", err)
256256
return "", false
257257
}
258+
for _, n := range notes {
259+
out.Info("Note: %s", n)
260+
}
258261
return domain, true
259262
}
260263

@@ -276,11 +279,14 @@ func loadTargets(f cliFlags, domain string, out *output.Writer) ([]string, bool)
276279
if wordlist.IsComment(line) {
277280
continue
278281
}
279-
d := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(line), "."))
280-
if err := validate.Domain(d); err != nil {
282+
d, notes, err := validate.NormalizeDomain(line)
283+
if err != nil {
281284
out.Info("Skipping invalid domain %q in %s: %v", strings.TrimSpace(line), f.domainList, err)
282285
continue
283286
}
287+
for _, n := range notes {
288+
out.Info("Note: %s", n)
289+
}
284290
if !seen[d] {
285291
seen[d] = true
286292
targets = append(targets, d)

‎main_e2e_test.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,29 @@ func TestE2EMergedStreamsHaveNoCarriageReturns(t *testing.T) {
256256
})
257257
}
258258
}
259+
260+
// TestE2EDomainFormsGiveIdenticalOutput covers #54: the same target written
261+
// as Example.COM., example.com, a URL, or via -dL scans identically.
262+
func TestE2EDomainFormsGiveIdenticalOutput(t *testing.T) {
263+
wl := writeFile(t, "wl.txt", e2eWords)
264+
common := []string{"-simulate", "-seed", "7", "-hit-rate", "100", "-progress=false", "-w", wl}
265+
scan := func(args ...string) string {
266+
code, out := runCLI(t, "", append(append([]string{}, common...), args...)...)
267+
if code != 0 {
268+
t.Fatalf("%v: exit %d", args, code)
269+
}
270+
lines := strings.Fields(out)
271+
sort.Strings(lines)
272+
return strings.Join(lines, "\n")
273+
}
274+
want := scan("example.com")
275+
if !strings.Contains(want, "www.example.com") {
276+
t.Fatalf("baseline output missing www.example.com:\n%s", want)
277+
}
278+
dl := writeFile(t, "domains.txt", "Example.COM.\n")
279+
for _, args := range [][]string{{"Example.COM."}, {"https://example.com/"}, {"-dL", dl}} {
280+
if got := scan(args...); got != want {
281+
t.Errorf("%v output differs:\n%s\nwant:\n%s", args, got, want)
282+
}
283+
}
284+
}

0 commit comments

Comments
 (0)