t.smith is a Domain Admin, therefore a protected object: SDProp rewrites his security descriptor every hour from AdminSDHolder and deletes any ACE not present there. The GenericAll that the lab builds was silently removed by that cycle, so 'bloodyad set password' started failing with the misleading 'oldpass not valid' error. Clearing adminCount on the target takes it out of SDProp's scope while it stays a Domain Admin. Applied in dc01-post.ps1 (guarded) and baked into the baseline. doctor now verifies the invariants that services do not reveal: the ACE, adminCount, SPN, disabled pre-auth, minimum password age, root.txt, the easter-egg TXT and the DHCP scope. This is exactly the drift that was invisible before.
139 lines
5.3 KiB
Bash
139 lines
5.3 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 ./platforms/qemu/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 "lab state"
|
|
_lab_state
|
|
|
|
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)"
|
|
}
|
|
|
|
|
|
# The puzzle has invariants that services do not reveal: a delegated right,
|
|
# an SPN, a disabled pre-authentication, a password policy. SDProp quietly
|
|
# reverts ACEs on protected objects, so this is worth checking every time.
|
|
_lab_state() {
|
|
local out key value
|
|
out=$(backend_ps dc01 '
|
|
Import-Module ActiveDirectory,DnsServer
|
|
$dn = (Get-ADUser t.smith).DistinguishedName
|
|
$acl = Get-Acl ("AD:\" + $dn)
|
|
"ace=" + @($acl.Access | Where-Object { $_.IdentityReference.Value -like "*svc_backup*" }).Count
|
|
"admincount=" + (Get-ADUser t.smith -Properties adminCount).adminCount
|
|
"spn=" + @((Get-ADUser svc_backup -Properties ServicePrincipalNames).ServicePrincipalNames).Count
|
|
"preauth=" + (Get-ADUser j.contractor -Properties DoesNotRequirePreAuth).DoesNotRequirePreAuth
|
|
"minage=" + (Get-ADDefaultDomainPasswordPolicy).MinPasswordAge.TotalHours
|
|
"root=" + (Test-Path C:\flag\root.txt)
|
|
"txt=" + ((Get-DnsServerResourceRecord -ZoneName norbourg.lab -Name yourlove -EA SilentlyContinue) -ne $null)
|
|
"dhcp=" + ((Get-DhcpServerv4Scope -EA SilentlyContinue) -ne $null)
|
|
' 2>/dev/null) || { _d_warn "cannot query DC01 for lab state"; return; }
|
|
|
|
while IFS='=' read -r key value; do
|
|
value=${value//$'\r'/}
|
|
case $key in
|
|
ace) if [[ $value -ge 1 ]]; then _d_ok "delegated right: svc_backup has an ACE on t.smith"
|
|
else _d_fail "delegated right missing (ACE on t.smith)"; fi ;;
|
|
admincount) if [[ $value == 0 ]]; then _d_ok "t.smith outside SDProp (adminCount=0)"
|
|
else _d_warn "adminCount=$value: SDProp will delete the ACE within the hour"; fi ;;
|
|
spn) [[ $value -ge 1 ]] && _d_ok "service account: SPN present" || _d_fail "svc_backup has no SPN" ;;
|
|
preauth) [[ $value == True ]] && _d_ok "pre-auth disabled on j.contractor" || _d_fail "j.contractor still requires pre-auth" ;;
|
|
minage) [[ $value == 0 ]] && _d_ok "minimum password age: 0" || _d_fail "minimum password age is $value h" ;;
|
|
root) [[ $value == True ]] && _d_ok "root.txt on DC01" || _d_fail "root.txt missing" ;;
|
|
txt) [[ $value == True ]] && _d_ok "easter egg TXT record" || _d_warn "yourlove TXT record missing" ;;
|
|
dhcp) [[ $value == True ]] && _d_ok "DHCP scope present" || _d_fail "DHCP scope missing" ;;
|
|
esac
|
|
done <<< "$out"
|
|
}
|