Files
NeuroSploit/setup.sh
T

632 lines
29 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# NeuroSploit installer (macOS / Linux / WSL) — by Joas A Santos & Red Team Leaders
#
# curl -fsSL https://raw.githubusercontent.com/JoasASantos/NeuroSploit/main/setup.sh | bash
# ./setup.sh # interactive: pick CLI, Web console, or everything
# ./setup.sh --web --yes # unattended
#
# Works on a fresh machine: installs what is missing (git, curl, build tools,
# Node.js >= 18, recon tools), downloads the prebuilt binary (or builds it from
# source), deploys the web console, puts `neurosploit` / `neurosploit-web` on
# PATH and sets NEUROSPLOIT_BASE. Safe to re-run: it updates in place and keeps
# your config (.neurosploit/) and runs (runs/).
#
# Options (each has an env equivalent for `curl | bash`):
# --cli | --web | --all what to install NEUROSPLOIT_MODE=cli|web|all
# -y, --yes no questions, use defaults NEUROSPLOIT_YES=1
# --dir PATH install dir NEUROSPLOIT_DIR (~/.neurosploit-app)
# --prefix PATH where commands are linked PREFIX (~/.local/bin)
# --ref TAG release tag or branch NEUROSPLOIT_REF (latest release)
# --build build from source NEUROSPLOIT_BUILD=1
# --port N web console port NEUROSPLOIT_WEB_PORT (4173)
# --service start the web console at login (systemd user / launchd)
# --no-deps skip system packages NEUROSPLOIT_NO_DEPS=1
# --run launch when done NEUROSPLOIT_RUN=1
# -h, --help
set -euo pipefail
REPO_SLUG="JoasASantos/NeuroSploit"
REPO_URL="https://github.com/${REPO_SLUG}.git"
FALLBACK_REF="v4.5.0"
NODE_MIN=18
NODE_LINE="latest-v22.x" # used only when the system cannot provide Node >= 18
MODE="${NEUROSPLOIT_MODE:-}"
YES="${NEUROSPLOIT_YES:-0}"
DIR="${NEUROSPLOIT_DIR:-$HOME/.neurosploit-app}"
PREFIX="${PREFIX:-$HOME/.local/bin}"
REF="${NEUROSPLOIT_REF:-}"
BUILD="${NEUROSPLOIT_BUILD:-0}"
WEB_PORT="${NEUROSPLOIT_WEB_PORT:-4173}"
SERVICE="${NEUROSPLOIT_SERVICE:-}"
NO_DEPS="${NEUROSPLOIT_NO_DEPS:-0}"
RUN_NOW="${NEUROSPLOIT_RUN:-}"
usage() {
if [ -f "${BASH_SOURCE[0]:-}" ]; then sed -n '2,26p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
else echo "Options: --cli | --web | --all, --yes, --dir, --prefix, --ref, --build, --port, --service, --no-deps, --run"; fi
exit 0
}
while [ $# -gt 0 ]; do
case "$1" in
--cli) MODE=cli ;;
--web) MODE=web ;;
--all|--both) MODE=all ;;
-y|--yes) YES=1 ;;
--dir) DIR="$2"; shift ;;
--prefix) PREFIX="$2"; shift ;;
--ref) REF="$2"; shift ;;
--build) BUILD=1 ;;
--port) WEB_PORT="$2"; shift ;;
--service) SERVICE=1 ;;
--no-service) SERVICE=0 ;;
--no-deps) NO_DEPS=1 ;;
--run) RUN_NOW=1 ;;
-h|--help) usage ;;
*) printf 'Unknown option: %s (see --help)\n' "$1" >&2; exit 2 ;;
esac
shift
done
# ---------------------------------------------------------------- output ----
if [ -t 1 ]; then B=$'\033[1m'; D=$'\033[2m'; R=$'\033[0m'; P=$'\033[1;35m'; G=$'\033[1;32m'; Y=$'\033[1;33m'; E=$'\033[1;31m'
else B=; D=; R=; P=; G=; Y=; E=; fi
STEP=0
step() { STEP=$((STEP + 1)); printf '\n%s[%s] %s%s\n' "$B" "$STEP" "$*" "$R"; }
say() { printf ' %s›%s %s\n' "$P" "$R" "$*"; }
ok() { printf ' %s✓%s %s\n' "$G" "$R" "$*"; }
warn() { printf ' %s!%s %s\n' "$Y" "$R" "$*"; }
die() { printf ' %s✗ %s%s\n' "$E" "$*" "$R" >&2; exit 1; }
have() { command -v "$1" >/dev/null 2>&1; }
# Questions read from the terminal even under `curl | bash`.
TTY=0
if [ "$YES" != "1" ] && [ -r /dev/tty ] && { exec 3</dev/tty; } 2>/dev/null; then TTY=1; fi
ask() { # ask <prompt> <default y|n> → 0 for yes
local def="$2" ans=""
if [ "$TTY" != "1" ]; then [ "$def" = "y" ]; return; fi
printf ' %s?%s %s %s ' "$P" "$R" "$1" "$([ "$def" = y ] && echo '[Y/n]' || echo '[y/N]')"
read -r ans <&3 || ans=""
ans="$(printf '%s' "$ans" | tr '[:upper:]' '[:lower:]')"
[ -z "$ans" ] && ans="$def"
case "$ans" in y|yes|s|sim) return 0 ;; *) return 1 ;; esac
}
cat <<'BANNER'
███╗ ██╗███████╗██╗ ██╗██████╗ ██████╗
████╗ ██║██╔════╝██║ ██║██╔══██╗██╔═══██╗ NeuroSploit installer
██╔██╗ ██║█████╗ ██║ ██║██████╔╝██║ ██║ CLI + web console
██║╚██╗██║██╔══╝ ██║ ██║██╔══██╗██║ ██║ by Joas A Santos
██║ ╚████║███████╗╚██████╔╝██║ ██║╚██████╔╝ & Red Team Leaders
╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝
BANNER
# -------------------------------------------------------------- platform ----
OS_RAW="$(uname -s)"; ARCH_RAW="$(uname -m)"
case "$OS_RAW" in
Linux*) OS=linux ;;
Darwin*) OS=macos ;;
MINGW*|MSYS*|CYGWIN*) die "Native Windows: run setup.bat (or install.ps1). This script works inside WSL." ;;
*) die "Unsupported OS: $OS_RAW" ;;
esac
case "$ARCH_RAW" in
x86_64|amd64) ARCH=x64 ;;
arm64|aarch64) ARCH=arm64 ;;
*) ARCH="$ARCH_RAW" ;;
esac
PLAT="${OS}-${ARCH}"
DISTRO=""
if [ "$OS" = linux ] && [ -r /etc/os-release ]; then DISTRO="$(. /etc/os-release && echo "${PRETTY_NAME:-$ID}")"; fi
grep -qi microsoft /proc/version 2>/dev/null && DISTRO="$DISTRO (WSL)"
# Script dir when run from a checkout (not `curl | bash`): lets us reuse local sources.
LOCAL_SRC=""
if [ -n "${BASH_SOURCE[0]:-}" ] && [ -f "${BASH_SOURCE[0]}" ]; then
_here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
[ -f "$_here/neurosploit-rs/Cargo.toml" ] && [ -f "$_here/web/server.js" ] && LOCAL_SRC="$_here"
fi
# ------------------------------------------------------------ what to install
if [ -z "$MODE" ]; then
if [ "$TTY" = "1" ]; then
printf '\n %sWhat do you want to install?%s\n' "$B" "$R"
printf ' %s1%s CLI only %sterminal agent: neurosploit run / REPL%s\n' "$B" "$R" "$D" "$R"
printf ' %s2%s Web console + CLI %sbrowser UI on http://localhost:%s (needs Node.js)%s\n' "$B" "$R" "$D" "$WEB_PORT" "$R"
printf ' %s3%s Everything %sweb console + CLI + full recon toolset (nmap, ffuf, rustscan, typst…)%s\n' "$B" "$R" "$D" "$R"
printf ' %s?%s Choice [3]: ' "$P" "$R"
read -r _c <&3 || _c=""
case "${_c:-3}" in 1|cli) MODE=cli ;; 2|web) MODE=web ;; *) MODE=all ;; esac
else
MODE=all
fi
fi
case "$MODE" in cli|web|all) ;; *) die "NEUROSPLOIT_MODE must be cli, web or all (got: $MODE)" ;; esac
WANT_WEB=0; [ "$MODE" != cli ] && WANT_WEB=1
printf '\n %sPlan%s %s · %s%s\n' "$B" "$R" "$PLAT" "${DISTRO:-$OS}" ""
printf ' mode %s%s%s → %s\n' "$B" "$MODE" "$R" "$DIR"
printf ' commands linked in %s\n' "$PREFIX"
[ -n "$LOCAL_SRC" ] && printf ' local checkout %s\n' "$LOCAL_SRC"
TMP="$(mktemp -d 2>/dev/null || mktemp -d -t neurosploit)"
cleanup() { rm -rf "$TMP"; }
trap cleanup EXIT
dl() { # dl <url> <out>
if have curl; then curl -fsL --retry 3 --connect-timeout 20 "$1" -o "$2"
elif have wget; then wget -q --tries=3 -O "$2" "$1"
else return 1; fi
}
# ------------------------------------------------------- package managers ---
SUDO=""
if [ "$(id -u)" != "0" ]; then
if have sudo; then SUDO="sudo"; else SUDO="__none__"; fi
fi
PKG=""
if [ "$OS" = macos ]; then PKG=brew
elif have apt-get; then PKG=apt
elif have dnf; then PKG=dnf
elif have yum; then PKG=yum
elif have pacman; then PKG=pacman
elif have zypper; then PKG=zypper
elif have apk; then PKG=apk; fi
brew_env() { # put Homebrew on PATH for this process (Apple Silicon / Intel / Linuxbrew)
local b
for b in /opt/homebrew/bin/brew /usr/local/bin/brew /home/linuxbrew/.linuxbrew/bin/brew; do
[ -x "$b" ] && { eval "$("$b" shellenv)"; return 0; }
done
return 1
}
APT_UPDATED=0
pkg_install() { # best-effort; never aborts the installer
[ "$NO_DEPS" = "1" ] && return 1
[ -n "$PKG" ] || return 1
if [ "$PKG" != brew ] && [ "$SUDO" = "__none__" ]; then
warn "not root and no sudo — cannot install: $*"; return 1
fi
local s="$SUDO"; [ "$s" = "__none__" ] && s=""
local log="$TMP/pkg.log" rc=0
case "$PKG" in
brew) have brew || return 1; HOMEBREW_NO_AUTO_UPDATE=1 HOMEBREW_NO_ENV_HINTS=1 brew install "$@" >"$log" 2>&1 || rc=$? ;;
apt) if [ "$APT_UPDATED" = 0 ]; then $s apt-get update -qq >"$log" 2>&1 || true; APT_UPDATED=1; fi
DEBIAN_FRONTEND=noninteractive $s apt-get install -y -qq --no-install-recommends "$@" >"$log" 2>&1 || rc=$? ;;
dnf) $s dnf install -y -q "$@" >"$log" 2>&1 || rc=$? ;;
yum) $s yum install -y -q "$@" >"$log" 2>&1 || rc=$? ;;
pacman) $s pacman -S --noconfirm --needed "$@" >"$log" 2>&1 || rc=$? ;;
zypper) $s zypper --non-interactive install "$@" >"$log" 2>&1 || rc=$? ;;
apk) $s apk add --no-cache "$@" >"$log" 2>&1 || rc=$? ;;
esac
if [ "$rc" != 0 ]; then
warn "$PKG could not install: $* (exit $rc)"
tail -n 4 "$log" 2>/dev/null | sed 's/^/ /'
return 1
fi
return 0
}
# ensure <cmd> <pkg-for-apt> <pkg-for-others> [label]
ensure() {
local cmd="$1" apt_pkg="$2" pkg="$3" label="${4:-$1}" name
if have "$cmd"; then ok "$label"; return 0; fi
case "$PKG" in apt) name="$apt_pkg" ;; *) name="$pkg" ;; esac
[ -z "$name" ] && { warn "$label missing (no package for $PKG)"; return 1; }
say "installing $label…"
pkg_install $name || true
hash -r 2>/dev/null || true
if have "$cmd"; then ok "$label installed"; return 0; fi
warn "$label still missing — install it manually"; return 1
}
# ---------------------------------------------------- 1. base prerequisites
step "Base prerequisites"
if [ "$NO_DEPS" = "1" ]; then
warn "system packages skipped (--no-deps) — only checking"
fi
if [ "$OS" = macos ]; then
if ! xcode-select -p >/dev/null 2>&1; then
warn "Xcode Command Line Tools are missing (git, compilers)."
if [ "$NO_DEPS" != 1 ] && ask "Install them now? A system dialog will open" y; then
xcode-select --install >/dev/null 2>&1 || true
say "Finish the dialog, then press Enter to continue…"
[ "$TTY" = 1 ] && read -r _ <&3 || true
fi
fi
if ! have brew && ! brew_env; then
if [ "$NO_DEPS" != 1 ] && ask "Homebrew is not installed. Install it (recommended, needs your password)?" y; then
say "installing Homebrew…"
if [ "$TTY" = 1 ]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" <&3 || warn "Homebrew install failed"
else
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || warn "Homebrew install failed"
fi
brew_env || true
fi
fi
have brew && ok "Homebrew $(brew --version 2>/dev/null | head -1 | awk '{print $2}')" || { warn "no Homebrew — system tools will be skipped"; PKG=""; }
else
[ -n "$PKG" ] && ok "package manager: $PKG" || warn "no supported package manager — system tools will be skipped"
[ "$SUDO" = "__none__" ] && warn "running without root or sudo — system packages cannot be installed"
fi
# TLS roots first: minimal images ship without them and every download is HTTPS.
case "$PKG" in
apt) dpkg -s ca-certificates >/dev/null 2>&1 || pkg_install ca-certificates || true ;;
dnf|yum|zypper|apk|pacman) [ -e /etc/ssl/certs/ca-certificates.crt ] || [ -e /etc/pki/tls/certs/ca-bundle.crt ] || pkg_install ca-certificates || true ;;
esac
have curl || have wget || ensure curl curl curl || die "curl or wget is required."
ensure git git git || true
have tar || ensure tar tar tar || die "tar is required."
# --------------------------------------------------------- 2. release ref ---
if [ -z "$REF" ]; then
REF="$(curl -fsSL https://api.github.com/repos/${REPO_SLUG}/releases/latest 2>/dev/null \
| grep -m1 '"tag_name"' | sed -E 's/.*"tag_name" *: *"([^"]+)".*/\1/' || true)"
[ -z "$REF" ] && REF="$FALLBACK_REF"
fi
# ------------------------------------------------- source tree (on demand) --
SRC_TREE=""
source_tree() { # sets SRC_TREE to a directory holding neurosploit-rs/, agents_md/, web/
[ -n "$SRC_TREE" ] && return 0
if [ -n "$LOCAL_SRC" ]; then SRC_TREE="$LOCAL_SRC"; return 0; fi
local co="$DIR/src"
if have git; then
if [ -d "$co/.git" ]; then
say "updating source checkout ($REF)…"
git -C "$co" fetch -q --depth 1 origin "$REF" 2>/dev/null && git -C "$co" checkout -q FETCH_HEAD 2>/dev/null \
|| git -C "$co" pull -q 2>/dev/null || warn "could not update $co — using it as is"
else
say "cloning $REPO_SLUG ($REF)…"
mkdir -p "$DIR"
git clone -q --depth 1 --branch "$REF" "$REPO_URL" "$co" 2>/dev/null || git clone -q --depth 1 "$REPO_URL" "$co" \
|| die "git clone failed"
fi
SRC_TREE="$co"; return 0
fi
# No git: the source tarball is enough for agents + web console.
say "downloading source archive ($REF)…"
dl "https://codeload.github.com/${REPO_SLUG}/tar.gz/${REF}" "$TMP/src.tar.gz" || die "could not download sources"
mkdir -p "$TMP/src" && tar -xzf "$TMP/src.tar.gz" -C "$TMP/src"
SRC_TREE="$(find "$TMP/src" -mindepth 1 -maxdepth 1 -type d | head -1)"
}
# ------------------------------------------------------- 3. the CLI binary --
step "NeuroSploit CLI ($REF)"
mkdir -p "$DIR"
BIN="$DIR/neurosploit"
bin_works() { [ -x "$BIN" ] && NEUROSPLOIT_BASE="$DIR" "$BIN" --version >/dev/null 2>&1; }
installed=0
if [ "$BUILD" != 1 ]; then
ASSET="neurosploit-${REF}-${PLAT}.tar.gz"
say "downloading $ASSET…"
if dl "https://github.com/${REPO_SLUG}/releases/download/${REF}/${ASSET}" "$TMP/bin.tar.gz" \
&& mkdir -p "$TMP/bin" && tar -xzf "$TMP/bin.tar.gz" -C "$TMP/bin" 2>/dev/null; then
f="$(find "$TMP/bin" -maxdepth 3 -name neurosploit -type f | head -1)"
if [ -n "$f" ]; then
d="$(dirname "$f")"
cp "$f" "$BIN.new" && chmod +x "$BIN.new" && mv -f "$BIN.new" "$BIN"
if [ -d "$d/agents_md" ]; then rm -rf "$DIR/agents_md"; cp -R "$d/agents_md" "$DIR/agents_md"; fi
[ "$OS" = macos ] && xattr -d com.apple.quarantine "$BIN" 2>/dev/null || true
if bin_works; then installed=1; ok "prebuilt binary installed"
else warn "prebuilt binary does not run on this system (old glibc?) — building from source"; fi
fi
else
warn "no prebuilt binary for $PLAT ($REF) — building from source"
fi
fi
if [ "$installed" != 1 ]; then
# Build toolchain: a C linker + Rust (TLS is rustls, so no OpenSSL headers needed).
if [ "$OS" = linux ] && ! have cc; then
case "$PKG" in
apt) pkg_install build-essential pkg-config || true ;;
dnf|yum) pkg_install gcc gcc-c++ make pkgconf-pkg-config || true ;;
pacman) pkg_install base-devel || true ;;
zypper) pkg_install gcc gcc-c++ make pkg-config || true ;;
apk) pkg_install build-base pkgconf || true ;;
esac
fi
have cc || have clang || warn "no C compiler found — the Rust build will likely fail"
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
# rustup present but no default toolchain → cargo exists yet cannot run.
if have rustup && ! cargo --version >/dev/null 2>&1; then
say "setting the default Rust toolchain (stable)…"; rustup default stable >/dev/null 2>&1 || true
fi
if ! have cargo || ! cargo --version >/dev/null 2>&1; then
say "installing Rust (rustup, stable, minimal profile)…"
curl --proto '=https' --tlsv1.2 -fsSL https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal >/dev/null \
|| die "rustup install failed"
. "$HOME/.cargo/env"
fi
ok "$(cargo --version)"
have git || die "git is required to build from source"
source_tree
say "compiling (first build downloads crates, takes a few minutes)…"
if ! ( cd "$SRC_TREE/neurosploit-rs" && cargo build --release ) >"$TMP/build.log" 2>&1; then
grep -E '^error' -A6 "$TMP/build.log" | head -40 | sed 's/^/ /'
die "cargo build failed"
fi
cp "$SRC_TREE/neurosploit-rs/target/release/neurosploit" "$BIN.new" && chmod +x "$BIN.new" && mv -f "$BIN.new" "$BIN"
rm -rf "$DIR/agents_md"; cp -R "$SRC_TREE/agents_md" "$DIR/agents_md"
bin_works || die "the built binary does not run"
ok "built from source"
fi
VERSION="$(NEUROSPLOIT_BASE="$DIR" "$BIN" --version 2>/dev/null | head -1 || echo neurosploit)"
ok "$VERSION → $BIN"
mkdir -p "$PREFIX"
ln -sf "$BIN" "$PREFIX/neurosploit"
ok "linked $PREFIX/neurosploit"
# ------------------------------------------------------------- 4. Node.js ---
NODE_BIN=""
node_ok() { # node_ok <node-binary>
local v; v="$("$1" -v 2>/dev/null | sed 's/^v//' | cut -d. -f1)"
[ -n "$v" ] && [ "$v" -ge "$NODE_MIN" ] 2>/dev/null
}
node_from_nodejs_org() { # official tarball into $DIR/runtime/node — no root needed
local nos narch sums file
case "$OS" in macos) nos=darwin ;; *) nos=linux ;; esac
case "$ARCH" in x64) narch=x64 ;; arm64) narch=arm64 ;; *) return 1 ;; esac
[ -f /etc/alpine-release ] && return 1 # glibc builds do not run on musl
dl "https://nodejs.org/dist/${NODE_LINE}/SHASUMS256.txt" "$TMP/SHASUMS256.txt" || return 1
file="$(grep -oE "node-v[0-9.]+-${nos}-${narch}\.tar\.gz" "$TMP/SHASUMS256.txt" | head -1)"
[ -n "$file" ] || return 1
say "downloading $file from nodejs.org…"
dl "https://nodejs.org/dist/${NODE_LINE}/${file}" "$TMP/$file" || return 1
sums="$(grep " ${file}\$" "$TMP/SHASUMS256.txt" | awk '{print $1}')"
local got
if have sha256sum; then got="$(sha256sum "$TMP/$file" | awk '{print $1}')"; else got="$(shasum -a 256 "$TMP/$file" | awk '{print $1}')"; fi
[ "$got" = "$sums" ] || { warn "Node.js checksum mismatch — refusing to install it"; return 1; }
rm -rf "$DIR/runtime/node" && mkdir -p "$DIR/runtime"
tar -xzf "$TMP/$file" -C "$DIR/runtime" && mv "$DIR/runtime/${file%.tar.gz}" "$DIR/runtime/node"
}
if [ "$WANT_WEB" = 1 ]; then
step "Node.js (>= $NODE_MIN, for the web console)"
if [ -x "$DIR/runtime/node/bin/node" ] && node_ok "$DIR/runtime/node/bin/node"; then NODE_BIN="$DIR/runtime/node/bin/node"
elif have node && node_ok "$(command -v node)"; then NODE_BIN="$(command -v node)"
else
have node && warn "node $(node -v) is too old"
case "$PKG" in
brew) pkg_install node || true ;;
apt) pkg_install nodejs npm || true ;;
dnf|yum|zypper) pkg_install nodejs npm || true ;;
pacman) pkg_install nodejs npm || true ;;
apk) pkg_install nodejs npm || true ;;
esac
hash -r 2>/dev/null || true
if have node && node_ok "$(command -v node)"; then NODE_BIN="$(command -v node)"
elif node_from_nodejs_org && node_ok "$DIR/runtime/node/bin/node"; then NODE_BIN="$DIR/runtime/node/bin/node"
fi
fi
[ -n "$NODE_BIN" ] || die "could not get Node.js >= $NODE_MIN — install it from https://nodejs.org and re-run"
ok "node $("$NODE_BIN" -v) → $NODE_BIN"
# ------------------------------------------------------- 5. web console ---
step "Web console"
source_tree
[ -f "$SRC_TREE/web/server.js" ] || die "web console not found in $SRC_TREE"
rm -rf "$DIR/web.new" && mkdir -p "$DIR/web.new"
cp -R "$SRC_TREE/web/server.js" "$SRC_TREE/web/package.json" "$SRC_TREE/web/public" "$DIR/web.new/"
rm -rf "$DIR/web" && mv "$DIR/web.new" "$DIR/web"
mkdir -p "$DIR/runs" "$DIR/.neurosploit"
ok "deployed → $DIR/web (config and runs are kept between updates)"
mkdir -p "$DIR/bin"
cat > "$DIR/bin/neurosploit-web" <<LAUNCHER
#!/usr/bin/env bash
# NeuroSploit web console launcher (written by setup.sh).
# neurosploit-web [--port N] [--host ADDR] [--open]
# Binds to 127.0.0.1 by default; use --host 0.0.0.0 only on a trusted network.
DIR="$DIR"
NODE="$NODE_BIN"
[ -x "\$NODE" ] || NODE="\$(command -v node)"
PORT="\${NEUROSPLOIT_WEB_PORT:-$WEB_PORT}"
HOST="\${NEUROSPLOIT_WEB_HOST:-127.0.0.1}"
OPEN=0
while [ \$# -gt 0 ]; do
case "\$1" in
--port) PORT="\$2"; shift ;;
--host) HOST="\$2"; shift ;;
--open) OPEN=1 ;;
-h|--help) sed -n '2,4p' "\$0"; exit 0 ;;
esac
shift
done
export NEUROSPLOIT_BASE="\$DIR" NEUROSPLOIT_BIN="\$DIR/neurosploit" NEUROSPLOIT_WEB_PORT="\$PORT" NEUROSPLOIT_WEB_HOST="\$HOST"
export PATH="\$DIR:\$PATH"
if [ "\$OPEN" = 1 ]; then
( sleep 1.5
url="http://localhost:\$PORT"
if command -v open >/dev/null 2>&1; then open "\$url"
elif command -v xdg-open >/dev/null 2>&1; then xdg-open "\$url" >/dev/null 2>&1
elif command -v wslview >/dev/null 2>&1; then wslview "\$url"; fi ) &
fi
cd "\$DIR/web" && exec "\$NODE" server.js
LAUNCHER
chmod +x "$DIR/bin/neurosploit-web"
ln -sf "$DIR/bin/neurosploit-web" "$PREFIX/neurosploit-web"
ok "linked $PREFIX/neurosploit-web"
# Optional: start at login.
if [ -z "$SERVICE" ]; then
if [ "$TTY" = 1 ] && ask "Start the web console automatically at login?" n; then SERVICE=1; else SERVICE=0; fi
fi
if [ "$SERVICE" = 1 ]; then
if [ "$OS" = macos ]; then
PL="$HOME/Library/LaunchAgents/io.neurosploit.web.plist"
mkdir -p "$(dirname "$PL")" "$DIR/logs"
cat > "$PL" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>Label</key><string>io.neurosploit.web</string>
<key>ProgramArguments</key><array><string>$DIR/bin/neurosploit-web</string></array>
<key>RunAtLoad</key><true/>
<key>KeepAlive</key><true/>
<key>StandardOutPath</key><string>$DIR/logs/web.log</string>
<key>StandardErrorPath</key><string>$DIR/logs/web.log</string>
</dict></plist>
PLIST
launchctl unload "$PL" >/dev/null 2>&1 || true
launchctl load -w "$PL" >/dev/null 2>&1 && ok "launchd agent loaded (logs: $DIR/logs/web.log)" || warn "could not load $PL"
elif have systemctl && systemctl --user show-environment >/dev/null 2>&1; then
UNIT="$HOME/.config/systemd/user/neurosploit-web.service"
mkdir -p "$(dirname "$UNIT")"
cat > "$UNIT" <<UNIT
[Unit]
Description=NeuroSploit web console
After=network-online.target
[Service]
ExecStart=$DIR/bin/neurosploit-web
Restart=on-failure
[Install]
WantedBy=default.target
UNIT
systemctl --user daemon-reload && systemctl --user enable --now neurosploit-web.service >/dev/null 2>&1 \
&& ok "systemd user service enabled (journalctl --user -u neurosploit-web)" || warn "could not enable the systemd user service"
else
warn "no launchd/systemd user session — start it with: neurosploit-web"
fi
fi
fi
# --------------------------------------------------------- 6. tools ---------
step "Testing tools"
ensure nmap nmap nmap "nmap (port scans)" || true
if [ "$MODE" = all ]; then
ensure jq jq jq "jq" || true
ensure python3 python3 python3 "python3" || true
case "$PKG" in
brew|pacman|apk) ensure ffuf ffuf ffuf "ffuf (content discovery)" || true ;;
apt) ensure ffuf ffuf ffuf "ffuf (content discovery)" || true ;;
*) have ffuf && ok "ffuf" || warn "ffuf optional — install with: go install github.com/ffuf/ffuf/v2@latest" ;;
esac
if have rustscan; then ok "rustscan"
elif [ "$PKG" = brew ]; then ensure rustscan "" rustscan "rustscan (fast port scan)" || true
elif have cargo; then say "installing rustscan (cargo)…"; cargo install --quiet rustscan >/dev/null 2>&1 && ok "rustscan installed" || warn "rustscan optional — skipped"
else warn "rustscan optional — skipped (needs Homebrew or Rust)"; fi
fi
# typst renders PDF reports.
if have typst; then ok "typst (PDF reports)"
elif [ "$PKG" = brew ] && pkg_install typst; then ok "typst installed"
else
TT=""
case "$PLAT" in
linux-x64) TT=x86_64-unknown-linux-musl ;; linux-arm64) TT=aarch64-unknown-linux-musl ;;
macos-x64) TT=x86_64-apple-darwin ;; macos-arm64) TT=aarch64-apple-darwin ;;
esac
if [ -n "$TT" ] && ! have xz && [ "$OS" = linux ]; then pkg_install xz-utils 2>/dev/null || pkg_install xz 2>/dev/null || true; fi
if [ -n "$TT" ] && have xz && dl "https://github.com/typst/typst/releases/latest/download/typst-${TT}.tar.xz" "$TMP/typst.tar.xz" \
&& mkdir -p "$TMP/typst" && tar -xJf "$TMP/typst.tar.xz" -C "$TMP/typst" 2>/dev/null; then
mkdir -p "$DIR/runtime/bin"
cp "$(find "$TMP/typst" -name typst -type f | head -1)" "$DIR/runtime/bin/typst" && chmod +x "$DIR/runtime/bin/typst"
ln -sf "$DIR/runtime/bin/typst" "$PREFIX/typst"
ok "typst installed → $PREFIX/typst"
else
warn "typst optional (PDF reports) — HTML/Markdown reports still work"
fi
fi
for c in claude codex gemini; do have "$c" && ok "$c CLI found (subscription login)"; done
# ------------------------------------------------- optional C2 MCP servers --
# Unchanged opt-in behaviour from earlier installers; nothing runs unless the
# matching NEUROSPLOIT_*_C2=1 variable is set.
if [ "${NEUROSPLOIT_SLIVER_C2:-0}" = 1 ]; then
SLIVER_MCP_DIR="${NEUROSPLOIT_SLIVER_MCP_PATH:-$DIR/sec-sliver-c2-mcp}"
if [ -d "$SLIVER_MCP_DIR/dist" ]; then ok "Sliver C2 MCP present"
elif have npm; then
git clone -q --depth 1 https://github.com/schwarztim/sec-sliver-c2-mcp.git "$SLIVER_MCP_DIR" 2>/dev/null \
&& ( cd "$SLIVER_MCP_DIR" && npm install --production >/dev/null 2>&1 && npm run build >/dev/null 2>&1 ) \
&& ok "Sliver C2 MCP installed" || warn "Sliver C2 MCP install failed"
else warn "Sliver C2 MCP needs npm — skipped"; fi
fi
if [ "${NEUROSPLOIT_ADAPTIX_C2:-0}" = 1 ]; then
ADAPTIX_MCP_DIR="${NEUROSPLOIT_ADAPTIX_MCP_PATH:-$DIR/AdaptixC2_mcp}"
if [ -f "$ADAPTIX_MCP_DIR/AdaptixC2_mcp.py" ]; then ok "AdaptixC2 MCP present"
elif have pip3; then
git clone -q --depth 1 https://github.com/0xb11a1/AdaptixC2_mcp.git "$ADAPTIX_MCP_DIR" 2>/dev/null \
&& ( cd "$ADAPTIX_MCP_DIR" && pip3 install -q -r requirments.txt >/dev/null 2>&1 ) \
&& ok "AdaptixC2 MCP installed" || warn "AdaptixC2 MCP install failed"
else warn "AdaptixC2 MCP needs pip3 — skipped"; fi
fi
# ------------------------------------------------------ 7. shell setup ------
step "Shell environment"
cat > "$DIR/env.sh" <<EOF
# NeuroSploit env — \`source\` this to use neurosploit in the current shell.
export NEUROSPLOIT_BASE="$DIR"
export NEUROSPLOIT="$DIR/neurosploit"
case ":\$PATH:" in *":$PREFIX:"*) : ;; *) export PATH="$PREFIX:\$PATH" ;; esac
EOF
persist() { # idempotent block in an rc file
local rc="$1"
[ -e "$rc" ] || touch "$rc"
if grep -q '# >>> neurosploit >>>' "$rc" 2>/dev/null; then
# refresh the managed block (install dir may have changed)
awk '/# >>> neurosploit >>>/{skip=1} !skip{print} /# <<< neurosploit <<</{skip=0}' "$rc" > "$rc.ns.tmp" && cat "$rc.ns.tmp" > "$rc" && rm -f "$rc.ns.tmp"
elif grep -q 'NEUROSPLOIT_BASE' "$rc" 2>/dev/null; then
ok "$rc already sets NEUROSPLOIT_BASE (left untouched)"; return 0
fi
{ echo '# >>> neurosploit >>>'
echo "[ -f \"$DIR/env.sh\" ] && . \"$DIR/env.sh\""
echo '# <<< neurosploit <<<'; } >> "$rc"
ok "configured $rc"
}
case "$(basename "${SHELL:-bash}")" in
zsh) persist "$HOME/.zshrc" ;;
bash) persist "$HOME/.bashrc"; [ "$OS" = macos ] && persist "$HOME/.bash_profile" ;;
*) persist "$HOME/.profile" ;;
esac
if [ -d "$HOME/.config/fish" ]; then
FCONF="$HOME/.config/fish/config.fish"
if ! grep -q 'NEUROSPLOIT_BASE' "$FCONF" 2>/dev/null; then
{ echo ''; echo '# NeuroSploit'; echo "set -gx NEUROSPLOIT_BASE \"$DIR\""; echo "fish_add_path \"$PREFIX\""; } >> "$FCONF"
ok "configured $FCONF"
fi
fi
# ------------------------------------------------------------ summary -------
printf '\n%s ✓ NeuroSploit is installed%s (%s, mode: %s)\n\n' "$G" "$R" "$VERSION" "$MODE"
printf ' Activate in this shell: %ssource "%s/env.sh"%s (new terminals pick it up automatically)\n\n' "$B" "$DIR" "$R"
printf ' %sCLI%s\n' "$B" "$R"
printf ' neurosploit interactive session\n'
printf ' neurosploit run https://target -v one-shot test\n'
printf ' neurosploit --help\n'
if [ "$WANT_WEB" = 1 ]; then
printf '\n %sWeb console%s\n' "$B" "$R"
printf ' neurosploit-web --open http://localhost:%s\n' "$WEB_PORT"
fi
printf '\n %sAI access%s: one API key (set it in the web console or export ANTHROPIC_API_KEY / OPENAI_API_KEY),\n' "$B" "$R"
printf ' or a logged-in CLI subscription (claude, codex, gemini).\n'
printf ' %sUpdate later: re-run this installer. Uninstall: rm -rf "%s" and the neurosploit block in your shell rc.%s\n' "$D" "$DIR" "$R"
# ------------------------------------------------------------ launch --------
if [ -z "$RUN_NOW" ] && [ "$TTY" = 1 ]; then
if [ "$WANT_WEB" = 1 ] && [ "$SERVICE" != 1 ]; then
ask "Open the web console now?" y && RUN_NOW=web
elif [ "$WANT_WEB" != 1 ]; then
ask "Start an interactive session now?" n && RUN_NOW=cli
fi
fi
case "$RUN_NOW" in
1) [ "$WANT_WEB" = 1 ] && RUN_NOW=web || RUN_NOW=cli ;;
esac
if [ "$RUN_NOW" = web ]; then
printf '\n'; say "starting the web console (Ctrl+C to stop)…"
exec "$DIR/bin/neurosploit-web" --open
elif [ "$RUN_NOW" = cli ]; then
printf '\n'; say "starting NeuroSploit…"
if [ "$TTY" = 1 ]; then exec env NEUROSPLOIT_BASE="$DIR" "$BIN" <&3; else exec env NEUROSPLOIT_BASE="$DIR" "$BIN"; fi
fi
if [ "$SERVICE" = 1 ] && [ "$WANT_WEB" = 1 ]; then
printf '\n The web console is running in the background: http://localhost:%s\n' "$WEB_PORT"
fi