Skip to content

reconFTW is a tool designed to perform automated recon on a target domain by running the best set of tools to perform scanning and finding out vulnerabilities

20.7 KB
Raw Blame

id: 01-02 phase: 01 plan: 02 type: execute wave: 2 depends_on: [01-01] requirements: [RESIL-02] files_modified:

  • modules/utils.sh
  • modules/core.sh autonomous: true must_haves: truths:
    • "D-09: When _check_disk_mid_run reports available_gb < MIN_DISK_SPACE_GB at any function boundary, the run aborts (hard abort, exit 1) with a clear error naming available and required GB and the target directory; soft-abort and pause-and-wait were rejected"
    • "D-08: The same MIN_DISK_SPACE_GB threshold used by the pre-flight check at modules/modes.sh:23 governs the mid-run check — single source of truth, no separate mid-run knob"
    • "D-07: Check cadence is at every start_func / end_func boundary — check_disk_mid_run is invoked at the TOP of start_func (before any state is written) and at the TAIL of end_func (after the . checkpoint and .status are durably written); ~1ms × ~100 boundaries per scan = negligible overhead; no background watcher"
    • "D-10: ENOSPC detection mechanism is boundary df only — no run_command stderr scanning for No space left on device, no per-redirect failure traps; mid-function truncation in a single tool is an accepted trade-off, boundary check catches it before further damage"
    • "D-09: On hard abort, the existing EXIT trap (registered in Plan 01-01 per D-02) clears all .inprogress_* sentinels so a subsequent run does NOT surface a fake resume condition"
    • "D-07: When _check_disk_mid_run aborts at start_func entry, no .inprogress_<fn> is written for the aborting function — the Plan 01-01 sentinel touch has not yet executed; the EXIT trap therefore has no orphan to clear for this specific function. Completed prior functions retain their .<fn> checkpoints"
    • "D-08: No new mid-run disk knob is introduced; reconftw.cfg:39 and modules/modes.sh:23 are NOT modified in this phase (DOCS-02 reconciliation is Phase 5)" artifacts:
    • path: "modules/utils.sh" provides: "_check_disk_mid_run thin wrapper around check_disk_space; _abort_disk_full emits structured error and exits 1"
    • path: "modules/core.sh" provides: "start_func and end_func call _check_disk_mid_run at the documented boundaries" key_links:
    • from: "modules/core.sh:start_func" to: "modules/utils.sh:_check_disk_mid_run" via: "guard pattern: _check_disk_mid_run || _abort_disk_full" pattern: "_check_disk_mid_run.\|\|._abort_disk_full"
    • from: "modules/utils.sh:_abort_disk_full" to: "exit 1" via: "after _print_error + log_json, exit 1 triggers EXIT trap from 01-01" pattern: "exit 1"
    • from: "modules/utils.sh:_check_disk_mid_run" to: "check_disk_space "${MIN_DISK_SPACE_GB:-5}" "${dir:-.}"" via: "reuses existing helper for df parsing; populates DISK_SPACE_INFO" pattern: "check_disk_space.*MIN_DISK_SPACE_GB"

Add boundary-only mid-run disk-full guard so a recon run aborts cleanly with `ENOSPC`-style error rather than producing zero-byte or truncated outputs when the working filesystem fills mid-scan. Closes RESIL-02.

Purpose: Today, check_disk_space() (modules/utils.sh:421) is only called once at the start of each recon mode (modules/modes.sh:23). If disk fills mid-run (e.g., during a 2GB gotator permutation write or a long DNS resolve), tools fail silently and downstream pipeline stages see corrupt partial outputs. This plan installs the same df-based check at every start_func/end_func boundary so the next function entry aborts the run before any further damage.

Output: New private helpers _check_disk_mid_run and _abort_disk_full in modules/utils.sh. start_func and end_func in modules/core.sh call them at the documented anchors (top-of-start, tail-of-end) so the check runs at boundary cadence with negligible overhead (~1ms per call × ~100 boundaries per scan).

@$HOME/.claude/get-shit-done/workflows/execute-plan.md @$HOME/.claude/get-shit-done/templates/summary.md @.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md @.planning/phases/01-resilient-resume-timeout-safety/01-PATTERNS.md @.planning/codebase/CONVENTIONS.md @.planning/phases/01-resilient-resume-timeout-safety/01-01-PLAN.md

