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:
+20
-3
@@ -86,18 +86,35 @@ _wait_for_boot() {
|
||||
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
|
||||
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
|
||||
[[ $name == dc01 ]] && continue
|
||||
if backend_running "$name"; then
|
||||
info " $name already running"
|
||||
else
|
||||
backend_launch "$name" run || fail "$name did not start"
|
||||
backend_launch "$name" run || { fail "$name did not start"; return 1; }
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
cmd_up() {
|
||||
step "start"
|
||||
_start_lab
|
||||
}
|
||||
|
||||
cmd_down() {
|
||||
local name
|
||||
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
|
||||
|
||||
step "start"
|
||||
for name in "${VM_NAMES[@]}"; do
|
||||
backend_launch "$name" run || fail "$name did not start"
|
||||
done
|
||||
_start_lab
|
||||
|
||||
printf '\n'
|
||||
ok "laboratory reset — previous state discarded"
|
||||
|
||||
Reference in New Issue
Block a user