Skip to content

Input Validation

Melvin PETIT edited this page Jun 17, 2026 · 1 revision

Input Validation

As of v1.2.0, inputs that have a well-defined shape (targets, ports, CIDR ranges, domains) are validated before they reach a tool. This catches typos early and keeps malformed values out of sudo command lines.

How it works

Two pieces cooperate:

  • Validator functions in lib/core.sh, named fys_is_*. Each takes one argument, returns 0 when the value is well-formed and 1 otherwise, and prints nothing. Callers decide how to react.

  • The prompt_valid wrapper in lib/installer.sh:

    port=$(prompt_valid "Port" fys_is_port) || return 0

    It reads a value, runs the validator, and re-prompts on bad input. An empty answer is treated as "abort": it logs No value provided. and returns 1, which the || return 0 turns into a clean trip back to the menu. So you can always back out of any validated prompt by pressing Enter.

A bad-but-non-empty value prints Invalid value: <x> and asks again.

The validators

Function Accepts Examples
fys_is_port A single TCP/UDP port, 1–65535. 22, 443, 65535
fys_is_port_spec Comma lists and ranges of ports (nmap/masscan style). Empty rejected. 80, 1-1000, 22,80,443, 1-65535
fys_is_ipv4 A dotted-quad IPv4 with each octet 0–255. 192.168.1.10
fys_is_hostname An RFC-1123 hostname (labels of letters/digits/hyphens, ≤253 chars). example.com, scanme.nmap.org
fys_is_host IPv4 or hostname. either of the above
fys_is_cidr IPv4 CIDR; prefix 0–32. 192.168.1.0/24, 10.0.0.0/8
fys_is_host_or_cidr A host or a CIDR range. host, IP, or CIDR

Which prompt uses which

Tool / prompt Validator
Nmap target fys_is_host_or_cidr
Netcat target / port fys_is_host / fys_is_port
Tcpdump port / host fys_is_port / fys_is_host
hping3 target / port fys_is_host / fys_is_port
arp-scan range fys_is_cidr
Masscan target / ports fys_is_host_or_cidr / fys_is_port_spec
Nikto host / port fys_is_host / fys_is_port (default 80)
dnsenum domain fys_is_hostname

Free-form prompts (URLs, interfaces, custom BPF filters, "custom args" modes) use prompt_value and are not shape-validated, because there is no single correct form. Treat those as you would a raw shell argument.

Using validators in a new module

When you add a tool, reuse these rather than rolling your own regex:

target=$(prompt_valid "Target (ip/host)" fys_is_host) || return 0
port=$(prompt_valid "Port" fys_is_port) || return 0

Always pair prompt_valid with || return 0 so an empty answer returns the user to the menu. See Extending FeedYourSpider.

Clone this wiki locally