Replace the unrealistic ACL target with a realistic delegation
GenericAll over a Domain Admin cannot survive in a real domain: SDProp rewrites protected objects from AdminSDHolder every hour. The previous design only worked thanks to adminCount=0, which no IT team would ever set. New design, matching what broad delegation actually looks like: svc_backup --GenericAll--> m.legault (plain user, ACE stable) m.legault in Serveurs-Admins, which is in BUILTIN\Administrators on DC01 t.smith stays as a decoy: the same edge exists but is reverted by SDProp, which is itself a lesson. Also repairs accounts that an interrupted first run left disabled (m.legault was one), and doctor now checks the stable path, the account state and the DC admin membership.
This commit is contained in:
@@ -111,6 +111,10 @@ Import-Module ActiveDirectory,DnsServer
|
|||||||
$dn = (Get-ADUser t.smith).DistinguishedName
|
$dn = (Get-ADUser t.smith).DistinguishedName
|
||||||
$acl = Get-Acl ("AD:\" + $dn)
|
$acl = Get-Acl ("AD:\" + $dn)
|
||||||
"ace=" + @($acl.Access | Where-Object { $_.IdentityReference.Value -like "*svc_backup*" }).Count
|
"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")
|
||||||
"admincount=" + (Get-ADUser t.smith -Properties adminCount).adminCount
|
"admincount=" + (Get-ADUser t.smith -Properties adminCount).adminCount
|
||||||
"spn=" + @((Get-ADUser svc_backup -Properties ServicePrincipalNames).ServicePrincipalNames).Count
|
"spn=" + @((Get-ADUser svc_backup -Properties ServicePrincipalNames).ServicePrincipalNames).Count
|
||||||
"preauth=" + (Get-ADUser j.contractor -Properties DoesNotRequirePreAuth).DoesNotRequirePreAuth
|
"preauth=" + (Get-ADUser j.contractor -Properties DoesNotRequirePreAuth).DoesNotRequirePreAuth
|
||||||
@@ -125,6 +129,12 @@ $acl = Get-Acl ("AD:\" + $dn)
|
|||||||
case $key in
|
case $key in
|
||||||
ace) if [[ $value -ge 1 ]]; then _d_ok "delegated right: svc_backup has an ACE on t.smith"
|
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 ;;
|
else _d_fail "delegated right missing (ACE on t.smith)"; 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 ;;
|
||||||
admincount) if [[ $value == 0 ]]; then _d_ok "t.smith outside SDProp (adminCount=0)"
|
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 ;;
|
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" ;;
|
spn) [[ $value -ge 1 ]] && _d_ok "service account: SPN present" || _d_fail "svc_backup has no SPN" ;;
|
||||||
|
|||||||
@@ -39,7 +39,11 @@ try {
|
|||||||
|
|
||||||
foreach ($u in $users) {
|
foreach ($u in $users) {
|
||||||
if (Get-ADUser -Filter "SamAccountName -eq '$($u.Sam)'" -ErrorAction SilentlyContinue) {
|
if (Get-ADUser -Filter "SamAccountName -eq '$($u.Sam)'" -ErrorAction SilentlyContinue) {
|
||||||
Write-LabLog "dc01: user $($u.Sam) exists"
|
# An interrupted first run can leave an account disabled: repair it.
|
||||||
|
Enable-ADAccount -Identity $u.Sam -ErrorAction SilentlyContinue
|
||||||
|
Set-ADAccountPassword -Identity $u.Sam -Reset `
|
||||||
|
-NewPassword (ConvertTo-SecureString $u.Pwd -AsPlainText -Force)
|
||||||
|
Write-LabLog "dc01: user $($u.Sam) exists (repaired)"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
$ou = if ($u.OU -eq 'TI') { "OU=TI,OU=Norbourg,$base" } else { "OU=Utilisateurs,OU=Norbourg,$base" }
|
$ou = if ($u.OU -eq 'TI') { "OU=TI,OU=Norbourg,$base" } else { "OU=Utilisateurs,OU=Norbourg,$base" }
|
||||||
@@ -106,6 +110,23 @@ try {
|
|||||||
Write-LabLog "dc01: could not clear adminCount ($($_.Exception.Message))"
|
Write-LabLog "dc01: could not clear adminCount ($($_.Exception.Message))"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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,
|
||||||
|
# so SDProp leaves this ACE alone — unlike the Domain Admin target above.
|
||||||
|
$plainDn = (Get-ADUser 'm.legault').DistinguishedName
|
||||||
|
if (-not (dsacls.exe $plainDn | Select-String 'svc_backup')) {
|
||||||
|
$null = dsacls.exe $plainDn /G '@@NETBIOS@@\svc_backup:GA'
|
||||||
|
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'
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------ 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