feat(infra): Docker + PostgreSQL + Kali worker setup

- docker-compose.yml: PostgreSQL 16, neurosploit app, kali-worker
- Dockerfile: multi-stage Rust build + Node runtime
- Dockerfile.kali: kalilinux/kali-rolling with full pentest toolbox
- install.sh: auto-generate credentials, build images, start services
- db/schema.sql: PostgreSQL schema for runs, findings, auth

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Joas A SantosandClaude Opus 4.6 committed 2026-12-04 01:37:20 -03:00
1 parent 1c7a0d0a9b
commit f5dcc3f459
5 files changed
+524

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
# NeuroSploit — main application image
# Multi-stage: build Rust binary + bundle Node web console
# ── Rust build ──────────────────────────────────────────────────────────
FROM rust:1.83-bookworm AS rust-build
WORKDIR /src
COPY neurosploit-rs/ ./
RUN cargo build --release --bin neurosploit \
&& strip target/release/neurosploit \
&& cp target/release/neurosploit /out-neurosploit
# ── Runtime ─────────────────────────────────────────────────────────────
FROM debian:bookworm-slim
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates curl nodejs npm docker.io jq git; \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Rust binary
COPY --from=rust-build /out-neurosploit /usr/local/bin/neurosploit
# Web console
COPY web/ /app/web/
RUN cd /app/web && npm ci --omit=dev 2>/dev/null || true
# Agent skills (markdown)
COPY agents_md/ /app/agents_md/
# DB schema
COPY db/ /app/db/
EXPOSE 8787
# Start the web console (which spawns the harness as needed)
CMD ["node", "/app/web/server.js"]
+66
View File
@@ -0,0 +1,66 @@
# NeuroSploit — Kali worker image
# Isolated per-task container with the full pentest toolbox.
# Runs as unprivileged user, read-only rootfs, no-new-privileges.
FROM kalilinux/kali-rolling
RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
# Core networking
curl wget netcat-openbsd dnsutils iputils-ping iproute2 socat nmap masscan \
# Web scanning
nikto whatweb wapiti dirb gobuster feroxbuster \
# Fuzzing
ffuf wfuzz \
# SQL injection
sqlmap \
# Exploitation frameworks
metasploit-framework exploitdb \
# Password cracking
john hashcat hydra medusa \
# Recon & OSINT
whois fierce dnsenum dnsrecon amass subfinder \
# Web proxying
proxychains4 \
# Binary analysis
binwalk radare2 \
# Scripting
python3 python3-pip python3-venv ruby perl \
# SSL/TLS
sslscan sslyze testssl.sh \
# SMB/Windows
smbclient enum4linux crackmapexec \
# Active Directory
bloodhound impacket-scripts \
# Utils
jq git vim-tiny tmux procps bash-completion ca-certificates \
# Nuclei (from GitHub releases if not in repo)
; \
# Install Go-based tools via go install
apt-get install -y --no-install-recommends golang-go 2>/dev/null || true; \
# Cleanup
apt-get clean; \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*; \
# Create unprivileged user
groupadd -g 10001 pentest; \
useradd -u 10001 -g 10001 -d /home/pentest -m -s /bin/bash pentest; \
mkdir -p /workspace /home/pentest/.local; \
chown -R 10001:10001 /workspace /home/pentest; \
# Remove setuid bits
find / -xdev -perm /6000 -type f -exec chmod a-s {} + 2>/dev/null || true
# Install nuclei & httpx (ProjectDiscovery tools)
RUN pip3 install --break-system-packages pipx 2>/dev/null || true; \
# Try installing from kali repos first, fallback to direct download
apt-get update && apt-get install -y --no-install-recommends nuclei 2>/dev/null; \
rm -rf /var/lib/apt/lists/* || true
USER 10001:10001
WORKDIR /workspace
ENV HOME=/home/pentest \
LANG=C.UTF-8 \
TERM=xterm-256color \
PATH="/home/pentest/.local/bin:$PATH"
CMD ["sleep", "infinity"]
+213
View File
@@ -0,0 +1,213 @@
-- NeuroSploit PostgreSQL schema (single source of truth)
-- Idempotent: safe to run repeatedly (IF NOT EXISTS / OR REPLACE).
-- =====================================================================
-- 0. Common: updated_at trigger
-- =====================================================================
CREATE OR REPLACE FUNCTION set_updated_at() RETURNS trigger AS $$
BEGIN NEW.updated_at = now(); RETURN NEW; END;
$$ LANGUAGE plpgsql;
-- =====================================================================
-- A. Users & authentication
-- =====================================================================
CREATE TABLE IF NOT EXISTS users (
id BIGSERIAL PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL, -- bcrypt hash
role TEXT NOT NULL DEFAULT 'operator'
CHECK (role IN ('admin','operator','viewer')),
active BOOLEAN NOT NULL DEFAULT TRUE,
last_login TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
DROP TRIGGER IF EXISTS trg_users_upd ON users;
CREATE TRIGGER trg_users_upd BEFORE UPDATE ON users
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
CREATE TABLE IF NOT EXISTS sessions (
id TEXT PRIMARY KEY, -- random token
user_id BIGINT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
expires_at TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id);
CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at);
-- =====================================================================
-- B. Targets & assets
-- =====================================================================
CREATE TABLE IF NOT EXISTS targets (
id BIGSERIAL PRIMARY KEY,
url TEXT NOT NULL,
normalized TEXT NOT NULL,
label TEXT,
scope JSONB NOT NULL DEFAULT '{}',
tags TEXT[] NOT NULL DEFAULT '{}',
created_by BIGINT REFERENCES users(id),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE UNIQUE INDEX IF NOT EXISTS uq_targets_normalized ON targets(normalized);
CREATE INDEX IF NOT EXISTS idx_targets_tags ON targets USING GIN(tags);
DROP TRIGGER IF EXISTS trg_targets_upd ON targets;
CREATE TRIGGER trg_targets_upd BEFORE UPDATE ON targets
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
CREATE TABLE IF NOT EXISTS assets (
id BIGSERIAL PRIMARY KEY,
target_id BIGINT NOT NULL REFERENCES targets(id) ON DELETE CASCADE,
type TEXT NOT NULL CHECK (type IN (
'domain','subdomain','ip','service','endpoint','technology'
)),
value TEXT NOT NULL,
port INTEGER CHECK (port BETWEEN 1 AND 65535),
extra JSONB NOT NULL DEFAULT '{}',
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_assets_target ON assets(target_id);
CREATE INDEX IF NOT EXISTS idx_assets_type ON assets(type);
CREATE UNIQUE INDEX IF NOT EXISTS uq_assets_val ON assets(target_id, type, value);
-- =====================================================================
-- C. Runs (engagement executions)
-- =====================================================================
CREATE TABLE IF NOT EXISTS runs (
id BIGSERIAL PRIMARY KEY,
run_id TEXT NOT NULL UNIQUE, -- ns-<ts>-<target>
target_id BIGINT REFERENCES targets(id),
target_url TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'running'
CHECK (status IN ('running','completed','failed','cancelled')),
mode TEXT NOT NULL DEFAULT 'exploit'
CHECK (mode IN ('exploit','recon','container','mobile','infra','chain','full')),
config JSONB NOT NULL DEFAULT '{}',
recon TEXT,
transcript TEXT,
started_by BIGINT REFERENCES users(id),
started_at TIMESTAMPTZ NOT NULL DEFAULT now(),
finished_at TIMESTAMPTZ,
duration_ms BIGINT,
agents_ran TEXT[] NOT NULL DEFAULT '{}',
model_used TEXT,
tokens_in BIGINT DEFAULT 0,
tokens_out BIGINT DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_runs_target ON runs(target_id);
CREATE INDEX IF NOT EXISTS idx_runs_status ON runs(status);
CREATE INDEX IF NOT EXISTS idx_runs_started ON runs(started_at DESC);
DROP TRIGGER IF EXISTS trg_runs_upd ON runs;
CREATE TRIGGER trg_runs_upd BEFORE UPDATE ON runs
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
-- =====================================================================
-- D. Findings
-- =====================================================================
CREATE TABLE IF NOT EXISTS findings (
id BIGSERIAL PRIMARY KEY,
run_id BIGINT NOT NULL REFERENCES runs(id) ON DELETE CASCADE,
target_id BIGINT REFERENCES targets(id),
agent TEXT NOT NULL,
title TEXT NOT NULL,
severity TEXT NOT NULL CHECK (severity IN ('Critical','High','Medium','Low','Info')),
cwe TEXT,
endpoint TEXT,
payload TEXT,
evidence TEXT,
impact TEXT,
remediation TEXT,
confidence REAL NOT NULL DEFAULT 0.5,
validated BOOLEAN NOT NULL DEFAULT FALSE,
review_status TEXT NOT NULL DEFAULT 'pending'
CHECK (review_status IN ('pending','confirmed','false_positive','duplicate','accepted_risk')),
reviewed_by BIGINT REFERENCES users(id),
reviewed_at TIMESTAMPTZ,
votes TEXT,
evidence_data JSONB,
extra JSONB NOT NULL DEFAULT '{}',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_findings_run ON findings(run_id);
CREATE INDEX IF NOT EXISTS idx_findings_target ON findings(target_id);
CREATE INDEX IF NOT EXISTS idx_findings_severity ON findings(severity);
CREATE INDEX IF NOT EXISTS idx_findings_cwe ON findings(cwe) WHERE cwe IS NOT NULL;
CREATE INDEX IF NOT EXISTS idx_findings_status ON findings(review_status);
DROP TRIGGER IF EXISTS trg_findings_upd ON findings;
CREATE TRIGGER trg_findings_upd BEFORE UPDATE ON findings
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
-- =====================================================================
-- E. Skill usage & gaps
-- =====================================================================
CREATE TABLE IF NOT EXISTS skill_usage (
id BIGSERIAL PRIMARY KEY,
ts TIMESTAMPTZ NOT NULL DEFAULT now(),
skill TEXT NOT NULL,
agent_key TEXT,
run_id BIGINT REFERENCES runs(id),
args_len INTEGER DEFAULT 0,
found BOOLEAN NOT NULL DEFAULT TRUE,
duration_ms INTEGER
);
CREATE INDEX IF NOT EXISTS idx_skill_usage_skill ON skill_usage(skill, ts DESC);
CREATE INDEX IF NOT EXISTS idx_skill_usage_run ON skill_usage(run_id);
-- =====================================================================
-- F. Credentials & secrets found during engagement
-- =====================================================================
CREATE TABLE IF NOT EXISTS credentials (
id BIGSERIAL PRIMARY KEY,
run_id BIGINT NOT NULL REFERENCES runs(id) ON DELETE CASCADE,
target_id BIGINT REFERENCES targets(id),
type TEXT NOT NULL CHECK (type IN ('password','hash','token','key','certificate','cookie')),
username TEXT,
value TEXT NOT NULL, -- encrypted at rest
source TEXT,
agent TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_creds_run ON credentials(run_id);
CREATE INDEX IF NOT EXISTS idx_creds_target ON credentials(target_id);
-- =====================================================================
-- G. Reports
-- =====================================================================
CREATE TABLE IF NOT EXISTS reports (
id BIGSERIAL PRIMARY KEY,
run_id BIGINT NOT NULL REFERENCES runs(id) ON DELETE CASCADE,
format TEXT NOT NULL CHECK (format IN ('html','pdf','sarif','json','markdown')),
content TEXT,
file_path TEXT,
created_by BIGINT REFERENCES users(id),
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS idx_reports_run ON reports(run_id);
-- =====================================================================
-- H. Configuration store
-- =====================================================================
CREATE TABLE IF NOT EXISTS config (
key TEXT PRIMARY KEY,
value JSONB NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- =====================================================================
-- I. Activity log (audit trail)
-- =====================================================================
CREATE TABLE IF NOT EXISTS activity_log (
id BIGSERIAL PRIMARY KEY,
ts TIMESTAMPTZ NOT NULL DEFAULT now(),
user_id BIGINT REFERENCES users(id),
action TEXT NOT NULL,
entity TEXT,
entity_id BIGINT,
detail JSONB,
ip TEXT
);
CREATE INDEX IF NOT EXISTS idx_activity_ts ON activity_log(ts DESC);
CREATE INDEX IF NOT EXISTS idx_activity_user ON activity_log(user_id);
+90
View File
@@ -0,0 +1,90 @@
# NeuroSploit — Docker Compose infrastructure
# Usage: cp .env.example .env && ./install.sh && docker compose up -d
#
# Services:
# postgres — persistent storage (findings, runs, assets, skills)
# neurosploit — web console + API + harness orchestrator
# kali-worker — isolated Kali container for running tools (nmap, sqlmap, ffuf, nuclei…)
x-logging: &default-logging
driver: json-file
options:
max-size: "10m"
max-file: "3"
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: ${POSTGRES_USER:-neurosploit}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
POSTGRES_DB: ${POSTGRES_DB:-neurosploit}
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
volumes:
- pgdata:/var/lib/postgresql/data
- ./db/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-neurosploit} -d ${POSTGRES_DB:-neurosploit}"]
interval: 5s
timeout: 3s
retries: 10
ports:
- "127.0.0.1:5432:5432"
logging: *default-logging
restart: unless-stopped
neurosploit:
build:
context: .
dockerfile: Dockerfile
depends_on:
postgres:
condition: service_healthy
environment:
NS_PG_HOST: postgres
NS_PG_PORT: "5432"
NS_PG_USER: ${POSTGRES_USER:-neurosploit}
NS_PG_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}
NS_PG_DBNAME: ${POSTGRES_DB:-neurosploit}
NS_PG_SSLMODE: disable
# LLM providers
ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
OPENAI_API_KEY: ${OPENAI_API_KEY:-}
DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY:-}
GEMINI_API_KEY: ${GEMINI_API_KEY:-}
XAI_API_KEY: ${XAI_API_KEY:-}
GROQ_API_KEY: ${GROQ_API_KEY:-}
OPENROUTER_API_KEY: ${OPENROUTER_API_KEY:-}
# Auth
NS_JWT_SECRET: ${NS_JWT_SECRET:?Set NS_JWT_SECRET in .env}
NS_DEFAULT_USER: ${NS_DEFAULT_USER:-neurosploit}
NS_DEFAULT_PASSWORD: ${NS_DEFAULT_PASSWORD:-}
# Worker
NS_WORKER_IMAGE: neurosploit-kali:local
NS_SANDBOX: ${NS_SANDBOX:-required}
ports:
- "${NS_BIND_ADDR:-127.0.0.1}:${NS_PORT:-8787}:8787"
volumes:
- ./runs:/app/runs
- ./agents_md:/app/agents_md:ro
- /var/run/docker.sock:/var/run/docker.sock
networks:
- default
security_opt:
- "no-new-privileges:true"
logging: *default-logging
restart: unless-stopped
kali-worker:
build:
context: .
dockerfile: Dockerfile.kali
image: neurosploit-kali:local
# Not started directly — the harness creates per-task instances.
# This service only builds the image so it's ready for `docker run`.
profiles:
- build-only
logging: *default-logging
volumes:
pgdata:
Executable
+117
View File
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
# NeuroSploit install script
# Usage: ./install.sh
set -euo pipefail
cd "$(cd "$(dirname "$0")" && pwd)"
info(){ printf '\033[36m[*]\033[0m %s\n' "$*"; }
ok(){ printf '\033[32m[+]\033[0m %s\n' "$*"; }
warn(){ printf '\033[33m[!]\033[0m %s\n' "$*"; }
die(){ printf '\033[31m[x]\033[0m %s\n' "$*" >&2; exit 1; }
rand(){ head -c 24 /dev/urandom | base64 | tr -dc 'A-Za-z0-9' | head -c 24; }
# ── Environment setup ──────────────────────────────────────────────────
if [ ! -f .env ]; then
info "Creating .env from template..."
cp .env.example .env
ok ".env created"
fi
# Normalize CRLF if present
grep -q $'\r' .env 2>/dev/null && sed -i.bak 's/\r$//' .env && rm -f .env.bak && ok ".env converted CRLF → LF"
set_env(){
local key="$1" value="$2" tmp
tmp="$(mktemp)"
awk -v k="$key" -v v="$value" '
$0 ~ "^" k "=" { print k "=" v; found=1; next }
{ print }
END { if (!found) print k "=" v }
' .env > "$tmp"
chmod --reference=.env "$tmp" 2>/dev/null || true
mv "$tmp" .env
}
# Generate secrets if not set
if ! grep -q '^POSTGRES_PASSWORD=[^[:space:]]' .env 2>/dev/null; then
PG_PASS="$(rand)"
set_env POSTGRES_PASSWORD "$PG_PASS"
ok "POSTGRES_PASSWORD generated"
fi
if ! grep -q '^NS_JWT_SECRET=[^[:space:]]' .env 2>/dev/null; then
set_env NS_JWT_SECRET "$(rand)"
ok "NS_JWT_SECRET generated"
fi
# Generate default login password
if ! grep -q '^NS_DEFAULT_PASSWORD=[^[:space:]]' .env 2>/dev/null; then
DEFAULT_PASS="$(rand)"
set_env NS_DEFAULT_PASSWORD "$DEFAULT_PASS"
ok "Default login: neurosploit / $DEFAULT_PASS"
echo ""
printf '\033[1;33m ╔══════════════════════════════════════════════╗\033[0m\n'
printf '\033[1;33m ║ \033[1;37mDefault Login Credentials\033[1;33m ║\033[0m\n'
printf '\033[1;33m ║ \033[0;36mUsername: \033[1;37mneurosploit\033[1;33m ║\033[0m\n'
printf '\033[1;33m ║ \033[0;36mPassword: \033[1;37m%-24s\033[1;33m ║\033[0m\n' "$DEFAULT_PASS"
printf '\033[1;33m ║ \033[0;33mChange after first login!\033[1;33m ║\033[0m\n'
printf '\033[1;33m ╚══════════════════════════════════════════════╝\033[0m\n'
echo ""
else
info "NS_DEFAULT_PASSWORD already set"
fi
# ── Docker check ───────────────────────────────────────────────────────
COMPOSE_CMD=""
if command -v docker >/dev/null 2>&1; then
if docker compose version >/dev/null 2>&1; then
COMPOSE_CMD="docker compose"
elif command -v docker-compose >/dev/null 2>&1; then
COMPOSE_CMD="docker-compose"
fi
fi
if [ -z "$COMPOSE_CMD" ]; then
die "Docker Compose not found. Install Docker: https://docs.docker.com/get-docker/"
fi
ok "Docker Compose: $COMPOSE_CMD"
# ── Build ──────────────────────────────────────────────────────────────
info "Building images (this may take a few minutes on first run)..."
# Build the Kali worker image first
info "Building Kali worker image..."
$COMPOSE_CMD build kali-worker 2>&1 | tail -5
# Build the main app
info "Building NeuroSploit..."
$COMPOSE_CMD build neurosploit 2>&1 | tail -5
ok "Images built"
# ── Start ──────────────────────────────────────────────────────────────
info "Starting services..."
$COMPOSE_CMD up -d postgres neurosploit
# Wait for healthy
info "Waiting for PostgreSQL..."
for i in $(seq 1 30); do
if $COMPOSE_CMD exec -T postgres pg_isready -U "${POSTGRES_USER:-neurosploit}" >/dev/null 2>&1; then
ok "PostgreSQL ready"
break
fi
sleep 1
done
echo ""
ok "NeuroSploit is running!"
echo ""
printf '\033[1;36m Web Console: \033[1;37mhttp://localhost:${NS_PORT:-8787}\033[0m\n'
printf '\033[1;36m Login: \033[1;37mneurosploit / (see above or .env)\033[0m\n'
echo ""
printf '\033[0;33m Commands:\033[0m\n'
printf ' docker compose logs -f # watch logs\n'
printf ' docker compose down # stop\n'
printf ' docker compose up -d # start\n'
echo ""