Skip to content

Commit 73aeca2

Browse files
committed
Empty TUI wordlist scans with the bundled list (#288)
The TUI form pre-filled examples/sample_wordlist.txt and rejected an empty field, so a binary run outside a checkout failed on ctrl+r with "cannot read wordlist: open examples/sample_wordlist.txt", and the bundled top-5000 list the command line falls back to was unreachable from the TUI. The Wordlist field is now optional: validate no longer rejects an empty value, and loadWordlist reads the bundled list through the same Preparer/EachLine path prepareWordlist uses for a missing -w. beginScan adds the CLI's notice, so the scan view names the list that ran. The field loses its repo-relative default and its required marker, with a placeholder that says what empty means. Tests: TestEmptyWordlistUsesBundledList starts a scan from an empty field and checks the loaded entries and the notice (it fails before the fix with the issue's "Wordlist path is required"); TestNewFormModelDefaults and TestFormViewRows pin the empty default. go test ./... passes, gofmt clean. Refs #288
1 parent d0c56f0 commit 73aeca2

6 files changed

Lines changed: 69 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4949
- Tests no longer flake under load: lab end-to-end runs use a 5 s timeout with 3 attempts and fail with a clear message if the lab 2 wildcard probe times out, the resolver-pool spread test counts lookups per member instead of timing the scan (the timing view is now `BenchmarkPoolSpreadsLoad`), and CI runs tests in shuffled order (#167).
5050

5151
### Fixed
52+
- The TUI no longer requires a wordlist file: an empty **Wordlist** field scans with the bundled top-5000 list, as a missing `-w` does on the command line, and the scan view says which list ran. The field no longer pre-fills `examples/sample_wordlist.txt`, which only exists inside a checkout, so `subenum -tui` from an installed binary works on the first run (#288).
5253
- On Windows, `-o NUL`, `-stats NUL` and `-sarif NUL` no longer fail with "Incorrect function" and exit 1: device and pipe targets are opened without truncation (#208, thanks @bfs2021).
5354
- An unreadable `-seeds` file no longer leaves a hidden `.<name>.tmp` file beside the `-o` path (kept locked on Windows until exit): seeds are read before the output file is opened (#212).
5455
- On Windows, `-simulate-zone` labs and the test DNS server no longer fail to start about a quarter of the time with "no free UDP+TCP port pair": after a failed TCP bind the server retries on random ports instead of the next OS-assigned one, which stayed inside the same reserved port block (#204).

‎README.md‎

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

594594
<img src="docs/assets/tui-form.png" alt="subenum interactive TUI" width="640"/>
595595

596-
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. 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`.
596+
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`.
597597

598598
### Go library
599599

‎internal/tui/form.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type formField struct {
8080
var formFields = [fieldCount]formField{
8181
fieldDomain: {label: "Domain*", kind: textField, placeholder: "e.g. example.com",
8282
saved: func(c *savedConfig) any { return &c.Domain }},
83-
fieldWordlist: {label: "Wordlist*", flag: "w", kind: textField, placeholder: "e.g. examples/sample_wordlist.txt", def: "examples/sample_wordlist.txt",
83+
fieldWordlist: {label: "Wordlist", flag: "w", kind: textField, placeholder: "empty = bundled top-5000 list",
8484
saved: func(c *savedConfig) any { return &c.Wordlist }},
8585
fieldSimulate: {label: "Simulate", flag: "simulate", kind: toggleField,
8686
saved: func(c *savedConfig) any { return &c.Simulate }},
@@ -388,10 +388,9 @@ func (m *formModel) validate() (formValues, string) {
388388
if err != nil {
389389
return formValues{}, err.Error()
390390
}
391+
// An empty Wordlist field scans with the bundled list, the way a missing
392+
// -w does on the command line (#288).
391393
wl := expandHome(strings.TrimSpace(text(fieldWordlist)))
392-
if wl == "" {
393-
return formValues{}, "Wordlist path is required"
394-
}
395394
// The TUI owns stdin, so reading a wordlist from it would block forever (#55).
396395
if wl == wordlist.Stdin {
397396
return formValues{}, "Wordlist from standard input (-) is not supported in the TUI; enter a file path"

‎internal/tui/form_test.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ func TestNewFormModelDefaults(t *testing.T) {
1717
if m.focus != fieldDomain {
1818
t.Errorf("expected initial focus on domain, got %d", m.focus)
1919
}
20-
if got := m.inputs[fieldWordlist].Value(); got != "examples/sample_wordlist.txt" {
20+
// No repo-relative default: an empty field means the bundled list, so a
21+
// binary run outside a checkout works on the first try (#288).
22+
if got := m.inputs[fieldWordlist].Value(); got != "" {
2123
t.Errorf("default wordlist = %q", got)
2224
}
2325
if got := m.inputs[fieldConcurrency].Value(); got != "100" {
@@ -328,7 +330,7 @@ func TestFormViewRows(t *testing.T) {
328330
}
329331
want := []string{
330332
"▸ Domain*: > e.g. example.com",
331-
" Wordlist*: > examples/sample_wordlist.txt",
333+
" Wordlist: > empty = bundled top-5000 list",
332334
" Simulate: OFF",
333335
" Hit Rate (%): (enable Simulate)",
334336
" DNS Server: > 8.8.8.8:53",

‎internal/tui/model.go‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
"errors"
77
"fmt"
88
"math/rand/v2"
9+
"strings"
910
"time"
1011

1112
tea "charm.land/bubbletea/v2"
1213

14+
"github.com/TMHSDigital/subenum/data"
1315
"github.com/TMHSDigital/subenum/internal/dns"
1416
"github.com/TMHSDigital/subenum/internal/output"
1517
"github.com/TMHSDigital/subenum/internal/report"
@@ -169,12 +171,27 @@ func (m Model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
169171
// pool, in a tea.Cmd goroutine.
170172
func loadWordlistCmd(vals formValues) tea.Cmd {
171173
return func() tea.Msg {
172-
entries, _, skipped, err := wordlist.LoadWordlist(vals.wordlist, vals.domain)
174+
entries, skipped, err := loadWordlist(vals)
173175
pool, poolErr := loadPool(vals)
174176
return wordlistLoadedMsg{cfg: vals, entries: entries, skipped: skipped, err: err, pool: pool, poolErr: poolErr}
175177
}
176178
}
177179

180+
// loadWordlist reads the file named on the form, or the bundled list when the
181+
// field is empty, the way the CLI treats a missing -w (#288).
182+
func loadWordlist(vals formValues) (entries []string, skipped int, err error) {
183+
if vals.wordlist != "" {
184+
entries, _, skipped, err = wordlist.LoadWordlist(vals.wordlist, vals.domain)
185+
return entries, skipped, err
186+
}
187+
pr := wordlist.NewPreparer()
188+
if err := wordlist.EachLine(strings.NewReader(data.Subdomains5k), pr.Add); err != nil {
189+
return nil, 0, err
190+
}
191+
entries, _, skipped = pr.Prepared().For(vals.domain)
192+
return entries, skipped, nil
193+
}
194+
178195
// loadPool builds the resolver pool from the Resolver Pool file, as the CLI
179196
// does for -r (#195). It returns nil without a file, and in simulation mode,
180197
// which sends no DNS queries.
@@ -239,6 +256,11 @@ func (m Model) beginScan(vals formValues, entries []string, skipped int, pool *d
239256
m.scanView.addMessage(dimStyle.Render("Note: the resolver pool is ignored in simulation mode, which sends no DNS queries"))
240257
}
241258

259+
// Same notice as the CLI's, so the TUI user knows which list ran (#288).
260+
if vals.wordlist == "" {
261+
m.scanView.addMessage(dimStyle.Render("Note: empty wordlist field: using the bundled top-5000 list (SecLists)"))
262+
}
263+
242264
opts := vals.options(entries, seed)
243265
opts.Pool = pool
244266
if vals.maxDuration > 0 {

‎internal/tui/model_test.go‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,43 @@ func TestRunLoadsWordlistAsync(t *testing.T) {
260260
}
261261
}
262262

263+
// TestEmptyWordlistUsesBundledList covers #288: an installed binary has no
264+
// examples/sample_wordlist.txt beside it, so an empty Wordlist field must scan
265+
// with the bundled list, the way a missing -w does for the CLI.
266+
func TestEmptyWordlistUsesBundledList(t *testing.T) {
267+
redirectConfig(t) // beginScan saves the form values
268+
m := Model{state: stateForm, form: newFormModel(savedConfig{})}
269+
m.form.inputs[fieldDomain].SetValue("example.com")
270+
m.form.inputs[fieldWordlist].SetValue("")
271+
m.form.inputs[fieldOutput].SetValue("") // no output file
272+
m.form.toggles[fieldSimulate] = true // simulate: the started scan sends no DNS traffic
273+
274+
next, cmd := m.updateForm(keyCtrlR)
275+
nm := next.(Model)
276+
if nm.form.err != "" {
277+
t.Fatalf("form error: %s", nm.form.err)
278+
}
279+
if cmd == nil {
280+
t.Fatal("ctrl+r with an empty wordlist field did not start a load")
281+
}
282+
loaded, ok := cmd().(wordlistLoadedMsg)
283+
if !ok || loaded.err != nil {
284+
t.Fatalf("load result = %+v, want the bundled list", loaded)
285+
}
286+
if len(loaded.entries) < 1000 {
287+
t.Fatalf("loaded %d entries, want the bundled top-5000 list", len(loaded.entries))
288+
}
289+
started, _ := nm.updateForm(loaded)
290+
sm := started.(Model)
291+
defer sm.cancel()
292+
if sm.state != stateScan {
293+
t.Fatalf("state=%v after load, want the scan screen", sm.state)
294+
}
295+
if !strings.Contains(sm.scanView.View(), "bundled top-5000 list") {
296+
t.Error("scan view does not say which wordlist ran")
297+
}
298+
}
299+
263300
// TestPoolErrorStaysOnForm covers #195: a resolver pool file that cannot be
264301
// used is reported on the form instead of starting the scan.
265302
func TestPoolErrorStaysOnForm(t *testing.T) {

0 commit comments

Comments
 (0)