Files
pentest.intro/content/lib/cmd_doctor.sh
T
quoije 890dd58700 Split into qemu and proxmox platforms over a shared content tree
platforms/qemu and platforms/proxmox each have their own lab.sh and
lab.conf; content/ holds everything shared (roles, seed, site, helpers).
The dispatcher, preflight and command implementations are common and take
platform differences from the backend.

Proxmox backend: qm create with q35/SATA/e1000, ISOs and seed ISOs in an
ISO storage, provisioning over qm guest exec (no Python packages needed on
the host), template + clone for reset, and peers/ to emit WireGuard configs.
The role scripts now ride on the seed ISO, so provisioning transfers nothing.

build-bundle.sh produces a self-contained tarball per platform, for hosts
that cannot reach the git server.

Both configs are generic: no absolute path from this machine remains.
2026-10-22 19:23:16 -04:00

99 lines
3.0 KiB
Bash

# shellcheck shell=bash
# cmd_doctor — end-to-end health check of the running laboratory.
_d_ok() { ok "$*"; }
_d_warn() { warn "$*"; DOCTOR_WARNS=$(( DOCTOR_WARNS + 1 )); }
_d_fail() { fail "$*"; DOCTOR_FAILS=$(( DOCTOR_FAILS + 1 )); }
cmd_doctor() {
DOCTOR_FAILS=0
DOCTOR_WARNS=0
local i name ip
step "host"
if ip link show "$LAB_BRIDGE" >/dev/null 2>&1; then
_d_ok "bridge ${LAB_BRIDGE} present"
else
_d_fail "bridge ${LAB_BRIDGE} missing — run sudo ./scripts/setup-network.sh"
fi
step "machines"
for i in "${!VM_NAMES[@]}"; do
name=${VM_NAMES[$i]}
ip=${VM_IPS[$i]}
if ! backend_running "$name"; then
_d_fail "$name is not running — ./lab.sh up"
continue
fi
if tcp_open "$ip" 445; then
_d_ok "$(printf '%-6s %-14s smb up' "$name" "$ip")"
else
_d_warn "$(printf '%-6s %-14s smb not answering' "$name" "$ip")"
fi
if [[ $name == dc01 || $name == ws01 || $name == fs01 ]]; then
if tcp_open "$ip" 5985; then
_d_ok "$(printf '%-6s %-14s winrm up' "$name" "$ip")"
else
_d_warn "$(printf '%-6s %-14s winrm not answering' "$name" "$ip")"
fi
fi
done
step "domain"
if have_cmd dig; then
local www
www=$(dig +short +time=2 +tries=1 "@$LAB_DC_IP" www.norbourg.lab 2>/dev/null | head -1)
if [[ $www == 10.10.10.20 ]]; then
_d_ok "dns: www.norbourg.lab -> $www"
else
_d_fail "dns: www.norbourg.lab did not resolve via ${LAB_DC_IP} (got '${www:-nothing}')"
fi
local srv
srv=$(dig +short +time=2 +tries=1 "@$LAB_DC_IP" SRV _ldap._tcp.dc._msdcs.norbourg.lab 2>/dev/null | head -1)
if [[ -n $srv ]]; then
_d_ok "dns: ldap SRV record present"
else
_d_fail "dns: ldap SRV record missing — AD discovery would fail"
fi
else
_d_warn "dig not installed, DNS checks skipped"
fi
step "web"
local code
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://10.10.10.20/" 2>/dev/null || true)
if [[ $code == 200 ]]; then
_d_ok "site answers on 10.10.10.20"
else
_d_fail "site not answering (${code:-timeout}) — ./lab.sh web --sync"
fi
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://10.10.10.20/public/IT-inventaire.txt" 2>/dev/null || true)
if [[ $code == 200 ]]; then
_d_ok "entry point reachable: /public/IT-inventaire.txt"
else
_d_fail "entry point missing (${code:-timeout})"
fi
step "share"
if have_cmd smbclient; then
if smbclient //10.10.10.20/Public -U 'NORBOURG\helpdesk1%Welcome2024!' -c 'ls' 2>/dev/null | grep -q 'IT-inventaire'; then
_d_ok "Public share reachable with the leaked credential"
else
_d_warn "Public share not readable as helpdesk1 (domain channel or DNS?)"
fi
else
_d_warn "smbclient not installed, share check skipped"
fi
printf '\n'
if (( DOCTOR_FAILS )); then
fail "${DOCTOR_FAILS} problem(s), ${DOCTOR_WARNS} warning(s)"
return 1
fi
ok "laboratory healthy · ${DOCTOR_WARNS} warning(s)"
}