Fix the ACL being reverted by SDProp, and make doctor check the puzzle
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.
This commit is contained in:
@@ -62,6 +62,9 @@ cmd_doctor() {
|
|||||||
_d_warn "dig not installed, DNS checks skipped"
|
_d_warn "dig not installed, DNS checks skipped"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
step "lab state"
|
||||||
|
_lab_state
|
||||||
|
|
||||||
step "web"
|
step "web"
|
||||||
local code
|
local code
|
||||||
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://10.10.10.20/" 2>/dev/null || true)
|
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://10.10.10.20/" 2>/dev/null || true)
|
||||||
@@ -96,3 +99,40 @@ cmd_doctor() {
|
|||||||
fi
|
fi
|
||||||
ok "laboratory healthy · ${DOCTOR_WARNS} warning(s)"
|
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"
|
||||||
|
}
|
||||||
|
|||||||
@@ -95,6 +95,17 @@ try {
|
|||||||
Write-LabLog 'dc01: svc_backup already has an ACE on t.smith'
|
Write-LabLog 'dc01: svc_backup already has an ACE on t.smith'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# t.smith is a Domain Admin, therefore a "protected" object: SDProp resets
|
||||||
|
# his security descriptor every hour and deletes any ACE not present in
|
||||||
|
# AdminSDHolder. Clearing adminCount takes him out of SDProp's scope while
|
||||||
|
# leaving his Domain Admins membership intact.
|
||||||
|
try {
|
||||||
|
Set-ADObject -Identity 't.smith' -Replace @{ adminCount = 0 } -ErrorAction Stop
|
||||||
|
Write-LabLog 'dc01: t.smith excluded from SDProp (adminCount=0)'
|
||||||
|
} catch {
|
||||||
|
Write-LabLog "dc01: could not clear adminCount ($($_.Exception.Message))"
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------ dns
|
# ------------------------------------------------------------ dns
|
||||||
try {
|
try {
|
||||||
Add-DnsServerResourceRecordA -Name 'www' -ZoneName '@@DOMAIN@@' -IPv4Address '10.10.10.20' -ErrorAction Stop
|
Add-DnsServerResourceRecordA -Name 'www' -ZoneName '@@DOMAIN@@' -IPv4Address '10.10.10.20' -ErrorAction Stop
|
||||||
|
|||||||
Reference in New Issue
Block a user