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:
+24
-6
@@ -40,7 +40,18 @@ backend_check() {
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------ 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_log() { printf '%s/run/%s.log' "$LAB_ROOT" "$1"; }
|
||||
qemu_monitor(){ printf '%s/run/%s.monitor' "$LAB_ROOT" "$1"; }
|
||||
@@ -66,7 +77,7 @@ backend_running() {
|
||||
backend_create_disk() {
|
||||
local name=$1 dry=${2:-0}
|
||||
local disk i size
|
||||
disk=$(qemu_disk "$name")
|
||||
disk=$(qemu_golden "$name")
|
||||
i=$(vm_index "$name") || die "unknown vm: $name"
|
||||
size=${VM_DISK[$i]}
|
||||
|
||||
@@ -154,17 +165,23 @@ backend_launch() {
|
||||
}
|
||||
|
||||
backend_stop() {
|
||||
local name=$1 sock pid i
|
||||
local name=$1 sock pid ip i
|
||||
|
||||
backend_running "$name" || { info " $name already stopped"; return 0; }
|
||||
|
||||
sock=$(qemu_monitor "$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
|
||||
fi
|
||||
|
||||
for i in $(seq 1 30); do
|
||||
for i in $(seq 1 90); do
|
||||
kill -0 "$pid" 2>/dev/null || break
|
||||
sleep 1
|
||||
done
|
||||
@@ -172,7 +189,8 @@ backend_stop() {
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
warn "$name did not shut down cleanly, sending TERM"
|
||||
kill "$pid" 2>/dev/null || true
|
||||
sleep 2
|
||||
sleep 3
|
||||
kill -9 "$pid" 2>/dev/null || true
|
||||
fi
|
||||
rm -f "$(qemu_pidfile "$name")"
|
||||
ok "$name stopped"
|
||||
|
||||
+10
-4
@@ -105,10 +105,16 @@ sur `docs/blue-team.md` : chaque étape de l'attaque correspond à un événemen
|
||||
|
||||
## 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
|
||||
./lab.sh down
|
||||
rm -f "$LAB_ROOT"/images/*.qcow2
|
||||
./lab.sh build && ./lab.sh provision
|
||||
./lab.sh snapshot # arrête les VM et fige une base (~2 min)
|
||||
./lab.sh up # ou ./lab.sh reset pour repartir de la base
|
||||
```
|
||||
|
||||
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).
|
||||
|
||||
@@ -22,6 +22,8 @@ source "$LAB_DIR/lib/cmd_seeds.sh"
|
||||
source "$LAB_DIR/lib/cmd_build.sh"
|
||||
# shellcheck source=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() {
|
||||
cat <<EOF
|
||||
@@ -42,9 +44,9 @@ Commands:
|
||||
seeds render unattend files and pack the seed ISOs
|
||||
build create VMs, run unattended installs (phase 3)
|
||||
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)
|
||||
reset revert to baseline (phase 8)
|
||||
reset revert to the baseline and start
|
||||
status VM table: state, pid, VNC display
|
||||
vnc open a console on a VM
|
||||
web sync the archived site to FS01 (phase 7)
|
||||
@@ -145,8 +147,8 @@ case $cmd in
|
||||
status) cmd_status "$@" ;;
|
||||
vnc) cmd_vnc "$@" ;;
|
||||
provision) cmd_provision "$@" ;;
|
||||
snapshot) planned snapshot "phase 8" ;;
|
||||
reset) planned reset "phase 8" ;;
|
||||
snapshot) cmd_snapshot "$@" ;;
|
||||
reset) cmd_reset "$@" ;;
|
||||
doctor) planned doctor "phase 8" ;;
|
||||
peers) planned peers "phase 11" ;;
|
||||
export-kali) planned export-kali "phase 9" ;;
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -114,6 +114,10 @@ def main() -> int:
|
||||
# runs under the Task Scheduler service and survives the disconnect,
|
||||
# which matters for anything that reboots the guest.
|
||||
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 = (
|
||||
'$tr = \'powershell.exe -NoProfile -ExecutionPolicy Bypass -File "'
|
||||
+ remote
|
||||
|
||||
+13
-12
@@ -84,19 +84,15 @@ try {
|
||||
Write-LabLog 'dc01: pre-auth disabled on j.contractor'
|
||||
|
||||
# ACL abuse: svc_backup has GenericAll on a Domain Admin.
|
||||
$target = Get-ADUser 't.smith'
|
||||
$sid = (Get-ADUser 'svc_backup').SID
|
||||
$aclPath = "AD:\$($target.DistinguishedName)"
|
||||
$acl = Get-Acl $aclPath
|
||||
$already = $acl.Access | Where-Object { $_.IdentityReference -eq $sid -and $_.ActiveDirectoryRights -match 'GenericAll' }
|
||||
if (-not $already) {
|
||||
$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
|
||||
# dsacls is used instead of the .NET ACL API, which returns success but
|
||||
# does not persist the ACE through the AD provider.
|
||||
$targetDn = (Get-ADUser 't.smith').DistinguishedName
|
||||
$aclCheck = dsacls.exe $targetDn | Select-String 'svc_backup'
|
||||
if (-not $aclCheck) {
|
||||
$null = dsacls.exe $targetDn /G '@@NETBIOS@@\svc_backup:GA'
|
||||
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
|
||||
@@ -125,6 +121,11 @@ try {
|
||||
Set-Acl -Path $flagDir -AclObject $acl
|
||||
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
|
||||
# Legacy policy off, advanced subcategories on: this is what the blue-team
|
||||
# debrief reads back from the event log.
|
||||
|
||||
Reference in New Issue
Block a user