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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user