From modules/utils.sh:

  • function check_disk_space() — :421-436. Signature: check_disk_space <required_gb> <path>. Behavior: parses df -Pk <path> to GB, returns 0 if available_gb >= required_gb else 1; populates global DISK_SPACE_INFO with either "Disk space LOW: required ${required_gb}GB, available ${available_gb}GB at ${check_path}" or "Disk space OK: ${available_gb}GB available at ${check_path}".
  • function cleanup_on_exit() — :116-146. NOT modified by Plan 01-01 (cleanup_on_exit remains bound to INT/TERM only). The new EXIT trap installed by Plan 01-01 invokes _cleanup_inprogress (a standalone helper), which fires on exit 1 from _abort_disk_full and clears .inprogress_* sentinels without printing any banner.

From modules/modes.sh:

  • start() pre-flight at :23-27: local required_space_gb="${MIN_DISK_SPACE_GB:-5}"; if ! check_disk_space "$required_space_gb" "."; then _print_status WARN "Low disk space detected" "Continuing anyway..."; fi. This is the SAME threshold the mid-run check must use (D-08 single source of truth).

From modules/core.sh:

  • function start_func() — :1419-1435. AFTER Plan 01-01 lands, the body order is: current_date=... → echo "[$current_date] Start function..." → local _fn_name="${1}" → printf -v "_start_time_..." → start=$(date +%s) → [Plan 01-01 inserts touch .inprogress here] → log_json "INFO" ... → ui_log_jsonl → if OUTPUT_VERBOSITY>=2: _print_msg INFO.
  • function end_func() — :1437-1531. AFTER Plan 01-01 lands, the body order is: status case-normalization → [Plan 01-01 inserts rm -f .inprogress here] → touch "$called_fn_dir/.${fn}" → timing → badge mapping → printf "%s\n" "$badge" >"${called_fn_dir}/.status_${fn}" → _print_status → log_json "SUCCESS" → (end of function).
  • function log_json() — :680.

From lib/common.sh:

  • _print_error() — :528. Always-visible stderr error.
Task 1: Define _check_disk_mid_run and _abort_disk_full in modules/utils.sh modules/utils.sh - modules/utils.sh (current check_disk_space at :421-436 — the analog whose df parsing is reused) - modules/utils.sh (current cleanup_on_exit at :116-146 — sibling style for new private helpers) - .planning/phases/01-resilient-resume-timeout-safety/01-PATTERNS.md (anchor "modules/utils.sh — check_disk_space sibling helpers" — placement and helper signatures) - .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md (D-07 cadence, D-08 single threshold, D-09 hard abort, D-10 boundary-only) - .planning/codebase/CONVENTIONS.md (Function Naming: underscore-prefix for private; Error Handling: _print_error always visible) Insert two new private helpers in modules/utils.sh IMMEDIATELY AFTER the existing `check_disk_space` closing brace at :436 and BEFORE the `progress_bar` block at :440. Both use `function name() { ... }` declaration style (CONVENTIONS.md §Function Naming).
Helper 1 — `_check_disk_mid_run`:
- Single-line doc comment above: `# Mid-run disk-full check: thin wrapper around check_disk_space using MIN_DISK_SPACE_GB (D-07/D-08).`
- Body: call `check_disk_space "${MIN_DISK_SPACE_GB:-5}" "${dir:-.}"` and `return $?`. The `:-5` fallback mirrors modes.sh:23 default (D-08 single source of truth). The `${dir:-.}` fallback handles invocations where `dir` is unset (e.g., test harness sourcing) by checking CWD.
- Returns 0 if disk OK, 1 if low. Populates `DISK_SPACE_INFO` as a side effect of check_disk_space.

