Escalate through explicit replication rights, not a protected group

The AdminSDHolder anchor worked but handed svc_backup GenericAll over every
protected object, including Domain Admins — a shortcut that undermined the
intended lesson.

New design, matching how backup products actually get AD access:
  svc_backup --GenericAll--> m.legault (plain user, never protected)
  m.legault in Sauvegarde-AD, which holds Replicating Directory Changes
  and ...All on the domain — the vendor requirement for AD-aware backups

Nothing on that path is a protected object, so SDProp has nothing to rewrite.
t.smith stays as the decoy whose ACE is reverted hourly.

The flag moves to C:\Sauvegarde, shared as Sauvegarde\$ readable by the
backup group: C\$ is admin-only, so a plain account could never fetch it.

web --sync now mirrors instead of merging (it used to leave deleted files
served forever) and clears the staging folder that smbclot only adds to.
Lore 2016/2021 rewritten around the replication requirement.
This commit is contained in:
2026-10-24 14:06:21 -04:00
parent 5e9be0a0b3
commit 122aeed6cb
7 changed files with 107 additions and 61 deletions
+33 -25
View File
@@ -101,54 +101,62 @@ cmd_doctor() {
}
# 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.
# The puzzle has invariants that services do not reveal: a delegated right, an
# SPN, disabled pre-authentication, a password policy, replication rights.
# SDProp quietly reverts ACEs on protected objects, so the target must stay
# outside protected groups — 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)
$dom = Get-ADDomain
$base = $dom.DistinguishedName
$acl = Get-Acl ("AD:\" + (Get-ADUser t.smith).DistinguishedName)
"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
"mcount=" + (Get-ADUser m.legault -Properties adminCount).adminCount
"repl=" + @((dsacls.exe $base | Select-String "Sauvegarde-AD")).Count
"share=" + ((Get-SmbShare -Name "Sauvegarde$" -ErrorAction SilentlyContinue) -ne $null)
"root=" + (Test-Path C:\Sauvegarde\root.txt)
"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) 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_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" ;;
mcount) if [[ -z $value || $value == 0 ]]; then _d_ok "m.legault outside protected groups"
else _d_fail "adminCount=$value: m.legault is protected, SDProp will wipe the ACE"; fi ;;
repl) if [[ $value -ge 2 ]]; then _d_ok "Sauvegarde-AD holds replication rights (DCSync)"
else _d_fail "replication rights missing on Sauvegarde-AD"; fi ;;
share) if [[ $value == True ]]; then _d_ok "backup share with the flag"
else _d_fail "Sauvegarde\$ share missing"; fi ;;
root) if [[ $value == True ]]; then _d_ok "root.txt reachable through the backup share"
else _d_fail "root.txt missing"; fi ;;
spn) if [[ $value -ge 1 ]]; then _d_ok "service account: SPN present"
else _d_fail "svc_backup has no SPN"; fi ;;
preauth) if [[ $value == True ]]; then _d_ok "pre-auth disabled on j.contractor"
else _d_fail "j.contractor still requires pre-auth"; fi ;;
minage) if [[ $value == 0 ]]; then _d_ok "minimum password age: 0"
else _d_fail "minimum password age is $value h"; fi ;;
txt) if [[ $value == True ]]; then _d_ok "easter egg TXT record"
else _d_warn "yourlove TXT record missing"; fi ;;
dhcp) if [[ $value == True ]]; then _d_ok "DHCP scope present"
else _d_fail "DHCP scope missing"; fi ;;
kali_res) if [[ $value -ge 1 ]]; then _d_ok "DHCP reservation 10.10.10.101"
else _d_fail "Kali reservation missing"; fi ;;
esac
done <<< "$out"
}
+14 -1
View File
@@ -51,6 +51,11 @@ _web_sync() {
tcp_open "$ip" 445 || die "fs01 SMB is not reachable — is it provisioned?"
have_cmd smbclient || die "smbclient is required to push the site"
# Clear the staging folder first: smbclient only adds, so an old file would
# otherwise come back on every sync.
backend_ready fs01 120 >/dev/null 2>&1 || true
backend_ps fs01 "Remove-Item -Recurse -Force -ErrorAction SilentlyContinue 'C:\\norbourg\\site'" >/dev/null 2>&1 || true
# Bulk copy goes over SMB: WinRM caps the command line at ~8 KB.
smbclient "//$ip/C\$" -W "$NETBIOS" \
-U "$LAB_USER%$LAB_ADMIN_PASSWORD" \
@@ -58,7 +63,15 @@ _web_sync() {
>/dev/null 2>&1 || true
backend_ready fs01 300 || die "fs01 did not answer"
backend_ps fs01 "Copy-Item -Path 'C:\\norbourg\\site\\*' -Destination 'C:\\inetpub\\wwwroot' -Recurse -Force; Test-Path 'C:\\inetpub\\wwwroot\\index.html'" \
# Mirror, not merge: remove everything except the web.config that fs01.ps1
# places in public/, otherwise files deleted from the repo keep being served.
backend_ps fs01 "
Get-ChildItem 'C:\inetpub\wwwroot' -Force | Where-Object { \$_.Name -ne 'public' } |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Get-ChildItem 'C:\inetpub\wwwroot\public' -Force | Where-Object { \$_.Name -ne 'web.config' } |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item -Path 'C:\norbourg\site\*' -Destination 'C:\inetpub\wwwroot' -Recurse -Force
Test-Path 'C:\inetpub\wwwroot\index.html'" \
| grep -qi true || die "copy failed on fs01"
ok "site published to C:\\inetpub\\wwwroot"
@@ -1,8 +1,11 @@
Note - 2016-01-12
-----------------
m.legault administre le controleur de domaine depuis toujours.
Le produit de sauvegarde doit lire l'annuaire pour les sauvegardes
"conscientes d'AD". Le vendeur exige les droits de replication.
Plutot que de la mettre dans Domain Admins, on a ajoute le groupe
"Serveurs-Admins" aux Administrateurs locaux de DC01.
On a cree le groupe "Sauvegarde-AD" et donne a ce groupe les deux
droits de replication sur le domaine. m.legault y est : c'est elle
qui lance les sauvegardes.
C'est equivalent en pratique, mais ca passe mieux en audit.
C'est large pour un compte utilisateur, mais c'etait plus simple que
de creer un compte de service de plus.
@@ -1,11 +0,0 @@
Note - 2021-02-03
-----------------
La delegation de sauvegarde sur les comptes d'administrateurs
disparaissait regulierement, sans explication.
Le vendeur a explique que Windows remet les permissions des comptes
proteges a jour toutes les heures, a partir d'un objet modele appele
AdminSDHolder.
Solution : on a mis le droit directement dans AdminSDHolder.
Depuis, il revient tout seul.
@@ -0,0 +1,13 @@
Note - 2021-02-03
-----------------
Revue annuelle des acces.
On a verifie que le groupe Sauvegarde-AD dispose bien des droits de
replication exiges par le produit. Personne ne se souvient pourquoi
m.legault est dans ce groupe plutot qu'un compte de service dedie,
mais tout fonctionne.
Le dossier de depot de la sauvegarde (partage Sauvegarde$) est lisible
par ce groupe, c'est necessaire pour les restaurations.
A revoir.
+1 -1
View File
@@ -10,4 +10,4 @@ Les dates sont celles des fichiers d'origine.
2011/ deploiement de l'agent sur les postes
2016/ administration du controleur de domaine
2019/ arrivee de t.smith
2021/ delegation ancree dans AdminSDHolder
2021/ revue annuelle des acces
+36 -16
View File
@@ -63,6 +63,7 @@ try {
'TI-Support' = @('s.bergeron', 'helpdesk1')
'WS Admins' = @('svc_backup')
'Serveurs-Admins' = @('m.legault')
'Sauvegarde-AD' = @('m.legault')
}
foreach ($name in $groups.Keys) {
if (-not (Get-ADGroup -Filter "Name -eq '$name'" -ErrorAction SilentlyContinue)) {
@@ -99,16 +100,28 @@ try {
Write-LabLog 'dc01: svc_backup already has an ACE on t.smith'
}
# t.smith is a Domain Admin and m.legault is in BUILTIN\Administrators, so
# both are *protected* objects: SDProp rewrites their security descriptor
# from AdminSDHolder every hour and deletes any ACE that only lives on the
# object. Anchoring the same ACE in AdminSDHolder is what makes it stick —
# SDProp then re-applies it instead of removing it.
$adminSdHolder = "CN=AdminSDHolder,CN=System,$base"
if (-not (dsacls.exe $adminSdHolder | Select-String 'svc_backup')) {
$null = dsacls.exe $adminSdHolder /G '@@NETBIOS@@\svc_backup:GA'
Write-LabLog 'dc01: delegation anchored in AdminSDHolder'
# The backup product needs directory replication rights for AD-aware
# backups. That is what makes m.legault reach the DC without being in a
# protected group — so the GenericAll above is never rewritten by SDProp.
$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')) {
$rule = New-Object System.DirectoryServices.ActiveDirectoryAccessRule(
$svcGroup.SID,
[System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight,
[System.Security.AccessControl.AccessControlType]::Allow,
[Guid]$rightGuid)
$sd.AddAccessRule($rule)
}
$domainAcl.ObjectSecurity = $sd
$domainAcl.CommitChanges()
Write-LabLog 'dc01: Sauvegarde-AD granted replication rights'
# m.legault must not carry a stale adminCount flag from an earlier design,
# or SDProp would keep treating the account as protected and wipe the ACE.
Set-ADObject -Identity 'm.legault' -Replace @{ adminCount = 0 } -ErrorAction SilentlyContinue
# Realistic delegation: the service account manages a plain user who is a
# member of the server-admin group. m.legault is NOT in a protected group,
@@ -144,23 +157,30 @@ try {
Write-LabLog 'dc01: yourlove TXT record already present'
}
# ------------------------------------------------------------ flags
$flagDir = 'C:\flag'
# ------------------------------------------------------------ flag
# The server flag sits in the backup staging folder: the agent's group can
# read it, so a plain account can prove it reached the DC.
$flagDir = 'C:\Sauvegarde'
New-Item -ItemType Directory -Force -Path $flagDir | Out-Null
$rootPath = Join-Path $flagDir 'root.txt'
if (-not (Test-Path $rootPath)) {
Set-Content -Path $rootPath -Value 'NORBOURG{do_m41n_4dm1n_0n_dc01}' -Encoding ascii
}
# Administrators only: SYSTEM + Domain Admins inherit through the default ACL.
$acl = Get-Acl $flagDir
$acl.SetAccessRuleProtection($true, $false)
foreach ($id in @('BUILTIN\Administrators', 'NT AUTHORITY\SYSTEM')) {
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
$id, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
$acl.AddAccessRule($rule)
$acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
$id, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
}
$acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
'@@NETBIOS@@\Sauvegarde-AD', 'Read', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
Set-Acl -Path $flagDir -AclObject $acl
Write-LabLog 'dc01: root.txt in place'
if (-not (Get-SmbShare -Name 'Sauvegarde$' -ErrorAction SilentlyContinue)) {
New-SmbShare -Name 'Sauvegarde$' -Path $flagDir `
-ReadAccess '@@NETBIOS@@\Sauvegarde-AD' | Out-Null
}
Write-LabLog 'dc01: root.txt in the backup share'
# The GenericAll path ends in a password reset; the default one-day
# minimum password age blocks it, and it is a plausible weak setting.