Files
pentest.intro/windows/roles/ws01-post.ps1
T
quoije 645adea875 Provisioning fixes: auth-based readiness, domain join guards, site push
- wait for WinRM with an authenticated call, not a TCP probe: the port opens
  before the service can authenticate
- skip promotion/join when the machine is already there, so provision is
  idempotent
- probe the domain with System.DirectoryServices: Get-ADDomain needs RSAT,
  which a member server does not have
- passwords must not contain the account name (Legault2024! is rejected)
- Web-Dir-Browsing is the real feature name
- push the site over SMB from C$: WinRM caps the command line at 8 KB
2026-10-21 20:02:43 -04:00

40 lines
1.3 KiB
PowerShell

# Norbourg lab — WS01 stage 2: local privileges and the workstation flag.
. "$PSScriptRoot\..\lib\common.ps1"
$self = $PSCommandPath
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
}