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
+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.