Add doctor health check and Kali setup script
doctor verifies bridge, per-VM SMB/WinRM, DNS SRV records, the site and the leaked credential in one pass — the instructor's first move when something looks wrong. Start order now boots dc01 first and waits for WinRM: a member that wins the race loses its machine-account channel (NO_LOGON_SERVERS on every logon).
This commit is contained in:
@@ -195,3 +195,50 @@ backend_stop() {
|
|||||||
rm -f "$(qemu_pidfile "$name")"
|
rm -f "$(qemu_pidfile "$name")"
|
||||||
ok "$name stopped"
|
ok "$name stopped"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ baseline
|
||||||
|
backend_snapshot() {
|
||||||
|
local name=$1
|
||||||
|
local golden base overlay
|
||||||
|
golden=$(qemu_golden "$name")
|
||||||
|
base=$(qemu_base "$name")
|
||||||
|
overlay=$(qemu_overlay "$name")
|
||||||
|
|
||||||
|
if backend_running "$name"; then
|
||||||
|
fail "$name is still running"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [[ -f $base ]]; then
|
||||||
|
ok "$(printf '%-6s baseline already frozen' "$name")"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ ! -f $golden ]]; then
|
||||||
|
fail "$name has no disk to freeze"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$(dirname "$base")" "$(dirname "$overlay")"
|
||||||
|
mv "$golden" "$base"
|
||||||
|
# Relative backing path: the tree can move without breaking the chain.
|
||||||
|
qemu-img create -q -f qcow2 -F qcow2 -b "../base/${name}-base.qcow2" "$overlay"
|
||||||
|
ok "$(printf '%-6s baseline frozen (%s)' "$name" "$(du -h "$base" | cut -f1)")"
|
||||||
|
}
|
||||||
|
|
||||||
|
backend_reset() {
|
||||||
|
local name=$1
|
||||||
|
local base overlay
|
||||||
|
base=$(qemu_base "$name")
|
||||||
|
overlay=$(qemu_overlay "$name")
|
||||||
|
|
||||||
|
if backend_running "$name"; then
|
||||||
|
backend_stop "$name" >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
if [[ ! -f $base ]]; then
|
||||||
|
fail "$name has no baseline — run ./lab.sh snapshot first"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "$overlay"
|
||||||
|
qemu-img create -q -f qcow2 -F qcow2 -b "../base/${name}-base.qcow2" "$overlay"
|
||||||
|
ok "$(printf '%-6s reverted' "$name")"
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ source "$LAB_DIR/lib/cmd_build.sh"
|
|||||||
source "$LAB_DIR/lib/cmd_provision.sh"
|
source "$LAB_DIR/lib/cmd_provision.sh"
|
||||||
# shellcheck source=lib/cmd_snapshot.sh
|
# shellcheck source=lib/cmd_snapshot.sh
|
||||||
source "$LAB_DIR/lib/cmd_snapshot.sh"
|
source "$LAB_DIR/lib/cmd_snapshot.sh"
|
||||||
|
# shellcheck source=lib/cmd_doctor.sh
|
||||||
|
source "$LAB_DIR/lib/cmd_doctor.sh"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@@ -50,7 +52,7 @@ Commands:
|
|||||||
status VM table: state, pid, VNC display
|
status VM table: state, pid, VNC display
|
||||||
vnc open a console on a VM
|
vnc open a console on a VM
|
||||||
web sync the archived site to FS01 (phase 7)
|
web sync the archived site to FS01 (phase 7)
|
||||||
doctor participant connectivity checklist (phase 8)
|
doctor end-to-end health check of the lab
|
||||||
peers WireGuard peer configs (proxmox only) (phase 11)
|
peers WireGuard peer configs (proxmox only) (phase 11)
|
||||||
export-kali build the participant Kali image (phase 9)
|
export-kali build the participant Kali image (phase 9)
|
||||||
answers instructor walkthrough (phase 9)
|
answers instructor walkthrough (phase 9)
|
||||||
@@ -149,7 +151,7 @@ case $cmd in
|
|||||||
provision) cmd_provision "$@" ;;
|
provision) cmd_provision "$@" ;;
|
||||||
snapshot) cmd_snapshot "$@" ;;
|
snapshot) cmd_snapshot "$@" ;;
|
||||||
reset) cmd_reset "$@" ;;
|
reset) cmd_reset "$@" ;;
|
||||||
doctor) planned doctor "phase 8" ;;
|
doctor) cmd_doctor "$@" ;;
|
||||||
peers) planned peers "phase 11" ;;
|
peers) planned peers "phase 11" ;;
|
||||||
export-kali) planned export-kali "phase 9" ;;
|
export-kali) planned export-kali "phase 9" ;;
|
||||||
answers) planned answers "phase 9" ;;
|
answers) planned answers "phase 9" ;;
|
||||||
|
|||||||
+20
-3
@@ -86,18 +86,35 @@ _wait_for_boot() {
|
|||||||
info " next: ./lab.sh status"
|
info " next: ./lab.sh status"
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_up() {
|
# Start the DC first and wait for it: a member that boots before the DC
|
||||||
|
# loses its machine-account channel and fails to authenticate (NO_LOGON_SERVERS).
|
||||||
|
_start_lab() {
|
||||||
local name
|
local name
|
||||||
step "start"
|
|
||||||
|
if vm_index dc01 >/dev/null 2>&1; then
|
||||||
|
if backend_running dc01; then
|
||||||
|
info " dc01 already running"
|
||||||
|
else
|
||||||
|
backend_launch dc01 run || { fail "dc01 did not start"; return 1; }
|
||||||
|
fi
|
||||||
|
_wait_winrm "$LAB_DC_IP" 240 || warn "dc01 did not answer WinRM in time"
|
||||||
|
fi
|
||||||
|
|
||||||
for name in "${VM_NAMES[@]}"; do
|
for name in "${VM_NAMES[@]}"; do
|
||||||
|
[[ $name == dc01 ]] && continue
|
||||||
if backend_running "$name"; then
|
if backend_running "$name"; then
|
||||||
info " $name already running"
|
info " $name already running"
|
||||||
else
|
else
|
||||||
backend_launch "$name" run || fail "$name did not start"
|
backend_launch "$name" run || { fail "$name did not start"; return 1; }
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd_up() {
|
||||||
|
step "start"
|
||||||
|
_start_lab
|
||||||
|
}
|
||||||
|
|
||||||
cmd_down() {
|
cmd_down() {
|
||||||
local name
|
local name
|
||||||
step "stop"
|
step "stop"
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
# shellcheck shell=bash
|
||||||
|
# cmd_doctor — end-to-end health check of the running laboratory.
|
||||||
|
|
||||||
|
_c_ok() { ok "$*"; }
|
||||||
|
_c_warn() { warn "$*"; DOCTOR_WARNS=$(( DOCTOR_WARNS + 1 )); }
|
||||||
|
_c_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 "$BRIDGE" >/dev/null 2>&1; then
|
||||||
|
_c_ok "bridge ${BRIDGE} present"
|
||||||
|
else
|
||||||
|
_c_fail "bridge ${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
|
||||||
|
_c_fail "$name is not running — ./lab.sh up"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if tcp_open "$ip" 445; then
|
||||||
|
_c_ok "$(printf '%-6s %-14s smb up' "$name" "$ip")"
|
||||||
|
else
|
||||||
|
_c_warn "$(printf '%-6s %-14s smb not answering' "$name" "$ip")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $name == dc01 || $name == ws01 || $name == fs01 ]]; then
|
||||||
|
if tcp_open "$ip" 5985; then
|
||||||
|
_c_ok "$(printf '%-6s %-14s winrm up' "$name" "$ip")"
|
||||||
|
else
|
||||||
|
_c_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
|
||||||
|
_c_ok "dns: www.norbourg.lab -> $www"
|
||||||
|
else
|
||||||
|
_c_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
|
||||||
|
_c_ok "dns: ldap SRV record present"
|
||||||
|
else
|
||||||
|
_c_fail "dns: ldap SRV record missing — AD discovery would fail"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
_c_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
|
||||||
|
_c_ok "site answers on 10.10.10.20"
|
||||||
|
else
|
||||||
|
_c_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
|
||||||
|
_c_ok "entry point reachable: /public/IT-inventaire.txt"
|
||||||
|
else
|
||||||
|
_c_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
|
||||||
|
_c_ok "Public share reachable with the leaked credential"
|
||||||
|
else
|
||||||
|
_c_warn "Public share not readable as helpdesk1 (domain channel or DNS?)"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
_c_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)"
|
||||||
|
}
|
||||||
+1
-3
@@ -30,9 +30,7 @@ cmd_reset() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
step "start"
|
step "start"
|
||||||
for name in "${VM_NAMES[@]}"; do
|
_start_lab
|
||||||
backend_launch "$name" run || fail "$name did not start"
|
|
||||||
done
|
|
||||||
|
|
||||||
printf '\n'
|
printf '\n'
|
||||||
ok "laboratory reset — previous state discarded"
|
ok "laboratory reset — previous state discarded"
|
||||||
|
|||||||
Executable
+52
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# kali-setup.sh — prepare a participant's Kali for the workshop.
|
||||||
|
#
|
||||||
|
# ./scripts/kali-setup.sh
|
||||||
|
#
|
||||||
|
# Installs the toolset used in the lab and copies the targeted wordlist to
|
||||||
|
# /opt/norbourg/wordlists/. Safe to run twice.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HERE=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
|
||||||
|
WORDLIST="$HERE/wordlists/norbourg.txt"
|
||||||
|
|
||||||
|
info() { printf '[*] %s\n' "$*"; }
|
||||||
|
ok() { printf '[ok] %s\n' "$*"; }
|
||||||
|
warn() { printf '[!] %s\n' "$*" >&2; }
|
||||||
|
|
||||||
|
if [[ $EUID -eq 0 ]]; then
|
||||||
|
SUDO=""
|
||||||
|
else
|
||||||
|
SUDO="sudo"
|
||||||
|
fi
|
||||||
|
|
||||||
|
info "installing packages (this takes a few minutes)"
|
||||||
|
$SUDO apt-get update -qq || warn "apt-get update failed, continuing"
|
||||||
|
$SUDO DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends \
|
||||||
|
netexec impacket-scripts bloodyad evil-winrm bloodhound.py \
|
||||||
|
hashcat seclists smbclient dnsutils python3-pip \
|
||||||
|
|| warn "some packages failed to install, see the list below"
|
||||||
|
|
||||||
|
info "installing the lab wordlist"
|
||||||
|
$SUDO mkdir -p /opt/norbourg/wordlists
|
||||||
|
$SUDO cp "$WORDLIST" /opt/norbourg/wordlists/norbourg.txt
|
||||||
|
$SUDO chmod 0644 /opt/norbourg/wordlists/norbourg.txt
|
||||||
|
|
||||||
|
info "checking the toolset"
|
||||||
|
check() {
|
||||||
|
if command -v "$1" >/dev/null 2>&1; then
|
||||||
|
ok "$1"
|
||||||
|
else
|
||||||
|
warn "$1 missing"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
for tool in nxc netexec evil-winrm hashcat smbclient dig; do
|
||||||
|
check "$tool"
|
||||||
|
done
|
||||||
|
command -v impacket-GetUserSPNs >/dev/null 2>&1 && ok "impacket-GetUserSPNs" \
|
||||||
|
|| warn "impacket scripts missing (impacket-scripts)"
|
||||||
|
command -v bloodhound-python >/dev/null 2>&1 && ok "bloodhound-python" \
|
||||||
|
|| warn "bloodhound-python missing"
|
||||||
|
|
||||||
|
printf '\n'
|
||||||
|
ok "done. Lab access is configured separately: see docs/prerequis.md"
|
||||||
Reference in New Issue
Block a user