Skip to content

Commit 1d49463

Browse files
authored
fix(cli): reject lab zones before starting the TUI (#382)
1 parent 2f372fa commit 1d49463

5 files changed

Lines changed: 48 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ No flags required. Fill in the form and press `ctrl+r` to start scanning. Last-u
631631

632632
<br>
633633

634-
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.
634+
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.
635635

636636
</details>
637637

‎docs/labs.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ L=examples/labs
3232
W="-w $L/words.txt"
3333
```
3434

35+
Labs run from the command line. Combining `-tui` with an active `-simulate-zone`
36+
setting (including `SUBENUM_SIMULATE_ZONE` or a config-file value) exits with
37+
usage error 2 before the interface opens. Remove `-tui` to run the lab.
38+
3539
Each lab ends with questions. The answers are folded underneath; try first.
3640

3741
## Lab 1: a first scan

‎internal/cli/config_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ func TestPrintConfigEffectiveAttempts(t *testing.T) {
308308
// tuiOmittedFlags are flags the TUI form deliberately has no field for: they
309309
// control CLI-only output, input sources, run state or modes the form does not
310310
// offer, so a command-line, SUBENUM_* or config file value for them never
311-
// seeds the form (-tui warns about one given on the command line). The one
312-
// exception is -ct, which tuiOptions turns into ct in the Sources field (#348).
311+
// seeds the form (-tui warns about one given on the command line). Lab zones
312+
// are rejected before the form opens; -ct becomes ct in Sources (#348).
313313
var tuiOmittedFlags = map[string]bool{
314314
"tui": true, "print-config": true, "dry-run": true, "version": true, "v": true, "progress": true, "silent": true,
315315
"simulate-zone": true, "retries": true, "show-records": true, "stats": true,

‎internal/cli/lab_test.go‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,42 @@ func TestE2ELabFlagConflicts(t *testing.T) {
392392
}
393393
}
394394

395+
// A lab request must be rejected before the TUI can discard it (#356).
396+
func TestE2ETUIRefusesLab(t *testing.T) {
397+
zone := filepath.Join("examples", "labs", "lab1-first-scan.zone")
398+
cfg := writeFile(t, "config.json", `{"simulate-zone": "`+filepath.ToSlash(zone)+`"}`)
399+
for _, tc := range []struct {
400+
name, env, value, want string
401+
args []string
402+
}{
403+
{name: "flags", want: "-simulate-zone", args: []string{"-tui", "-simulate-zone", zone, "lab.example"}},
404+
{name: "interspersed", want: "-simulate-zone", args: []string{"-simulate-zone", zone, "lab.example", "--tui"}},
405+
{name: "no domain", want: "-simulate-zone", args: []string{"-tui", "-simulate-zone", zone}},
406+
{name: "environment", env: "SUBENUM_SIMULATE_ZONE", value: zone, want: "SUBENUM_SIMULATE_ZONE", args: []string{"-tui", "lab.example"}},
407+
{name: "config", env: configEnv, value: cfg, want: "config file", args: []string{"-tui", "lab.example"}},
408+
{name: "json", want: "-simulate-zone", args: []string{"-tui", "-simulate-zone", zone, "-log-format", "json", "lab.example"}},
409+
} {
410+
t.Run(tc.name, func(t *testing.T) {
411+
if tc.env != "" {
412+
t.Setenv(tc.env, tc.value)
413+
}
414+
code, stdout, stderr := runCLIStreams(t, tc.args...)
415+
if code != exitUsage || stdout != "" {
416+
t.Errorf("exit %d, stdout %q; want exit %d and no scan output", code, stdout, exitUsage)
417+
}
418+
if !strings.Contains(stderr, "-tui") || !strings.Contains(stderr, tc.want) || !strings.Contains(stderr, "run the lab without -tui") {
419+
t.Errorf("missing lab/TUI conflict diagnostic naming %q: %s", tc.want, stderr)
420+
}
421+
if tc.name == "json" {
422+
lines := parseLogLines(t, stderr)
423+
if len(lines) != 1 || lines[0].Level != "error" {
424+
t.Errorf("diagnostics = %+v, want one JSON error", lines)
425+
}
426+
}
427+
})
428+
}
429+
}
430+
395431
// TestE2ELabRefusesEnvAndConfigResolvers covers #106: a resolver list or
396432
// simulation mode from SUBENUM_* or the config file must not turn a lab run
397433
// into one that sends queries off the machine.

‎internal/cli/session.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ func (s *session) parse() (code int, done bool) {
195195
// -tui counts only as a real flag, not as the value of another flag
196196
// (-o -tui) or an argument after "--" (#58).
197197
if f.tui {
198+
// The form cannot represent lab zones; never discard a lab request.
199+
if f.simZone != "" {
200+
diag.Error("-tui cannot be combined with %s; run the lab without -tui", defaults.describe(fs, "simulate-zone"))
201+
return exitUsage, true
202+
}
198203
return tui.Start(tuiOptions(f, fs, positionals, defaults, diag)), true
199204
}
200205

0 commit comments

Comments
 (0)