diff --git a/session1/content/lib/cmd_build.sh b/session1/content/lib/cmd_build.sh index 33c9085..7a76904 100644 --- a/session1/content/lib/cmd_build.sh +++ b/session1/content/lib/cmd_build.sh @@ -129,7 +129,25 @@ _start_lab() { notready=1 fi 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() { diff --git a/session1/content/lib/cmd_doctor.sh b/session1/content/lib/cmd_doctor.sh index f8f130d..dca28da 100644 --- a/session1/content/lib/cmd_doctor.sh +++ b/session1/content/lib/cmd_doctor.sh @@ -131,8 +131,8 @@ $plainAcl = Get-Acl ("AD:\" + (Get-ADUser m.legault).DistinguishedName) 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 (decoy)" - else _d_warn "decoy ACE on t.smith reverted by SDProp (expected)"; fi ;; + ace) if [[ $value -ge 1 ]]; then _d_fail "decoy ACE still on t.smith — a Domain Admin shortcut until SDProp runs" + 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" else _d_fail "stable path missing (ACE on m.legault)"; fi ;; plain_enabled) if [[ $value == True ]]; then _d_ok "m.legault account enabled" diff --git a/session1/content/windows/roles/dc01-post.ps1 b/session1/content/windows/roles/dc01-post.ps1 index 28d7399..be1064d 100644 --- a/session1/content/windows/roles/dc01-post.ps1 +++ b/session1/content/windows/roles/dc01-post.ps1 @@ -92,17 +92,17 @@ try { Set-ADAccountControl -Identity 'j.contractor' -DoesNotRequirePreAuth $true 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 # does not persist the ACE through the AD provider. $targetDn = (Get-ADUser 't.smith').DistinguishedName - $aclCheck = dsacls.exe $targetDn | Select-String 'svc_backup' - if (-not $aclCheck) { - $null = dsacls.exe $targetDn /G '@@NETBIOS@@\svc_backup:GA' - Write-LabLog 'dc01: GenericAll granted to svc_backup over t.smith' - } else { - Write-LabLog 'dc01: svc_backup already has an ACE on t.smith' - } + $null = dsacls.exe $targetDn /G '@@NETBIOS@@\svc_backup:GA' + Write-LabLog 'dc01: GenericAll granted to svc_backup over t.smith (decoy)' + $null = dsacls.exe $targetDn /R '@@NETBIOS@@\svc_backup' + Write-LabLog 'dc01: decoy ACE on t.smith revoked (SDProp would do it within the hour)' # The backup product needs directory replication rights for AD-aware # backups. That is what makes m.legault reach the DC without being in a @@ -110,8 +110,22 @@ try { $svcGroup = Get-ADGroup 'Sauvegarde-AD' $domainAcl = [ADSI]("LDAP://$base") $sd = $domainAcl.ObjectSecurity - foreach ($rightGuid in @('1131f6aa-9c07-11d1-f79f-00c04fc2dcd2', - '1131f6ad-9c07-11d1-f79f-00c04fc2dcd2')) { + $rightGuids = @('1131f6aa-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( $svcGroup.SID, [System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight, @@ -139,13 +153,10 @@ try { Write-LabLog 'dc01: GenericAll granted to svc_backup over m.legault' } - # m.legault reaches DC admin through the server group. - try { - Add-ADGroupMember -Identity 'S-1-5-32-544' -Members 'Serveurs-Admins' -ErrorAction Stop - Write-LabLog 'dc01: Serveurs-Admins added to BUILTIN\Administrators' - } catch { - Write-LabLog 'dc01: Serveurs-Admins already in BUILTIN\Administrators' - } + # Deliberately NOT added to BUILTIN\Administrators: a local admin on the + # DC can read C$ and NTDS.dit, which is a shortcut around the whole ACL + # path. The lab's lesson is the delegated ACE plus the replication right, + # not "the account happens to be a domain-controller admin". # ------------------------------------------------------------ dns try { diff --git a/session1/docs/slides/build_slides.py b/session1/docs/slides/build_slides.py index e182c03..e6132cc 100644 --- a/session1/docs/slides/build_slides.py +++ b/session1/docs/slides/build_slides.py @@ -496,8 +496,8 @@ def build(): box.line.color.rgb = LINE box.shadow.inherit = False 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 " - "chaque heure. C'est le leurre — et la leçon sur les objets protégés.", + "t.smith (Domain Admins) a reçu le même droit, retiré aussitôt : objet protégé, " + "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) footer(s, len(prs.slides)) 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.", "Sauvegarde-AD détient Replicating Directory Changes (All).", "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.", ]) footer(s, len(prs.slides)) diff --git a/session1/docs/slides/norbourg-atelier-1.pptx b/session1/docs/slides/norbourg-atelier-1.pptx index 9fda5c6..c376483 100644 Binary files a/session1/docs/slides/norbourg-atelier-1.pptx and b/session1/docs/slides/norbourg-atelier-1.pptx differ