Helper 2 — `_abort_disk_full`:
- Single-line doc comment above: `# Hard-abort the run on disk-full mid-run detection (D-09). EXIT trap (Plan 01-01) clears .inprogress_* on the way out.`
- Body:
  1. `_print_error "disk_full: aborting (${DISK_SPACE_INFO:-disk space exhausted})"` — uses the always-visible stderr helper from lib/common.sh:528. Includes the DISK_SPACE_INFO string already populated by _check_disk_mid_run for available/required context.
  2. `log_json "ERROR" "${FUNCNAME[1]:-main}" "Disk space exhausted" "reason=disk_full" "info=${DISK_SPACE_INFO:-unknown}"` — uses `FUNCNAME[1]` to log the CALLER's name (start_func or end_func), not _abort_disk_full itself. Reuses the log_json shape from modules/core.sh:1428/1525.
  3. `exit 1` — hard-aborts the entire process. The EXIT trap installed in Plan 01-01 (`trap '_cleanup_inprogress' EXIT`) fires automatically and clears all `.inprogress_*` files so a subsequent invocation does not see a fake resume condition (D-09 closing rationale). Returns nothing else after exit.

Do NOT introduce a new global. Do NOT add a separate "mid-run threshold" knob (D-08 single source of truth). Do NOT add `run_command` stderr scanning or per-redirect ENOSPC traps (D-10 boundary-only is locked). Do NOT call `exit 1` from `_check_disk_mid_run` — caller is responsible for chaining `_check_disk_mid_run || _abort_disk_full`.

