BUILTIN\Administrators is itself a protected group, so adding Serveurs-Admins to it made m.legault transitively protected too: SDProp then wiped both ACEs and reset adminCount. doctor caught it. The durable fix is the one that works in a real domain: the ACE lives in AdminSDHolder, which SDProp copies onto protected objects every hour, so it is re-applied rather than deleted. The adminCount workaround is gone. Lore gains a 2021 note explaining exactly this, in the voice of the instructor who hit it: the delegation kept vanishing, the vendor explained AdminSDHolder, the right was moved there and stopped disappearing.
155 lines
6.7 KiB
Bash
155 lines
6.7 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
|
|
$plainAcl = Get-Acl ("AD:\" + (Get-ADUser m.legault).DistinguishedName)
|
|
"ace_plain=" + @($plainAcl.Access | Where-Object { $_.IdentityReference.Value -like "*svc_backup*" }).Count
|
|
"plain_enabled=" + (Get-ADUser m.legault).Enabled
|
|
"dcadmin=" + ((Get-ADGroupMember "S-1-5-32-544").Name -contains "Serveurs-Admins")
|
|
"sdh=" + @((dsacls.exe ("CN=AdminSDHolder,CN=System," + (Get-ADDomain).DistinguishedName) | Select-String "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)
|
|
"kali_res=" + @((Get-DhcpServerv4Reservation -ScopeId 10.10.10.0 -EA SilentlyContinue) | Where-Object { $_.IPAddress -eq "10.10.10.101" }).Count
|
|
' 2>/dev/null) || { _d_warn "cannot query DC01 for lab state"; return; }
|
|
|
|
local sdh_ok=0
|
|
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 ;;
|
|
ace_plain) if [[ $value -ge 1 ]]; then _d_ok "stable path: svc_backup has an ACE on m.legault"
|
|
else _d_fail "stable path missing (ACE on m.legault)"; fi ;;
|
|
plain_enabled) if [[ $value == True ]]; then _d_ok "m.legault account enabled"
|
|
else _d_fail "m.legault is disabled — the path is dead"; fi ;;
|
|
dcadmin) if [[ $value == True ]]; then _d_ok "Serveurs-Admins is DC local admin"
|
|
else _d_fail "Serveurs-Admins is not in BUILTIN\Administrators"; fi ;;
|
|
sdh) if [[ $value -ge 1 ]]; then _d_ok "AdminSDHolder carries the delegation (SDProp-proof)"; sdh_ok=1
|
|
else _d_warn "delegation not anchored in AdminSDHolder"; fi ;;
|
|
admincount) if (( sdh_ok )) || [[ $value == 0 ]]; then _d_ok "protected objects cannot strip the ACE"
|
|
else _d_warn "adminCount=$value and no AdminSDHolder anchor"; 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" ;;
|
|
kali_res) [[ $value -ge 1 ]] && _d_ok "DHCP reservation 10.10.10.101" || _d_fail "Kali reservation missing" ;;
|
|
esac
|
|
done <<< "$out"
|
|
}
|