Phase 8: baseline snapshot and reset; validated attack path

snapshot freezes each golden disk into images/base/ and boots a thin
overlay; reset recreates the overlay in about a second. Shutdown now asks
the guest over WinRM because ACPI powerdown is ignored by Server 2022.

dc01-post: grant GenericAll with dsacls (the .NET ACL API reported success
but never persisted the ACE) and set MinPasswordAge to zero, without which
the ACL reset fails.

Attack path validated end to end against the live lab: web -> SMB creds ->
AS-REP -> Kerberoast -> WinRM -> GenericAll reset -> DCSync.
This commit is contained in:
2026-10-21 20:10:06 -04:00
parent 645adea875
commit 71e05d6aa6
6 changed files with 96 additions and 26 deletions
+24 -6
View File
@@ -40,7 +40,18 @@ backend_check() {
} }
# ------------------------------------------------------------------ layout # ------------------------------------------------------------------ layout
qemu_disk() { printf '%s/images/%s.qcow2' "$LAB_ROOT" "$1"; } qemu_base() { printf '%s/images/base/%s-base.qcow2' "$LAB_ROOT" "$1"; }
qemu_overlay(){ printf '%s/images/overlays/%s.qcow2' "$LAB_ROOT" "$1"; }
# Boot the overlay when a baseline exists, the golden disk otherwise.
qemu_disk() {
local overlay
overlay=$(qemu_overlay "$1")
if [[ -f $overlay ]]; then printf '%s' "$overlay"; else printf '%s/images/%s.qcow2' "$LAB_ROOT" "$1"; fi
}
# The disk created by `build`, before it is frozen into a base image.
qemu_golden() { printf '%s/images/%s.qcow2' "$LAB_ROOT" "$1"; }
qemu_pidfile(){ printf '%s/run/%s.pid' "$LAB_ROOT" "$1"; } qemu_pidfile(){ printf '%s/run/%s.pid' "$LAB_ROOT" "$1"; }
qemu_log() { printf '%s/run/%s.log' "$LAB_ROOT" "$1"; } qemu_log() { printf '%s/run/%s.log' "$LAB_ROOT" "$1"; }
qemu_monitor(){ printf '%s/run/%s.monitor' "$LAB_ROOT" "$1"; } qemu_monitor(){ printf '%s/run/%s.monitor' "$LAB_ROOT" "$1"; }
@@ -66,7 +77,7 @@ backend_running() {
backend_create_disk() { backend_create_disk() {
local name=$1 dry=${2:-0} local name=$1 dry=${2:-0}
local disk i size local disk i size
disk=$(qemu_disk "$name") disk=$(qemu_golden "$name")
i=$(vm_index "$name") || die "unknown vm: $name" i=$(vm_index "$name") || die "unknown vm: $name"
size=${VM_DISK[$i]} size=${VM_DISK[$i]}
@@ -154,17 +165,23 @@ backend_launch() {
} }
backend_stop() { backend_stop() {
local name=$1 sock pid i local name=$1 sock pid ip i
backend_running "$name" || { info " $name already stopped"; return 0; } backend_running "$name" || { info " $name already stopped"; return 0; }
sock=$(qemu_monitor "$name") sock=$(qemu_monitor "$name")
pid=$(<"$(qemu_pidfile "$name")") pid=$(<"$(qemu_pidfile "$name")")
ip=${VM_IPS[$(vm_index "$name")]}
if [[ -S $sock ]]; then # ACPI powerdown is best-effort; Server 2022 often ignores it. Asking the
# guest to shut itself down over WinRM is what actually works.
if _winrm "$ip" ps "shutdown.exe /s /t 3 /f" >/dev/null 2>&1; then
detail "shutdown requested over WinRM"
elif [[ -S $sock ]]; then
printf 'system_powerdown\n' | socat - "UNIX-CONNECT:$sock" >/dev/null 2>&1 || true printf 'system_powerdown\n' | socat - "UNIX-CONNECT:$sock" >/dev/null 2>&1 || true
fi fi
for i in $(seq 1 30); do for i in $(seq 1 90); do
kill -0 "$pid" 2>/dev/null || break kill -0 "$pid" 2>/dev/null || break
sleep 1 sleep 1
done done
@@ -172,7 +189,8 @@ backend_stop() {
if kill -0 "$pid" 2>/dev/null; then if kill -0 "$pid" 2>/dev/null; then
warn "$name did not shut down cleanly, sending TERM" warn "$name did not shut down cleanly, sending TERM"
kill "$pid" 2>/dev/null || true kill "$pid" 2>/dev/null || true
sleep 2 sleep 3
kill -9 "$pid" 2>/dev/null || true
fi fi
rm -f "$(qemu_pidfile "$name")" rm -f "$(qemu_pidfile "$name")"
ok "$name stopped" ok "$name stopped"
+10 -4
View File
@@ -105,10 +105,16 @@ sur `docs/blue-team.md` : chaque étape de l'attaque correspond à un événemen
## Remise à zéro ## Remise à zéro
`./lab.sh reset` n'est pas encore implémenté. En attendant, pour repartir propre : Une fois le laboratoire validé, figez l'état propre :
```bash ```bash
./lab.sh down ./lab.sh snapshot # arrête les VM et fige une base (~2 min)
rm -f "$LAB_ROOT"/images/*.qcow2 ./lab.sh up # ou ./lab.sh reset pour repartir de la base
./lab.sh build && ./lab.sh provision
``` ```
Ensuite, `./lab.sh reset` arrête les VM, jette les disques de travail et les recrée depuis la
base : environ deux minutes, sans réinstallation. C'est la commande à utiliser entre deux
groupes ou après une manipulation destructive.
Les disques sont organisés en deux couches : `images/base/<vm>-base.qcow2` (jamais modifié) et
`images/overlays/<vm>.qcow2` (jetable).
+6 -4
View File
@@ -22,6 +22,8 @@ source "$LAB_DIR/lib/cmd_seeds.sh"
source "$LAB_DIR/lib/cmd_build.sh" source "$LAB_DIR/lib/cmd_build.sh"
# shellcheck source=lib/cmd_provision.sh # shellcheck source=lib/cmd_provision.sh
source "$LAB_DIR/lib/cmd_provision.sh" source "$LAB_DIR/lib/cmd_provision.sh"
# shellcheck source=lib/cmd_snapshot.sh
source "$LAB_DIR/lib/cmd_snapshot.sh"
usage() { usage() {
cat <<EOF cat <<EOF
@@ -42,9 +44,9 @@ Commands:
seeds render unattend files and pack the seed ISOs seeds render unattend files and pack the seed ISOs
build create VMs, run unattended installs (phase 3) build create VMs, run unattended installs (phase 3)
provision run role scripts over WinRM (--role NAME for one) provision run role scripts over WinRM (--role NAME for one)
snapshot freeze a clean baseline (phase 8) snapshot freeze a clean baseline (stops the VMs)
up, down start / stop the VMs (phase 3) up, down start / stop the VMs (phase 3)
reset revert to baseline (phase 8) reset revert to the baseline and start
status VM table: state, pid, VNC display status VM table: state, pid, VNC display
vnc open a console on a VM vnc open a console on a VM
web sync the archived site to FS01 (phase 7) web sync the archived site to FS01 (phase 7)
@@ -145,8 +147,8 @@ case $cmd in
status) cmd_status "$@" ;; status) cmd_status "$@" ;;
vnc) cmd_vnc "$@" ;; vnc) cmd_vnc "$@" ;;
provision) cmd_provision "$@" ;; provision) cmd_provision "$@" ;;
snapshot) planned snapshot "phase 8" ;; snapshot) cmd_snapshot "$@" ;;
reset) planned reset "phase 8" ;; reset) cmd_reset "$@" ;;
doctor) planned doctor "phase 8" ;; doctor) planned doctor "phase 8" ;;
peers) planned peers "phase 11" ;; peers) planned peers "phase 11" ;;
export-kali) planned export-kali "phase 9" ;; export-kali) planned export-kali "phase 9" ;;
+39
View File
@@ -0,0 +1,39 @@
# shellcheck shell=bash
# cmd_snapshot / cmd_reset — freeze a clean baseline and revert to it.
# qemu backend: the golden disk becomes a read-only base, each run boots a
# thin overlay. Reset deletes the overlay, so it takes about a second.
cmd_snapshot() {
local name
step "stop"
for name in "${VM_NAMES[@]}"; do
backend_stop "$name"
done
step "freeze baseline"
for name in "${VM_NAMES[@]}"; do
backend_snapshot "$name" || die "snapshot failed for $name"
done
printf '\n'
ok "baseline ready"
info " start with ./lab.sh up · revert with ./lab.sh reset"
}
cmd_reset() {
local name
step "revert to baseline"
for name in "${VM_NAMES[@]}"; do
backend_reset "$name" || die "reset failed for $name"
done
step "start"
for name in "${VM_NAMES[@]}"; do
backend_launch "$name" run || fail "$name did not start"
done
printf '\n'
ok "laboratory reset — previous state discarded"
}
+4
View File
@@ -114,6 +114,10 @@ def main() -> int:
# runs under the Task Scheduler service and survives the disconnect, # runs under the Task Scheduler service and survives the disconnect,
# which matters for anything that reboots the guest. # which matters for anything that reboots the guest.
ps(session, f"Remove-Item -Force -ErrorAction SilentlyContinue '{done}'") ps(session, f"Remove-Item -Force -ErrorAction SilentlyContinue '{done}'")
# A task left over from an interrupted run stays in "Running" and
# blocks the next one; clear it first.
ps(session, "schtasks.exe /End /TN NorbourgStage 2>$null | Out-Null; "
"schtasks.exe /Delete /TN NorbourgStage /F 2>$null | Out-Null")
task = ( task = (
'$tr = \'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "' '$tr = \'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "'
+ remote + remote
+13 -12
View File
@@ -84,19 +84,15 @@ try {
Write-LabLog 'dc01: pre-auth disabled on j.contractor' Write-LabLog 'dc01: pre-auth disabled on j.contractor'
# ACL abuse: svc_backup has GenericAll on a Domain Admin. # ACL abuse: svc_backup has GenericAll on a Domain Admin.
$target = Get-ADUser 't.smith' # dsacls is used instead of the .NET ACL API, which returns success but
$sid = (Get-ADUser 'svc_backup').SID # does not persist the ACE through the AD provider.
$aclPath = "AD:\$($target.DistinguishedName)" $targetDn = (Get-ADUser 't.smith').DistinguishedName
$acl = Get-Acl $aclPath $aclCheck = dsacls.exe $targetDn | Select-String 'svc_backup'
$already = $acl.Access | Where-Object { $_.IdentityReference -eq $sid -and $_.ActiveDirectoryRights -match 'GenericAll' } if (-not $aclCheck) {
if (-not $already) { $null = dsacls.exe $targetDn /G '@@NETBIOS@@\svc_backup:GA'
$rule = New-Object System.DirectoryServices.ActiveDirectoryAccessRule(
$sid,
[System.DirectoryServices.ActiveDirectoryRights]::GenericAll,
[System.Security.AccessControl.AccessControlType]::Allow)
$acl.AddAccessRule($rule)
Set-Acl -Path $aclPath -AclObject $acl
Write-LabLog 'dc01: GenericAll granted to svc_backup over t.smith' Write-LabLog 'dc01: GenericAll granted to svc_backup over t.smith'
} else {
Write-LabLog 'dc01: svc_backup already has an ACE on t.smith'
} }
# ------------------------------------------------------------ dns # ------------------------------------------------------------ dns
@@ -125,6 +121,11 @@ try {
Set-Acl -Path $flagDir -AclObject $acl Set-Acl -Path $flagDir -AclObject $acl
Write-LabLog 'dc01: root.txt in place' Write-LabLog 'dc01: root.txt in place'
# The GenericAll path ends in a password reset; the default one-day
# minimum password age blocks it, and it is a plausible weak setting.
Set-ADDefaultDomainPasswordPolicy -Identity '@@DOMAIN@@' -MinPasswordAge '00:00:00'
Write-LabLog 'dc01: minimum password age set to zero'
# ------------------------------------------------------------ auditing # ------------------------------------------------------------ auditing
# Legacy policy off, advanced subcategories on: this is what the blue-team # Legacy policy off, advanced subcategories on: this is what the blue-team
# debrief reads back from the event log. # debrief reads back from the event log.