Skip to content

Shared Library and Testing

Qwavey edited this page Aug 23, 2026 · 1 revision

Shared Library & Testing

scripts/lib/common.sh

Sourced by every script in this toolkit - never executed directly.

. "$(dirname "$0")/lib/common.sh"

What it provides:

  • say / err / die - consistent console output and fatal-error exit.
  • cfg_get / cfg_set / cfg_del - a config store wrapping the official PAYLOAD_*_CONFIG DuckyScript commands.
  • confirm / ask - interactive yes/no and free-text prompts.
  • need_arg - set -u-safe "this flag needs a value" argument parsing.
  • print_help - reads the calling script's own leading comment header and prints it as --help output. This is why every script's --help text in this wiki is guaranteed accurate: it's not hand-maintained documentation that can drift, it's literally what the script prints on the real device when you run it with -h.
  • pid_running(PIDFILE, NAME_PATTERN) - the shared PID-reuse-safe process-liveness check used by every script that tracks a background job. Checks /proc/$PID/cmdline against NAME_PATTERN before trusting a PID file's contents, so a reused PID can't be mistaken for the process that originally wrote the file.
  • canonicalize_lan_topology(DESIRED, BRIDGE_NAME) - the shared reconciler that keeps eth0 correctly placed in br-lan (or correctly handed off to a bridge), used by both sniff.sh and reset.sh.
  • filter_yes_args, is_valid_mac, sql_escape, resolve_python3, and several other small helpers - see the file itself for the full list, each documented at its own definition.

scripts/lib/deadnet/

The vendored deadnet core tool (trimmed to just the ~30KB engine, not its own CLI wrapper) that deadnet.sh drives directly.

scripts/guiserver/

The optional local web Control Panel - server.py is a thin HTTP backend that shells out to the same scripts documented in this wiki (nothing it does bypasses the official commands underneath), gated by an ALLOWED_SCRIPTS allowlist and a token set during python setup.py. Binds only to br-lan, never the internet-facing uplink. Start/stop it with webui.sh. Not the main focus of this project - most work happens over SSH and payloads.

Test suites (scripts/tests/)

Standalone, offline regression checks - no real device, no real network hardware needed. Each extracts the actual pure-logic functions straight out of the live source (not a hand-copied duplicate) and feeds them synthetic input.

Suite Covers Passing
test_sniff_logic.sh sniff.sh's argument validation, block-boundary parsing, protocol classification, the credential/HTTP detection regexes, and the shared PID-reuse-guard helpers 56
test_payload_logic.sh lan_sniffer/payload.sh's progress-bar rendering and duration-picker parsing 12
test_common_logic.sh lib/common.sh's canonicalize_lan_topology() and eth0_in_br_lan() 7

Run any of them directly:

bash scripts/tests/test_sniff_logic.sh

Each suite was spot-verified at least once by deliberately breaking the behavior it covers, confirming the test fails, then restoring the fix - so they're not just checking that the code runs, they're checking that breaking the real bug they were written for actually gets caught.

Clone this wiki locally