From 2d8918d80cd5e14c4106fd302d04bf1f0fcdd8b9 Mon Sep 17 00:00:00 2001 From: Asahi Arataki Date: Mon, 16 Nov 2026 12:10:40 +0800 Subject: [PATCH] fix(cli): reject lab zones before starting the TUI --- README.md | 2 +- docs/labs.md | 4 ++++ internal/cli/config_test.go | 4 ++-- internal/cli/lab_test.go | 36 ++++++++++++++++++++++++++++++++++++ internal/cli/session.go | 5 +++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c688000..3a889de 100644 --- a/README.md +++ b/README.md @@ -631,7 +631,7 @@ No flags required. Fill in the form and press `ctrl+r` to start scanning. Last-u
-Flags and a domain given with `-tui` fill the form, so a prepared command line opens ready to run: `./subenum -tui example.com -w big.txt -r resolvers.txt`. The form takes one wordlist (the first `-w`), and `-tui` warns about any flag it has no field for. **Wordlist is optional:** leave the field empty to scan with the bundled top-5000 list, as a missing `-w` does on the command line. The **Resolver Pool** and **Rate/Resolver** fields are `-r` and `-rate-per-resolver`; the pool is not used with Simulate on. **Auto Rate**, **Max Duration** (blank for none, or a duration such as `20m`) and **Retry Inconclusive** are `-auto-rate`, `-max-duration` and `-retry-inconclusive`. **Sources** takes what `-sources` does (`ct`, `wayback` or both; `-ct` fills in `ct`): the sources are asked while the wordlist loads, their names are scanned with the wordlist's, and a source that fails is a warning on the scan screen, not a failed scan; they are not asked with Simulate on. **Permute** is `-permute`: when the scan finishes, a second pass scans permutations of the names found, and its results are marked on the scan screen. With either field set, the results file says what proposed each name, as the CLI's does. +Flags and a domain given with `-tui` fill the form, so a prepared command line opens ready to run: `./subenum -tui example.com -w big.txt -r resolvers.txt`. The form takes one wordlist (the first `-w`), and `-tui` warns about flags it has no field for, except `-simulate-zone`: lab mode is rejected with exit 2 before the TUI opens. Run labs without `-tui`. **Wordlist is optional:** leave the field empty to scan with the bundled top-5000 list, as a missing `-w` does on the command line. The **Resolver Pool** and **Rate/Resolver** fields are `-r` and `-rate-per-resolver`; the pool is not used with Simulate on. **Auto Rate**, **Max Duration** (blank for none, or a duration such as `20m`) and **Retry Inconclusive** are `-auto-rate`, `-max-duration` and `-retry-inconclusive`. **Sources** takes what `-sources` does (`ct`, `wayback` or both; `-ct` fills in `ct`): the sources are asked while the wordlist loads, their names are scanned with the wordlist's, and a source that fails is a warning on the scan screen, not a failed scan; they are not asked with Simulate on. **Permute** is `-permute`: when the scan finishes, a second pass scans permutations of the names found, and its results are marked on the scan screen. With either field set, the results file says what proposed each name, as the CLI's does. diff --git a/docs/labs.md b/docs/labs.md index d1f6770..68a340c 100644 --- a/docs/labs.md +++ b/docs/labs.md @@ -32,6 +32,10 @@ L=examples/labs W="-w $L/words.txt" ``` +Labs run from the command line. Combining `-tui` with an active `-simulate-zone` +setting (including `SUBENUM_SIMULATE_ZONE` or a config-file value) exits with +usage error 2 before the interface opens. Remove `-tui` to run the lab. + Each lab ends with questions. The answers are folded underneath; try first. ## Lab 1: a first scan diff --git a/internal/cli/config_test.go b/internal/cli/config_test.go index 1e076cd..3661ca1 100644 --- a/internal/cli/config_test.go +++ b/internal/cli/config_test.go @@ -308,8 +308,8 @@ func TestPrintConfigEffectiveAttempts(t *testing.T) { // tuiOmittedFlags are flags the TUI form deliberately has no field for: they // control CLI-only output, input sources, run state or modes the form does not // offer, so a command-line, SUBENUM_* or config file value for them never -// seeds the form (-tui warns about one given on the command line). The one -// exception is -ct, which tuiOptions turns into ct in the Sources field (#348). +// seeds the form (-tui warns about one given on the command line). Lab zones +// are rejected before the form opens; -ct becomes ct in Sources (#348). var tuiOmittedFlags = map[string]bool{ "tui": true, "print-config": true, "dry-run": true, "version": true, "v": true, "progress": true, "silent": true, "simulate-zone": true, "retries": true, "show-records": true, "stats": true, diff --git a/internal/cli/lab_test.go b/internal/cli/lab_test.go index 83b897e..5036a36 100644 --- a/internal/cli/lab_test.go +++ b/internal/cli/lab_test.go @@ -377,6 +377,42 @@ func TestE2ELabFlagConflicts(t *testing.T) { } } +// A lab request must be rejected before the TUI can discard it (#356). +func TestE2ETUIRefusesLab(t *testing.T) { + zone := filepath.Join("examples", "labs", "lab1-first-scan.zone") + cfg := writeFile(t, "config.json", `{"simulate-zone": "`+filepath.ToSlash(zone)+`"}`) + for _, tc := range []struct { + name, env, value, want string + args []string + }{ + {name: "flags", want: "-simulate-zone", args: []string{"-tui", "-simulate-zone", zone, "lab.example"}}, + {name: "interspersed", want: "-simulate-zone", args: []string{"-simulate-zone", zone, "lab.example", "--tui"}}, + {name: "no domain", want: "-simulate-zone", args: []string{"-tui", "-simulate-zone", zone}}, + {name: "environment", env: "SUBENUM_SIMULATE_ZONE", value: zone, want: "SUBENUM_SIMULATE_ZONE", args: []string{"-tui", "lab.example"}}, + {name: "config", env: configEnv, value: cfg, want: "config file", args: []string{"-tui", "lab.example"}}, + {name: "json", want: "-simulate-zone", args: []string{"-tui", "-simulate-zone", zone, "-log-format", "json", "lab.example"}}, + } { + t.Run(tc.name, func(t *testing.T) { + if tc.env != "" { + t.Setenv(tc.env, tc.value) + } + code, stdout, stderr := runCLIStreams(t, tc.args...) + if code != exitUsage || stdout != "" { + t.Errorf("exit %d, stdout %q; want exit %d and no scan output", code, stdout, exitUsage) + } + if !strings.Contains(stderr, "-tui") || !strings.Contains(stderr, tc.want) || !strings.Contains(stderr, "run the lab without -tui") { + t.Errorf("missing lab/TUI conflict diagnostic naming %q: %s", tc.want, stderr) + } + if tc.name == "json" { + lines := parseLogLines(t, stderr) + if len(lines) != 1 || lines[0].Level != "error" { + t.Errorf("diagnostics = %+v, want one JSON error", lines) + } + } + }) + } +} + // TestE2ELabRefusesEnvAndConfigResolvers covers #106: a resolver list or // simulation mode from SUBENUM_* or the config file must not turn a lab run // into one that sends queries off the machine. diff --git a/internal/cli/session.go b/internal/cli/session.go index 0cb24c6..1a769c7 100644 --- a/internal/cli/session.go +++ b/internal/cli/session.go @@ -195,6 +195,11 @@ func (s *session) parse() (code int, done bool) { // -tui counts only as a real flag, not as the value of another flag // (-o -tui) or an argument after "--" (#58). if f.tui { + // The form cannot represent lab zones; never discard a lab request. + if f.simZone != "" { + diag.Error("-tui cannot be combined with %s; run the lab without -tui", defaults.describe(fs, "simulate-zone")) + return exitUsage, true + } return tui.Start(tuiOptions(f, fs, positionals, defaults, diag)), true }