Skip to content

Commit efc5920

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 496df99 commit efc5920

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
@@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4848
- 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).
4949

5050
### Fixed
51+
- 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).
5152
- 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).
5253
- 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).
5354
- 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
@@ -591,7 +591,7 @@ jq -e '.verdict == "complete"' run.json > /dev/null || { jq -r .reason run.json;
591591

592592
No flags required. Fill in the form and press `ctrl+r` to start scanning. Last-used values are saved to `last.json` in your user config directory (`~/.config/subenum/` on Linux, `~/Library/Application Support/subenum/` on macOS, `%AppData%\subenum\` on Windows) and restored on next launch. The interface is shown at the top of this README.
593593

594-
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.
594+
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.
595595

596596
### Go library
597597

‎internal/tui/form.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type formField struct {
7676
var formFields = [fieldCount]formField{
7777
fieldDomain: {label: "Domain*", kind: textField, placeholder: "e.g. example.com",
7878
saved: func(c *savedConfig) any { return &c.Domain }},
79-
fieldWordlist: {label: "Wordlist*", flag: "w", kind: textField, placeholder: "e.g. examples/sample_wordlist.txt", def: "examples/sample_wordlist.txt",
79+
fieldWordlist: {label: "Wordlist", flag: "w", kind: textField, placeholder: "empty = bundled top-5000 list",
8080
saved: func(c *savedConfig) any { return &c.Wordlist }},
8181
fieldSimulate: {label: "Simulate", flag: "simulate", kind: toggleField,
8282
saved: func(c *savedConfig) any { return &c.Simulate }},
@@ -376,10 +376,9 @@ func (m *formModel) validate() (formValues, string) {
376376
if err != nil {
377377
return formValues{}, err.Error()
378378
}
379+
// An empty Wordlist field scans with the bundled list, the way a missing
380+
// -w does on the command line (#288).
379381
wl := expandHome(strings.TrimSpace(text(fieldWordlist)))
380-
if wl == "" {
381-
return formValues{}, "Wordlist path is required"
382-
}
383382
// The TUI owns stdin, so reading a wordlist from it would block forever (#55).
384383
if wl == wordlist.Stdin {
385384
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" {
@@ -290,7 +292,7 @@ func TestFormViewRows(t *testing.T) {
290292
}
291293
want := []string{
292294
"▸ Domain*: > e.g. example.com",
293-
" Wordlist*: > examples/sample_wordlist.txt",
295+
" Wordlist: > empty = bundled top-5000 list",
294296
" Simulate: OFF",
295297
" Hit Rate (%): (enable Simulate)",
296298
" 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
@@ -5,10 +5,12 @@ import (
55
"context"
66
"fmt"
77
"math/rand/v2"
8+
"strings"
89
"time"
910

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

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

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

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

‎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)