A from-scratch rebuild surfaced three defects that only appear on a clean deployment: - dc01-post: `Set-ADObject -Identity <sAMAccountName>` raises ADIdentityNotFoundException even right after New-ADUser, so resolve the DN once and reuse it. The stage aborted before DNS, flags, DHCP and the audit policy, leaving a half-built domain. - bootstrap ran the role script at first boot while `provision` also ran it. fs01 tried to join a domain that did not exist yet, and dc01 ran two promotions concurrently; the loser wrote "FAIL Stream was not readable". Roles are now only started by the harness, which orders them. - fs01: the `.url` MIME existence test read the staticContent element (-Name '.') instead of its collection, so any re-run died on a duplicate entry. Test -Name 'collection'. Every stage now takes a PID-based lock: a duplicate start exits instead of racing the real one. Validated on a fresh build: doctor 0 warnings, and the full path (site -> SMB -> AS-REP -> Kerberoast -> WinRM -> ACL -> replication -> DCSync) reproduces.
46 lines
1.5 KiB
PowerShell
46 lines
1.5 KiB
PowerShell
# Norbourg lab — WS01 stage 2: local privileges and the workstation flag.
|
|
|
|
. "$PSScriptRoot\..\lib\common.ps1"
|
|
|
|
$self = $PSCommandPath
|
|
if (-not (Enter-StageLock $self)) {
|
|
Write-LabLog 'stage already running on this guest; duplicate start ignored'
|
|
return
|
|
}
|
|
Write-LabLog 'ws01: post stage starting'
|
|
|
|
try {
|
|
Wait-ForDomain 600
|
|
|
|
# svc_backup becomes a local admin through this domain group.
|
|
try {
|
|
Add-LocalGroupMember -Group 'Administrators' -Member '@@NETBIOS@@\WS Admins' -ErrorAction Stop
|
|
Write-LabLog 'ws01: WS Admins added to local Administrators'
|
|
} catch {
|
|
Write-LabLog 'ws01: WS Admins already local admin'
|
|
}
|
|
|
|
$flagDir = 'C:\flag'
|
|
New-Item -ItemType Directory -Force -Path $flagDir | Out-Null
|
|
$userFlag = Join-Path $flagDir 'user.txt'
|
|
if (-not (Test-Path $userFlag)) {
|
|
Set-Content -Path $userFlag -Value 'NORBOURG{w0rkst4t10n_l4t3r4l_m0v3}' -Encoding ascii
|
|
}
|
|
|
|
$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)
|
|
}
|
|
Set-Acl -Path $flagDir -AclObject $acl
|
|
Write-LabLog 'ws01: user.txt in place'
|
|
|
|
Complete-Stage $self 'ok'
|
|
} catch {
|
|
Fail-Stage $self $_.Exception.Message
|
|
} finally {
|
|
Exit-StageLock $self
|
|
}
|