lab: move the DC flag to C:\flag and make the last step an admin takeover

The replication right is read-only, so root.txt now sits where only DC
administrators can read it (like user.txt on WS01). The backup share stays
readable by Sauvegarde-AD with a note, but no flag. The final step is DCSync
-> Administrator hash -> pass-the-hash -> create a Domain Admin -> read
C:\flag\root.txt; the golden ticket becomes the persistence variant.

doctor checks the new path and fails if the flag is still exposed on the
share. Walkthrough, student sheet, blue-team table and deck updated.
This commit is contained in:
2026-10-27 00:18:44 -04:00
parent e30a447662
commit 2c46b78712
6 changed files with 83 additions and 47 deletions
+7 -4
View File
@@ -126,7 +126,8 @@ $plainAcl = Get-Acl ("AD:\" + (Get-ADUser m.legault).DistinguishedName)
"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)
"root=" + (Test-Path C:\flag\root.txt)
"oldflag=" + (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
@@ -148,10 +149,12 @@ $plainAcl = Get-Acl ("AD:\" + (Get-ADUser m.legault).DistinguishedName)
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"
share) if [[ $value == True ]]; then _d_ok "backup share present (Sauvegarde$)"
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 ;;
root) if [[ $value == True ]]; then _d_ok "root.txt in C:\flag (administrators only)"
else _d_fail "root.txt missing from C:\flag"; fi ;;
oldflag) if [[ $value == True ]]; then _d_fail "root.txt still readable on the backup share"
else _d_ok "flag not exposed on the backup share"; 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"
+39 -8
View File
@@ -190,10 +190,11 @@ try {
Write-LabLog 'dc01: yourlove TXT record already present'
}
# ------------------------------------------------------------ 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'
# ------------------------------------------------------------ flags
# root.txt is only readable by DC administrators. The replication right
# is read-only: reaching this file means turning it into a privileged
# identity (DCSync -> hash -> pass-the-hash, or a freshly created DA).
$flagDir = 'C:\flag'
New-Item -ItemType Directory -Force -Path $flagDir | Out-Null
$rootPath = Join-Path $flagDir 'root.txt'
if (-not (Test-Path $rootPath)) {
@@ -201,19 +202,49 @@ try {
}
$acl = Get-Acl $flagDir
$acl.SetAccessRuleProtection($true, $false)
foreach ($rule in @($acl.Access)) {
if (-not $rule.IsInherited) { [void]$acl.RemoveAccessRule($rule) }
}
foreach ($id in @('BUILTIN\Administrators', 'NT AUTHORITY\SYSTEM')) {
$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
# Re-inherit, otherwise a file left from an older layout keeps its ACL.
$null = icacls.exe $rootPath /reset
# The backup staging folder stays readable by Sauvegarde-AD (that is how
# the service works) but it no longer holds the flag.
$shareDir = 'C:\Sauvegarde'
New-Item -ItemType Directory -Force -Path $shareDir | Out-Null
Remove-Item -Force -ErrorAction SilentlyContinue (Join-Path $shareDir 'root.txt')
$note = Join-Path $shareDir 'LISEZ-MOI.txt'
if (-not (Test-Path $note)) {
Set-Content -Path $note -Encoding ascii -Value @'
Depot de sauvegarde
Le service lit ses cliches dans ce dossier (groupe Sauvegarde-AD).
Les secrets du domaine ne sont pas deposes ici.
'@
}
$shareAcl = Get-Acl $shareDir
$shareAcl.SetAccessRuleProtection($true, $false)
foreach ($rule in @($shareAcl.Access)) {
if (-not $rule.IsInherited) { [void]$shareAcl.RemoveAccessRule($rule) }
}
foreach ($id in @('BUILTIN\Administrators', 'NT AUTHORITY\SYSTEM')) {
$shareAcl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
$id, 'FullControl', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
}
$shareAcl.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule(
'@@NETBIOS@@\Sauvegarde-AD', 'Read', 'ContainerInherit,ObjectInherit', 'None', 'Allow')))
Set-Acl -Path $shareDir -AclObject $shareAcl
$null = icacls.exe $note /reset
if (-not (Get-SmbShare -Name 'Sauvegarde$' -ErrorAction SilentlyContinue)) {
New-SmbShare -Name 'Sauvegarde$' -Path $flagDir `
New-SmbShare -Name 'Sauvegarde$' -Path $shareDir `
-ReadAccess '@@NETBIOS@@\Sauvegarde-AD' | Out-Null
}
Write-LabLog 'dc01: root.txt in the backup share'
Write-LabLog 'dc01: root.txt in C:\flag (administrators only); backup share kept'
# The GenericAll path ends in a password reset; the default one-day
# minimum password age blocks it, and it is a plausible weak setting.