Both helpers MUST be defined BEFORE the call sites in modules/core.sh are added (Task 2). The sourcing order in reconftw.sh loads `modules/utils.sh` before `modules/core.sh` (per CONVENTIONS.md §Import / Sourcing Order), so this ordering is naturally satisfied.
bash -n /Users/six2dez/Tools/reconftw/modules/utils.sh && shellcheck -s bash --severity=error /Users/six2dez/Tools/reconftw/modules/utils.sh - `grep -n '^function _check_disk_mid_run' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns exactly one match. - `grep -n '^function _abort_disk_full' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns exactly one match. - `grep -n 'check_disk_space "\${MIN_DISK_SPACE_GB:-5}"' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns at least one match (inside _check_disk_mid_run body). - `grep -n 'reason=disk_full' /Users/six2dez/Tools/reconftw/modules/utils.sh` returns at least one match (inside _abort_disk_full log_json call). - `grep -n '^[[:space:]]*exit 1' /Users/six2dez/Tools/reconftw/modules/utils.sh` shows at least one new occurrence inside `_abort_disk_full` (file may have other unrelated `exit 1` sites; the one inside _abort_disk_full must be present). - Both new helpers placed AFTER `check_disk_space` closing brace and BEFORE `progress_bar` (visual ordering): `grep -n 'check_disk_space\|_check_disk_mid_run\|_abort_disk_full\|progress_bar' modules/utils.sh | head` shows the order check_disk_space → _check_disk_mid_run → _abort_disk_full → progress_bar. - `bash -n modules/utils.sh` exits 0. - `shellcheck -s bash --severity=error modules/utils.sh` exits 0 (no new error-level findings). - Behavior smoke: source `--source-only`, set `MIN_DISK_SPACE_GB=99999999`, set `dir=/tmp`, call `_check_disk_mid_run; echo $?` — expect `1`. Set `MIN_DISK_SPACE_GB=0`, call `_check_disk_mid_run; echo $?` — expect `0`. `_abort_disk_full` cannot be tested without exiting the test shell; verify visually that body contains exit 1. Two private helpers added with correct placement, sibling-style declaration, single-threshold reuse of MIN_DISK_SPACE_GB, structured log emission via log_json, and hard-exit semantics in _abort_disk_full; shellcheck clean. Task 2: Call _check_disk_mid_run at start_func top + end_func tail modules/core.sh - modules/core.sh (current start_func :1419-1435 — AFTER Plan 01-01 lands, the .inprogress touch sits between :1425 and :1428) - modules/core.sh (current end_func :1437-1531 — AFTER Plan 01-01 lands, the .inprogress rm sits immediately BEFORE the . touch at :1465) - .planning/phases/01-resilient-resume-timeout-safety/01-PATTERNS.md (anchor "Insertion anchor (D-01 sentinel + D-07 disk check)" — exact placement) - .planning/phases/01-resilient-resume-timeout-safety/01-CONTEXT.md (D-07: "start_func calls it BEFORE the existing body; end_func calls it AFTER touching the checkpoint") In modules/core.sh start_func (at :1419, after Plan 01-01 lands): insert `_check_disk_mid_run || _abort_disk_full` as the VERY FIRST executable statement INSIDE the function body — that is, immediately AFTER the opening `{` and BEFORE the `local current_date` line at :1420. This placement ensures the disk-full abort fires before any LOGFILE write, any timestamp setup, any sentinel touch (the .inprogress touch added by 01-01 will run AFTER this guard).
In modules/core.sh end_func (at :1437, after Plan 01-01 lands): insert `_check_disk_mid_run || _abort_disk_full` as the VERY LAST executable statement of the function body — immediately AFTER the existing `log_json "SUCCESS" ...` call at :1525 (and after the `ui_log_jsonl` block at :1526-1528) and BEFORE the trailing `:` no-op at :1530 and the closing `}` at :1531. Per D-07 / PATTERNS.md "post-checkpoint disk check", this placement ensures the `.<fn>` checkpoint and `.status_<fn>` / `.status_reason_<fn>` files are durably written for the just-finished function BEFORE the abort can fire. A disk-full abort detected at end_func therefore still leaves a complete success record for the function that just finished.

Both call sites use the exact pattern `_check_disk_mid_run || _abort_disk_full` — short-circuit OR so _abort_disk_full only runs on non-zero return. No `if/then/fi` wrapper, no other transformations. No additional logging at the call sites (the helpers emit their own messages).

Do NOT call `_check_disk_mid_run` anywhere ELSE in this phase — boundary-only cadence is locked (D-10). Do NOT add `set -e` or any new shell options. Do NOT modify the order of the existing Plan 01-01 sentinel ops at start_func or end_func.

Note on context with Plan 01-01: after both plans land, start_func body order is (1) `_check_disk_mid_run || _abort_disk_full`, (2) all the existing pre-Plan-01-01 setup (`current_date`, LOGFILE write, _fn_name, printf -v start time, `start=`), (3) Plan 01-01 inserted `touch .inprogress`, (4) existing log_json INFO + ui_log_jsonl + verbose INFO print. end_func order is mostly unchanged with two insertions: (1) Plan 01-01 inserted `rm -f .inprogress` before the existing `touch .<fn>`, (2) Plan 01-02 inserted `_check_disk_mid_run || _abort_disk_full` after the existing `log_json SUCCESS` block. The two plans MUST land in order (01-01 first, 01-02 second) — captured in this plan's frontmatter via `depends_on: [01-01]` and `wave: 2`.

Sentinel-state contract on abort at start_func entry: because the Plan 01-02 disk check is the FIRST executable statement in start_func and the Plan 01-01 `touch .inprogress_<fn>` runs LATER in the same function, a disk-full abort at start_func entry happens BEFORE the sentinel touch for that function. Result: no `.inprogress_<fn>` is written for the aborting function. The EXIT trap from Plan 01-01 still fires and clears any sentinels that earlier functions might have left behind (there should be none if those earlier functions completed cleanly via end_func, which also clears them). A disk-full abort at end_func tail happens AFTER the `.<fn>` and `.status_<fn>` writes and AFTER the Plan 01-01 `rm -f .inprogress_<fn>`, so again the completing function leaves no sentinel orphan. Net effect: on disk-full abort, completed prior functions retain their `.<fn>` success checkpoints; the aborting function leaves no sentinel; the next run sees no resume banner for the aborting function (which is correct — disk-full is not a crash-recovery scenario).
bash -n /Users/six2dez/Tools/reconftw/modules/core.sh && shellcheck -s bash --severity=error /Users/six2dez/Tools/reconftw/modules/core.sh - `grep -nc '_check_disk_mid_run || _abort_disk_full' /Users/six2dez/Tools/reconftw/modules/core.sh` returns 2 (one in start_func, one in end_func). - In start_func: the `_check_disk_mid_run || _abort_disk_full` line appears BEFORE the `local current_date` line and BEFORE the Plan 01-01 `touch "$called_fn_dir/.inprogress_` line. Verifiable via: `awk '/^function start_func/,/^}/' modules/core.sh | grep -n '_check_disk_mid_run\|local current_date\|touch "\$called_fn_dir/\.inprogress_' | head` — first match must be `_check_disk_mid_run`. - In end_func: the `_check_disk_mid_run || _abort_disk_full` line appears AFTER the `log_json "SUCCESS"` line and BEFORE the closing `}`. Verifiable via: `awk '/^function end_func/,/^}/' modules/core.sh | grep -n 'log_json "SUCCESS"\|_check_disk_mid_run\|^}'` — the order must be `log_json "SUCCESS"` → `_check_disk_mid_run` → `}`. - The Plan 01-01 lines (`touch "$called_fn_dir/.inprogress_${1}"` in start_func and `rm -f "$called_fn_dir/.inprogress_${fn}"` in end_func) are still present and unchanged. - The existing `touch "$called_fn_dir/.${fn}"` at :1465 is still present. - `bash -n modules/core.sh` exits 0. - `shellcheck -s bash --severity=error modules/core.sh` exits 0 (no new error-level findings). - Behavior smoke: with `MIN_DISK_SPACE_GB=99999999` exported, invoking a real recon command (`./reconftw.sh -d test.local -p --dry-run` or any source-only test that calls start_func) MUST cause the process to exit non-zero with stderr containing `disk_full: aborting` and the JSONL log file (if STRUCTURED_LOGGING=true) MUST contain `reason=disk_full`. With `MIN_DISK_SPACE_GB=0` the run proceeds normally. - Sentinel-state smoke on disk-full at start_func: `mkdir -p /tmp/rftw-test/.called_fn && export dir=/tmp/rftw-test called_fn_dir=/tmp/rftw-test/.called_fn LOGFILE=/tmp/rftw-test/log.txt MIN_DISK_SPACE_GB=99999999`, then call `start_func test_fn "desc"` — process exits 1; check `ls "$called_fn_dir"/.inprogress_*` shows NO file for test_fn (sentinel never touched). Pre-seeded `.other_fn` checkpoint files remain present. Both call sites added in canonical short-circuit form at the documented anchors; existing Plan 01-01 sentinel ops untouched; existing `.` touch unchanged; shellcheck clean. - `bash -n modules/utils.sh modules/core.sh` → exit 0. - `shellcheck -s bash --severity=error modules/utils.sh modules/core.sh` → exit 0 (no NEW error-level findings vs baseline). - Manual smoke (no test files in this phase per CONTEXT Deferred): 1. Source the project: `./reconftw.sh --source-only`. 2. Force disk-full: `export MIN_DISK_SPACE_GB=99999999`. 3. Set up minimal state: `mkdir -p /tmp/rftw-test/.called_fn && export dir=/tmp/rftw-test called_fn_dir=/tmp/rftw-test/.called_fn LOGFILE=/tmp/rftw-test/log.txt STRUCTURED_LOGGING=true STRUCTURED_LOG_FILE=/tmp/rftw-test/events.jsonl`. 4. Call `start_func test_fn "desc"` directly — expect immediate exit 1, stderr contains `disk_full: aborting`, and `/tmp/rftw-test/events.jsonl` contains a line with `"reason":"disk_full"` (or equivalent JSONL shape). Verify NO `.inprogress_test_fn` was created (the disk check ran before the sentinel touch). 5. Verify EXIT trap composition with Plan 01-01: with `MIN_DISK_SPACE_GB=99999999` and a pre-seeded `.inprogress_sub_brute` in `called_fn_dir`, a `start` invocation that aborts via _abort_disk_full must STILL clear the `.inprogress_*` files via the EXIT trap chain (no fake resume condition for the next run). - Plan 01-02 success criterion (ROADMAP §"Phase 1" SC#2): A scan that exhausts disk space mid-run aborts with a clear `ENOSPC` error message rather than producing zero-byte or truncated output files. - All `must_haves.truths` verifiable per the acceptance criteria above. - MIN_DISK_SPACE_GB threshold used by mid-run check is the same as pre-flight (single source of truth; no new knob). - No `run_command` stderr scanning, no per-redirect ENOSPC traps (D-10 boundary-only locked). - No modification to `reconftw.cfg:39` or `modules/modes.sh:23` (DOCS-02 reconciliation is Phase 5). - _abort_disk_full exits 1 and lets the Plan 01-01 EXIT trap clear `.inprogress_*` automatically — no double-cleanup logic. - Disk-full abort at start_func entry leaves no `.inprogress_` for the aborting function (the disk check precedes the sentinel touch); completed prior functions retain their `.` checkpoints. After completion, create `.planning/phases/01-resilient-resume-timeout-safety/01-02-SUMMARY.md`.