Skip to content

scripts: report a missing script program before scanning - #965

Merged
bee-san merged 1 commit into
bee-san:masterfrom
qianeric-backup:fix/preflight-script-programs
Nov 4, 2026
Merged

bee-san merged 1 commit into
bee-san:masterfrom
qianeric-backup:fix/preflight-script-programs

Conversation

@qianeric-backup

Copy link
Copy Markdown
Contributor

What this fixes

Scripts are executed through sh -c, so when the program a call_format starts with is missing, the
only feedback comes after the scan has already run:

Open 127.0.0.1:18080
[~] Starting Script(s)
[!] Error No such file or directory (os error 2)

That neither names the program nor arrives before a long scan has been wasted. From the issue:

[~] Starting Script(s)
sh: line 1: nmap: command not found
[!] Error Exit code = 127

Fixes #691, following the approach you suggested in the issue.

The change

init_scripts now checks the first word of every selected script format against PATH and fails
there with the program named. Resolution follows what the shell would do: PATH entries in order,
plus PATHEXT on Windows for bare names.

Formats whose first word is not a bare program name are skipped, because PATH cannot answer for
them:

  • FOO=bar cmd ... — leading assignment
  • /opt/custom/nmap ... — explicit path
  • {{script}} ... — placeholder filled in at run time

Verification

nmap absent from PATH, scan against a listening port:

$ env PATH=/tmp/fakebin rustscan -a 127.0.0.1 -p 18080
[!] Initiating scripts failed!
The script `default` runs `nmap`, which is not installed or not in PATH. Install it, or skip scripts with `--scripts none`.

Before the change, the same command scanned first and then reported
[!] Error No such file or directory (os error 2).

nmap present — scan and script phase unchanged:

Open 127.0.0.1:18080
[~] Starting Script(s)

--scripts none still runs with no check at all.

Three unit tests cover the accept, reject and skip paths. cargo test scripts: 10 passed, 0 failed.

Why not which

You mentioned harryfei/which-rs, and I tried it first. Both which 7 and 8 drag windows-sys
from 0.60.2 to 0.61.2, which rewrites about 110 lines of Cargo.lock — a lot of churn in a
dependency-sensitive repo for what is a split_paths + is_file check. The implementation here is
about 15 lines with no new dependency, and Cargo.lock is untouched. Happy to switch to which if
you would rather keep the resolution logic in a crate.

Scripts are run through `sh -c`, so when the program a `call_format`
starts with is missing, the only feedback is whatever the shell prints
once the scan has already finished:

    Open 127.0.0.1:18080
    [~] Starting Script(s)
    [!] Error No such file or directory (os error 2)

which neither names the program nor arrives before a long scan has been
wasted.

Check the first word of every selected script format against PATH while
the scripts are initialised, and fail there with the program named. Name
resolution follows what the shell would do: PATH entries in order, plus
PATHEXT on Windows.

Formats that do not start with a bare program name are left alone, since
their first word is not something PATH can answer for:

- `FOO=bar cmd ...` (leading assignment)
- `/opt/custom/nmap ...` (explicit path)
- `{{script}} ...` (placeholder filled in at run time)

With nmap absent, on the same scan:

    before: scans, then "[!] Error No such file or directory (os error 2)"
    after:  "[!] Initiating scripts failed!
             The script `default` runs `nmap`, which is not installed or
             not in PATH. Install it, or skip scripts with `--scripts none`."

With nmap present the scan and the script phase run as before.

Implemented with std/target-specific helpers rather than a new
dependency: `which` pulls in a newer windows-sys and rewrites ~110 lines
of Cargo.lock for a 15-line check.

Refs bee-san#691
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@bee-san
bee-san merged commit b46f982 into bee-san:master Nov 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

detect the presence of nmap

2 participants