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:
+36
-28
@@ -101,54 +101,62 @@ cmd_doctor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# The puzzle has invariants that services do not reveal: a delegated right,
|
# The puzzle has invariants that services do not reveal: a delegated right, an
|
||||||
# an SPN, a disabled pre-authentication, a password policy. SDProp quietly
|
# SPN, disabled pre-authentication, a password policy, replication rights.
|
||||||
# reverts ACEs on protected objects, so this is worth checking every time.
|
# SDProp quietly reverts ACEs on protected objects, so the target must stay
|
||||||
|
# outside protected groups — worth checking every time.
|
||||||
_lab_state() {
|
_lab_state() {
|
||||||
local out key value
|
local out key value
|
||||||
out=$(backend_ps dc01 '
|
out=$(backend_ps dc01 '
|
||||||
Import-Module ActiveDirectory,DnsServer
|
Import-Module ActiveDirectory,DnsServer
|
||||||
$dn = (Get-ADUser t.smith).DistinguishedName
|
$dom = Get-ADDomain
|
||||||
$acl = Get-Acl ("AD:\" + $dn)
|
$base = $dom.DistinguishedName
|
||||||
|
$acl = Get-Acl ("AD:\" + (Get-ADUser t.smith).DistinguishedName)
|
||||||
"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)
|
$plainAcl = Get-Acl ("AD:\" + (Get-ADUser m.legault).DistinguishedName)
|
||||||
"ace_plain=" + @($plainAcl.Access | Where-Object { $_.IdentityReference.Value -like "*svc_backup*" }).Count
|
"ace_plain=" + @($plainAcl.Access | Where-Object { $_.IdentityReference.Value -like "*svc_backup*" }).Count
|
||||||
"plain_enabled=" + (Get-ADUser m.legault).Enabled
|
"plain_enabled=" + (Get-ADUser m.legault).Enabled
|
||||||
"dcadmin=" + ((Get-ADGroupMember "S-1-5-32-544").Name -contains "Serveurs-Admins")
|
"mcount=" + (Get-ADUser m.legault -Properties adminCount).adminCount
|
||||||
"sdh=" + @((dsacls.exe ("CN=AdminSDHolder,CN=System," + (Get-ADDomain).DistinguishedName) | Select-String "svc_backup")).Count
|
"repl=" + @((dsacls.exe $base | Select-String "Sauvegarde-AD")).Count
|
||||||
"admincount=" + (Get-ADUser t.smith -Properties adminCount).adminCount
|
"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
|
"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
|
||||||
"minage=" + (Get-ADDefaultDomainPasswordPolicy).MinPasswordAge.TotalHours
|
"minage=" + (Get-ADDefaultDomainPasswordPolicy).MinPasswordAge.TotalHours
|
||||||
"root=" + (Test-Path C:\flag\root.txt)
|
|
||||||
"txt=" + ((Get-DnsServerResourceRecord -ZoneName norbourg.lab -Name yourlove -EA SilentlyContinue) -ne $null)
|
"txt=" + ((Get-DnsServerResourceRecord -ZoneName norbourg.lab -Name yourlove -EA SilentlyContinue) -ne $null)
|
||||||
"dhcp=" + ((Get-DhcpServerv4Scope -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
|
"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; }
|
' 2>/dev/null) || { _d_warn "cannot query DC01 for lab state"; return; }
|
||||||
|
|
||||||
local sdh_ok=0
|
|
||||||
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"
|
ace) if [[ $value -ge 1 ]]; then _d_ok "delegated right: svc_backup has an ACE on t.smith (decoy)"
|
||||||
else _d_fail "delegated right missing (ACE on t.smith)"; fi ;;
|
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"
|
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"
|
||||||
else _d_fail "m.legault is disabled — the path is dead"; fi ;;
|
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"
|
mcount) if [[ -z $value || $value == 0 ]]; then _d_ok "m.legault outside protected groups"
|
||||||
else _d_fail "Serveurs-Admins is not in BUILTIN\Administrators"; fi ;;
|
else _d_fail "adminCount=$value: m.legault is protected, SDProp will wipe the ACE"; fi ;;
|
||||||
sdh) if [[ $value -ge 1 ]]; then _d_ok "AdminSDHolder carries the delegation (SDProp-proof)"; sdh_ok=1
|
repl) if [[ $value -ge 2 ]]; then _d_ok "Sauvegarde-AD holds replication rights (DCSync)"
|
||||||
else _d_warn "delegation not anchored in AdminSDHolder"; fi ;;
|
else _d_fail "replication rights missing on Sauvegarde-AD"; fi ;;
|
||||||
admincount) if (( sdh_ok )) || [[ $value == 0 ]]; then _d_ok "protected objects cannot strip the ACE"
|
share) if [[ $value == True ]]; then _d_ok "backup share with the flag"
|
||||||
else _d_warn "adminCount=$value and no AdminSDHolder anchor"; fi ;;
|
else _d_fail "Sauvegarde\$ share missing"; fi ;;
|
||||||
spn) [[ $value -ge 1 ]] && _d_ok "service account: SPN present" || _d_fail "svc_backup has no SPN" ;;
|
root) if [[ $value == True ]]; then _d_ok "root.txt reachable through the backup share"
|
||||||
preauth) [[ $value == True ]] && _d_ok "pre-auth disabled on j.contractor" || _d_fail "j.contractor still requires pre-auth" ;;
|
else _d_fail "root.txt missing"; fi ;;
|
||||||
minage) [[ $value == 0 ]] && _d_ok "minimum password age: 0" || _d_fail "minimum password age is $value h" ;;
|
spn) if [[ $value -ge 1 ]]; then _d_ok "service account: SPN present"
|
||||||
root) [[ $value == True ]] && _d_ok "root.txt on DC01" || _d_fail "root.txt missing" ;;
|
else _d_fail "svc_backup has no SPN"; fi ;;
|
||||||
txt) [[ $value == True ]] && _d_ok "easter egg TXT record" || _d_warn "yourlove TXT record missing" ;;
|
preauth) if [[ $value == True ]]; then _d_ok "pre-auth disabled on j.contractor"
|
||||||
dhcp) [[ $value == True ]] && _d_ok "DHCP scope present" || _d_fail "DHCP scope missing" ;;
|
else _d_fail "j.contractor still requires pre-auth"; fi ;;
|
||||||
kali_res) [[ $value -ge 1 ]] && _d_ok "DHCP reservation 10.10.10.101" || _d_fail "Kali reservation missing" ;;
|
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
|
esac
|
||||||
done <<< "$out"
|
done <<< "$out"
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-1
@@ -51,6 +51,11 @@ _web_sync() {
|
|||||||
tcp_open "$ip" 445 || die "fs01 SMB is not reachable — is it provisioned?"
|
tcp_open "$ip" 445 || die "fs01 SMB is not reachable — is it provisioned?"
|
||||||
have_cmd smbclient || die "smbclient is required to push the site"
|
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.
|
# Bulk copy goes over SMB: WinRM caps the command line at ~8 KB.
|
||||||
smbclient "//$ip/C\$" -W "$NETBIOS" \
|
smbclient "//$ip/C\$" -W "$NETBIOS" \
|
||||||
-U "$LAB_USER%$LAB_ADMIN_PASSWORD" \
|
-U "$LAB_USER%$LAB_ADMIN_PASSWORD" \
|
||||||
@@ -58,7 +63,15 @@ _web_sync() {
|
|||||||
>/dev/null 2>&1 || true
|
>/dev/null 2>&1 || true
|
||||||
|
|
||||||
backend_ready fs01 300 || die "fs01 did not answer"
|
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"
|
| grep -qi true || die "copy failed on fs01"
|
||||||
|
|
||||||
ok "site published to C:\\inetpub\\wwwroot"
|
ok "site published to C:\\inetpub\\wwwroot"
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
Note - 2016-01-12
|
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
|
On a cree le groupe "Sauvegarde-AD" et donne a ce groupe les deux
|
||||||
"Serveurs-Admins" aux Administrateurs locaux de DC01.
|
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.
|
||||||
@@ -10,4 +10,4 @@ Les dates sont celles des fichiers d'origine.
|
|||||||
2011/ deploiement de l'agent sur les postes
|
2011/ deploiement de l'agent sur les postes
|
||||||
2016/ administration du controleur de domaine
|
2016/ administration du controleur de domaine
|
||||||
2019/ arrivee de t.smith
|
2019/ arrivee de t.smith
|
||||||
2021/ delegation ancree dans AdminSDHolder
|
2021/ revue annuelle des acces
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ try {
|
|||||||
'TI-Support' = @('s.bergeron', 'helpdesk1')
|
'TI-Support' = @('s.bergeron', 'helpdesk1')
|
||||||
'WS Admins' = @('svc_backup')
|
'WS Admins' = @('svc_backup')
|
||||||
'Serveurs-Admins' = @('m.legault')
|
'Serveurs-Admins' = @('m.legault')
|
||||||
|
'Sauvegarde-AD' = @('m.legault')
|
||||||
}
|
}
|
||||||
foreach ($name in $groups.Keys) {
|
foreach ($name in $groups.Keys) {
|
||||||
if (-not (Get-ADGroup -Filter "Name -eq '$name'" -ErrorAction SilentlyContinue)) {
|
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'
|
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
|
# The backup product needs directory replication rights for AD-aware
|
||||||
# both are *protected* objects: SDProp rewrites their security descriptor
|
# backups. That is what makes m.legault reach the DC without being in a
|
||||||
# from AdminSDHolder every hour and deletes any ACE that only lives on the
|
# protected group — so the GenericAll above is never rewritten by SDProp.
|
||||||
# object. Anchoring the same ACE in AdminSDHolder is what makes it stick —
|
$svcGroup = Get-ADGroup 'Sauvegarde-AD'
|
||||||
# SDProp then re-applies it instead of removing it.
|
$domainAcl = [ADSI]("LDAP://$base")
|
||||||
$adminSdHolder = "CN=AdminSDHolder,CN=System,$base"
|
$sd = $domainAcl.ObjectSecurity
|
||||||
if (-not (dsacls.exe $adminSdHolder | Select-String 'svc_backup')) {
|
foreach ($rightGuid in @('1131f6aa-9c07-11d1-f79f-00c04fc2dcd2',
|
||||||
$null = dsacls.exe $adminSdHolder /G '@@NETBIOS@@\svc_backup:GA'
|
'1131f6ad-9c07-11d1-f79f-00c04fc2dcd2')) {
|
||||||
Write-LabLog 'dc01: delegation anchored in AdminSDHolder'
|
$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
|
# 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,
|
# 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'
|
Write-LabLog 'dc01: yourlove TXT record already present'
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------ flags
|
# ------------------------------------------------------------ flag
|
||||||
$flagDir = 'C:\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
|
New-Item -ItemType Directory -Force -Path $flagDir | Out-Null
|
||||||
$rootPath = Join-Path $flagDir 'root.txt'
|
$rootPath = Join-Path $flagDir 'root.txt'
|
||||||
if (-not (Test-Path $rootPath)) {
|
if (-not (Test-Path $rootPath)) {
|
||||||
Set-Content -Path $rootPath -Value 'NORBOURG{do_m41n_4dm1n_0n_dc01}' -Encoding ascii
|
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 = Get-Acl $flagDir
|
||||||
$acl.SetAccessRuleProtection($true, $false)
|
$acl.SetAccessRuleProtection($true, $false)
|
||||||
foreach ($id in @('BUILTIN\Administrators', 'NT AUTHORITY\SYSTEM')) {
|
foreach ($id in @('BUILTIN\Administrators', 'NT AUTHORITY\SYSTEM')) {
|
||||||
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
$acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||||
$id, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')
|
$id, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
|
||||||
$acl.AddAccessRule($rule)
|
|
||||||
}
|
}
|
||||||
|
$acl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
|
||||||
|
'@@NETBIOS@@\Sauvegarde-AD', 'Read', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
|
||||||
Set-Acl -Path $flagDir -AclObject $acl
|
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
|
# The GenericAll path ends in a password reset; the default one-day
|
||||||
# minimum password age blocks it, and it is a plausible weak setting.
|
# minimum password age blocks it, and it is a plausible weak setting.
|
||||||
|
|||||||
Reference in New Issue
Block a user