dc01: make the delegated ACL the only way out, and stabilise the state

Three shortcuts and one race made the lab either easier than documented or
non-deterministic:

- Serveurs-Admins was nested in BUILTIN\Administrators on the DC, so
  m.legault was a de-facto domain-controller admin (C$, NTDS.dit) and the
  whole ACL lesson could be skipped. It also made SDProp treat her as
  protected: an hour after provisioning, the intended GenericAll ACE was
  wiped. Removed the nesting; adminCount is explicitly reset.
- the t.smith decoy ACE gave a working path to Domain Admin until SDProp
  ran (up to an hour after a fresh build). The role now grants it and
  revokes it immediately, so the state is deterministic.
- the replication-rights grant stacked duplicate ACEs on every re-run; it
  now removes its own ACEs first.
- up/reset/save returned as soon as WinRM answered, while the directory
  was still starting; doctor right after could report a missing ACE and
  missing replication rights on a healthy lab. They now wait for
  Get-ADDomain on dc01.

doctor: a decoy ACE that is still present is now a failure, not a success.
The deck's wording matches the new behaviour.
This commit is contained in:
2026-10-25 14:05:55 -04:00
parent df5ce2d497
commit 59e2594c1e
5 changed files with 52 additions and 23 deletions
+19 -1
View File
@@ -129,7 +129,25 @@ _start_lab() {
notready=1 notready=1
fi fi
done done
return $(( notready )) if (( notready )); then
warn "skipping the directory check: not every guest answered"
return 1
fi
# WinRM answers before the directory does. A doctor run right after up saw
# "stable path missing" and "replication rights missing" on a healthy lab
# because the DC was still starting AD.
step "wait for the domain"
local deadline=$(( SECONDS + 240 ))
while (( SECONDS < deadline )); do
if backend_ps dc01 'Import-Module ActiveDirectory; (Get-ADDomain).DNSRoot' >/dev/null 2>&1; then
ok "directory services answer"
return 0
fi
sleep 5
done
warn "the domain did not answer in time — check with ./lab.sh doctor"
return 1
} }
cmd_up() { cmd_up() {
+2 -2
View File
@@ -131,8 +131,8 @@ $plainAcl = Get-Acl ("AD:\" + (Get-ADUser m.legault).DistinguishedName)
while IFS='=' read -r key value; do while IFS='=' read -r key value; do
value=${value//$'\r'/} value=${value//$'\r'/}
case $key in case $key in
ace) if [[ $value -ge 1 ]]; then _d_ok "delegated right: svc_backup has an ACE on t.smith (decoy)" ace) if [[ $value -ge 1 ]]; then _d_fail "decoy ACE still on t.smith — a Domain Admin shortcut until SDProp runs"
else _d_warn "decoy ACE on t.smith reverted by SDProp (expected)"; fi ;; else _d_ok "decoy ACE absent on t.smith (protected object, as designed)"; fi ;;
ace_plain) if [[ $value -ge 1 ]]; then _d_ok "stable path: svc_backup has an ACE on m.legault" 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 ;; else _d_fail "stable path missing (ACE on m.legault)"; fi ;;
plain_enabled) if [[ $value == True ]]; then _d_ok "m.legault account enabled" plain_enabled) if [[ $value == True ]]; then _d_ok "m.legault account enabled"
+28 -17
View File
@@ -92,17 +92,17 @@ try {
Set-ADAccountControl -Identity 'j.contractor' -DoesNotRequirePreAuth $true Set-ADAccountControl -Identity 'j.contractor' -DoesNotRequirePreAuth $true
Write-LabLog 'dc01: pre-auth disabled on j.contractor' Write-LabLog 'dc01: pre-auth disabled on j.contractor'
# ACL abuse: svc_backup has GenericAll on a Domain Admin. # ACL abuse: svc_backup has GenericAll on a Domain Admin. SDProp resets a
# protected object's ACL within the hour, so the lab grants the ACE and
# revokes it immediately: a participant who finds it in the first hour
# could reset a Domain Admin's password and skip the intended path.
# dsacls is used instead of the .NET ACL API, which returns success but # dsacls is used instead of the .NET ACL API, which returns success but
# does not persist the ACE through the AD provider. # does not persist the ACE through the AD provider.
$targetDn = (Get-ADUser 't.smith').DistinguishedName $targetDn = (Get-ADUser 't.smith').DistinguishedName
$aclCheck = dsacls.exe $targetDn | Select-String 'svc_backup' $null = dsacls.exe $targetDn /G '@@NETBIOS@@\svc_backup:GA'
if (-not $aclCheck) { Write-LabLog 'dc01: GenericAll granted to svc_backup over t.smith (decoy)'
$null = dsacls.exe $targetDn /G '@@NETBIOS@@\svc_backup:GA' $null = dsacls.exe $targetDn /R '@@NETBIOS@@\svc_backup'
Write-LabLog 'dc01: GenericAll granted to svc_backup over t.smith' Write-LabLog 'dc01: decoy ACE on t.smith revoked (SDProp would do it within the hour)'
} else {
Write-LabLog 'dc01: svc_backup already has an ACE on t.smith'
}
# The backup product needs directory replication rights for AD-aware # The backup product needs directory replication rights for AD-aware
# backups. That is what makes m.legault reach the DC without being in a # backups. That is what makes m.legault reach the DC without being in a
@@ -110,8 +110,22 @@ try {
$svcGroup = Get-ADGroup 'Sauvegarde-AD' $svcGroup = Get-ADGroup 'Sauvegarde-AD'
$domainAcl = [ADSI]("LDAP://$base") $domainAcl = [ADSI]("LDAP://$base")
$sd = $domainAcl.ObjectSecurity $sd = $domainAcl.ObjectSecurity
foreach ($rightGuid in @('1131f6aa-9c07-11d1-f79f-00c04fc2dcd2', $rightGuids = @('1131f6aa-9c07-11d1-f79f-00c04fc2dcd2',
'1131f6ad-9c07-11d1-f79f-00c04fc2dcd2')) { '1131f6ad-9c07-11d1-f79f-00c04fc2dcd2')
$sidText = $svcGroup.SID.Value
$nameText = '@@NETBIOS@@\Sauvegarde-AD'
# Idempotent: a re-run must not stack duplicate ACEs on the domain.
foreach ($ace in @($sd.Access)) {
if ($ace.IsInherited) { continue }
$trustee = $ace.IdentityReference.Value
if (($trustee -eq $sidText -or $trustee -eq $nameText) -and
($rightGuids -contains $ace.ObjectType.Guid.ToString())) {
[void]$sd.RemoveAccessRule($ace)
}
}
foreach ($rightGuid in $rightGuids) {
$rule = New-Object System.DirectoryServices.ActiveDirectoryAccessRule( $rule = New-Object System.DirectoryServices.ActiveDirectoryAccessRule(
$svcGroup.SID, $svcGroup.SID,
[System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight, [System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight,
@@ -139,13 +153,10 @@ try {
Write-LabLog 'dc01: GenericAll granted to svc_backup over m.legault' Write-LabLog 'dc01: GenericAll granted to svc_backup over m.legault'
} }
# m.legault reaches DC admin through the server group. # Deliberately NOT added to BUILTIN\Administrators: a local admin on the
try { # DC can read C$ and NTDS.dit, which is a shortcut around the whole ACL
Add-ADGroupMember -Identity 'S-1-5-32-544' -Members 'Serveurs-Admins' -ErrorAction Stop # path. The lab's lesson is the delegated ACE plus the replication right,
Write-LabLog 'dc01: Serveurs-Admins added to BUILTIN\Administrators' # not "the account happens to be a domain-controller admin".
} catch {
Write-LabLog 'dc01: Serveurs-Admins already in BUILTIN\Administrators'
}
# ------------------------------------------------------------ dns # ------------------------------------------------------------ dns
try { try {
+3 -3
View File
@@ -496,8 +496,8 @@ def build():
box.line.color.rgb = LINE box.line.color.rgb = LINE
box.shadow.inherit = False box.shadow.inherit = False
textbox(s, 1.15, 4.8, 11.1, 0.9, textbox(s, 1.15, 4.8, 11.1, 0.9,
"t.smith (Domain Admins) a reçu le même droit : objet protégé, SDProp l'efface " "t.smith (Domain Admins) a reçu le même droit, retiré aussitôt : objet protégé, "
"chaque heure. C'est le leurre — et la leçon sur les objets protégés.", "SDProp l'aurait effacé dans l'heure. C'est le leurre — et la leçon sur les objets protégés.",
size=14, color=INK, line_spacing=1.15) size=14, color=INK, line_spacing=1.15)
footer(s, len(prs.slides)) footer(s, len(prs.slides))
notes(s, "Ce n'est pas un exploit : c'est un droit accordé, et le compte qui le porte " notes(s, "Ce n'est pas un exploit : c'est un droit accordé, et le compte qui le porte "
@@ -510,7 +510,7 @@ def build():
"m.legault est membre de Sauvegarde-AD.", "m.legault est membre de Sauvegarde-AD.",
"Sauvegarde-AD détient Replicating Directory Changes (All).", "Sauvegarde-AD détient Replicating Directory Changes (All).",
"secretsdump -just-dc-user krbtgt : le hash du compte krbtgt.", "secretsdump -just-dc-user krbtgt : le hash du compte krbtgt.",
"m.legault n'est pas Domain Admin au sens strict.", "m.legault n'est ni Domain Admin ni administratrice du DC.",
"Et pourtant : le domaine est compromis.", "Et pourtant : le domaine est compromis.",
]) ])
footer(s, len(prs.slides)) footer(s, len(prs.slides))
Binary file not shown.