Add optional Kali attacker VM and DHCP for the lab bridge
lab.sh kali install|up|down|reset|status extracts the official Kali QEMU image once, keeps it as a read-only base with a throwaway overlay, and boots two NICs: the lab bridge (for the exercise) and user networking (so apt works without opening the isolation policy). DC01 now serves DHCP on 10.10.10.100-200 with DNS and domain options but no router: devices on the bridge configure themselves while the lab stays isolated. A reservation pins 10.10.10.101 to the Kali MAC. Also fixed backend_stop, which still called the pre-refactor WinRM helper and fell back to killing the VMs.
This commit is contained in:
@@ -82,6 +82,22 @@ Sans accès au serveur git sur l'hôte Proxmox, construisez une archive autonome
|
|||||||
scp dist/norbourg-proxmox.tar.gz root@pve:/root/
|
scp dist/norbourg-proxmox.tar.gz root@pve:/root/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Machine d'attaque (Kali, optionnel)
|
||||||
|
|
||||||
|
La plateforme `qemu` peut installer l'image QEMU officielle de Kali, avec tous les outils de
|
||||||
|
l'atelier :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./lab.sh kali install # télécharge ~4 Go, extrait, prépare une couche jetable
|
||||||
|
./lab.sh kali up # démarre (VNC 127.0.0.1:5909, SSH 127.0.0.1:2222)
|
||||||
|
./lab.sh kali reset # repart de l'image propre
|
||||||
|
./lab.sh kali down
|
||||||
|
```
|
||||||
|
|
||||||
|
Identifiants par défaut : `kali` / `kali`. La VM a deux cartes : le pont du laboratoire
|
||||||
|
(adresse fournie par le DHCP de DC01) et un réseau utilisateur qui permet `apt` sans ouvrir de
|
||||||
|
passage vers le réseau du bureau.
|
||||||
|
|
||||||
## Commandes
|
## Commandes
|
||||||
|
|
||||||
| Commande | Effet |
|
| Commande | Effet |
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
# shellcheck shell=bash
|
||||||
|
# cmd_kali — optional attacker VM on the qemu platform.
|
||||||
|
#
|
||||||
|
# Uses the official Kali QEMU image (full toolset, kali/kali). It is kept as a
|
||||||
|
# read-only base plus a throwaway overlay, exactly like the Windows guests.
|
||||||
|
# Two NICs: br-lab (lab network, DHCP from DC01) and QEMU user networking so
|
||||||
|
# apt still works while the lab itself stays isolated.
|
||||||
|
|
||||||
|
_kali_base() { printf '%s/images/base/kali-base.qcow2' "$LAB_ROOT"; }
|
||||||
|
_kali_disk() { printf '%s/images/overlays/kali.qcow2' "$LAB_ROOT"; }
|
||||||
|
_kali_pid() { printf '%s/run/kali.pid' "$LAB_ROOT"; }
|
||||||
|
_kali_log() { printf '%s/run/kali.log' "$LAB_ROOT"; }
|
||||||
|
|
||||||
|
_kali_installed() { [[ -f $(_kali_base) ]]; }
|
||||||
|
|
||||||
|
_kali_ensure_overlay() {
|
||||||
|
local base overlay
|
||||||
|
base=$(_kali_base)
|
||||||
|
overlay=$(_kali_disk)
|
||||||
|
_kali_installed || return 1
|
||||||
|
mkdir -p "$(dirname "$overlay")"
|
||||||
|
[[ -f $overlay ]] && return 0
|
||||||
|
qemu-img create -q -f qcow2 -F qcow2 -b "../base/kali-base.qcow2" "$overlay"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_kali() {
|
||||||
|
local action=${1:-up}
|
||||||
|
case $action in
|
||||||
|
install) _kali_install ;;
|
||||||
|
up) _kali_up ;;
|
||||||
|
down) _kali_down ;;
|
||||||
|
reset) _kali_reset ;;
|
||||||
|
status) _kali_status ;;
|
||||||
|
*) info "usage: ./lab.sh kali install|up|down|reset|status"; return 2 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_kali_install() {
|
||||||
|
local archive="$LAB_ISO_CACHE/kali-qemu.7z"
|
||||||
|
local base tmp found
|
||||||
|
|
||||||
|
have_cmd 7z || die "7z is required to extract the Kali image"
|
||||||
|
base=$(_kali_base)
|
||||||
|
|
||||||
|
if _kali_installed; then
|
||||||
|
ok "Kali base image already present ($(du -h "$base" | cut -f1))"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$LAB_ISO_CACHE" "$(dirname "$base")"
|
||||||
|
|
||||||
|
if [[ ! -f $archive ]]; then
|
||||||
|
step "download Kali QEMU image (~4 GB)"
|
||||||
|
curl -L --fail --retry 3 -C - -o "$archive.part" "$KALI_ARCHIVE_URL" -sS \
|
||||||
|
|| { rm -f "$archive.part"; die "download failed"; }
|
||||||
|
mv -f "$archive.part" "$archive"
|
||||||
|
fi
|
||||||
|
ok "archive: $(du -h "$archive" | cut -f1)"
|
||||||
|
|
||||||
|
step "extract"
|
||||||
|
tmp=$(mktemp -d "$LAB_ROOT/run/kali-extract.XXXXXX")
|
||||||
|
( cd "$tmp" && 7z x -y "$archive" >/dev/null ) || { rm -rf "$tmp"; die "extraction failed"; }
|
||||||
|
found=$(find "$tmp" -maxdepth 2 -name '*.qcow2' -print -quit)
|
||||||
|
[[ -n $found ]] || { rm -rf "$tmp"; die "no qcow2 inside the archive"; }
|
||||||
|
mv "$found" "$base"
|
||||||
|
rm -rf "$tmp"
|
||||||
|
|
||||||
|
if [[ ${KALI_DISK_GB:-40} -gt 0 ]]; then
|
||||||
|
qemu-img resize -q "$base" "${KALI_DISK_GB}G" >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
ok "base image: $(du -h "$base" | cut -f1) (${KALI_DISK_GB:-40}G nominal)"
|
||||||
|
_kali_ensure_overlay
|
||||||
|
|
||||||
|
printf '\n'
|
||||||
|
ok "Kali installed — ./lab.sh kali up"
|
||||||
|
info " default credentials: kali / kali"
|
||||||
|
}
|
||||||
|
|
||||||
|
_kali_up() {
|
||||||
|
local base overlay pid vnc
|
||||||
|
_kali_installed || die "Kali is not installed — ./lab.sh kali install"
|
||||||
|
_kali_ensure_overlay || die "could not create the Kali overlay"
|
||||||
|
|
||||||
|
if _kali_status >/dev/null 2>&1; then
|
||||||
|
info "Kali already running"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
base=$(_kali_base)
|
||||||
|
overlay=$(_kali_disk)
|
||||||
|
vnc=${KALI_VNC_DISPLAY:-9}
|
||||||
|
|
||||||
|
mkdir -p "$LAB_ROOT/run"
|
||||||
|
|
||||||
|
# net0: the lab bridge (DHCP from DC01). net1: user networking so apt works
|
||||||
|
# without punching a hole through the lab isolation policy.
|
||||||
|
nohup qemu-system-x86_64 \
|
||||||
|
-name norbourg-kali \
|
||||||
|
-machine q35,accel=kvm -cpu host \
|
||||||
|
-smp "${KALI_VCPU:-2},sockets=1,cores=${KALI_VCPU:-2}" \
|
||||||
|
-m "${KALI_RAM:-4096}" \
|
||||||
|
-rtc base=localtime,clock=host \
|
||||||
|
-drive "if=none,id=disk,file=$overlay,format=qcow2,cache=none,aio=native" \
|
||||||
|
-device ide-hd,drive=disk,bus=ide.0 \
|
||||||
|
-netdev "bridge,id=net0,br=$LAB_BRIDGE" \
|
||||||
|
-device "e1000,netdev=net0,mac=$(qemu_mac_for "${KALI_IP:-10.10.10.101}")" \
|
||||||
|
-netdev "user,id=net1,hostfwd=tcp:127.0.0.1:${KALI_SSH_PORT:-2222}-:22" \
|
||||||
|
-device "e1000,netdev=net1" \
|
||||||
|
-monitor "unix:$LAB_ROOT/run/kali.monitor,server,nowait" \
|
||||||
|
-display none -vnc "127.0.0.1:$vnc" \
|
||||||
|
>>"$(_kali_log)" 2>&1 &
|
||||||
|
printf '%s\n' "$!" > "$(_kali_pid)"
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
if kill -0 "$(<"$(_kali_pid)")" 2>/dev/null; then
|
||||||
|
ok "Kali started · vnc 127.0.0.1:$(( 5900 + vnc )) · ssh 127.0.0.1:${KALI_SSH_PORT:-2222}"
|
||||||
|
info " login kali/kali · bridge address via DHCP (${KALI_IP:-10.10.10.101} reserved)"
|
||||||
|
else
|
||||||
|
fail "Kali failed to start — see $(_kali_log)"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_kali_down() {
|
||||||
|
local pid sock
|
||||||
|
_kali_status >/dev/null 2>&1 || { info "Kali already stopped"; return 0; }
|
||||||
|
|
||||||
|
pid=$(<"$(_kali_pid)")
|
||||||
|
sock="$LAB_ROOT/run/kali.monitor"
|
||||||
|
if [[ -S $sock ]]; then
|
||||||
|
printf 'system_powerdown\n' | socat - "UNIX-CONNECT:$sock" >/dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
for _ in $(seq 1 30); do kill -0 "$pid" 2>/dev/null || break; sleep 1; done
|
||||||
|
kill -0 "$pid" 2>/dev/null && { kill "$pid" 2>/dev/null; sleep 2; }
|
||||||
|
rm -f "$(_kali_pid)"
|
||||||
|
ok "Kali stopped"
|
||||||
|
}
|
||||||
|
|
||||||
|
_kali_reset() {
|
||||||
|
local overlay
|
||||||
|
_kali_installed || die "Kali is not installed"
|
||||||
|
_kali_down >/dev/null 2>&1 || true
|
||||||
|
overlay=$(_kali_disk)
|
||||||
|
rm -f "$overlay"
|
||||||
|
_kali_ensure_overlay
|
||||||
|
ok "Kali reverted to the clean image"
|
||||||
|
}
|
||||||
|
|
||||||
|
_kali_status() {
|
||||||
|
local pid
|
||||||
|
_kali_installed || return 1
|
||||||
|
[[ -r $(_kali_pid) ]] || return 1
|
||||||
|
pid=$(<"$(_kali_pid)")
|
||||||
|
[[ -n $pid ]] && kill -0 "$pid" 2>/dev/null
|
||||||
|
}
|
||||||
@@ -31,3 +31,6 @@ cmd_destroy() {
|
|||||||
|
|
||||||
# Platforms that support participant tunnels override this.
|
# Platforms that support participant tunnels override this.
|
||||||
cmd_peers() { planned peers; }
|
cmd_peers() { planned peers; }
|
||||||
|
|
||||||
|
# Overridden by the qemu platform, which ships the Kali image helper.
|
||||||
|
cmd_kali() { planned kali; }
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ render_role() {
|
|||||||
-e "s|@@BASE_DN@@|${BASE_DN}|g" \
|
-e "s|@@BASE_DN@@|${BASE_DN}|g" \
|
||||||
-e "s|@@ADMIN_PASSWORD@@|${LAB_ADMIN_PASSWORD}|g" \
|
-e "s|@@ADMIN_PASSWORD@@|${LAB_ADMIN_PASSWORD}|g" \
|
||||||
-e "s|@@SAFE_MODE_PASSWORD@@|${LAB_SAFE_MODE_PASSWORD}|g" \
|
-e "s|@@SAFE_MODE_PASSWORD@@|${LAB_SAFE_MODE_PASSWORD}|g" \
|
||||||
|
-e "s|@@LAB_DC_IP@@|${LAB_DC_IP}|g" \
|
||||||
|
-e "s|@@LAB_GATEWAY@@|${LAB_GATEWAY:-}|g" \
|
||||||
"$src" > "$dst"
|
"$src" > "$dst"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ Commands:
|
|||||||
status VM table
|
status VM table
|
||||||
vnc open a console on a VM
|
vnc open a console on a VM
|
||||||
doctor end-to-end health check
|
doctor end-to-end health check
|
||||||
|
kali install / start / stop the optional Kali attacker VM
|
||||||
answers print the instructor walkthrough
|
answers print the instructor walkthrough
|
||||||
destroy remove the VMs and generated artifacts
|
destroy remove the VMs and generated artifacts
|
||||||
EOF
|
EOF
|
||||||
@@ -96,6 +97,7 @@ case $cmd in
|
|||||||
snapshot) cmd_snapshot "$@" ;;
|
snapshot) cmd_snapshot "$@" ;;
|
||||||
reset) cmd_reset "$@" ;;
|
reset) cmd_reset "$@" ;;
|
||||||
doctor) cmd_doctor "$@" ;;
|
doctor) cmd_doctor "$@" ;;
|
||||||
|
kali) cmd_kali "$@" ;;
|
||||||
answers) cmd_answers "$@" ;;
|
answers) cmd_answers "$@" ;;
|
||||||
destroy) cmd_destroy "$@" ;;
|
destroy) cmd_destroy "$@" ;;
|
||||||
peers) cmd_peers "$@" ;;
|
peers) cmd_peers "$@" ;;
|
||||||
|
|||||||
@@ -135,6 +135,27 @@ try {
|
|||||||
Set-ADDefaultDomainPasswordPolicy -Identity '@@DOMAIN@@' -MinPasswordAge '00:00:00'
|
Set-ADDefaultDomainPasswordPolicy -Identity '@@DOMAIN@@' -MinPasswordAge '00:00:00'
|
||||||
Write-LabLog 'dc01: minimum password age set to zero'
|
Write-LabLog 'dc01: minimum password age set to zero'
|
||||||
|
|
||||||
|
# ------------------------------------------------------------ dhcp
|
||||||
|
# Lets anything plugged into the lab bridge configure itself: the Kali
|
||||||
|
# attacker VM, an instructor laptop. No router option on purpose — the lab
|
||||||
|
# is isolated, so clients must not think they have a way out.
|
||||||
|
if (-not (Get-WindowsFeature -Name DHCP).Installed) {
|
||||||
|
$null = Install-WindowsFeature -Name DHCP -IncludeManagementTools
|
||||||
|
Write-LabLog 'dc01: DHCP role installed'
|
||||||
|
}
|
||||||
|
try { Add-DhcpServerInDC -DnsName "dc01.@@DOMAIN@@" -IPAddress '@@LAB_DC_IP@@' -ErrorAction Stop }
|
||||||
|
catch { Write-LabLog 'dc01: DHCP already authorized' }
|
||||||
|
|
||||||
|
if (-not (Get-DhcpServerv4Scope -ScopeId '10.10.10.0' -ErrorAction SilentlyContinue)) {
|
||||||
|
Add-DhcpServerv4Scope -Name 'Norbourg lab' -StartRange '10.10.10.100' `
|
||||||
|
-EndRange '10.10.10.200' -SubnetMask '255.255.255.0' -State Active
|
||||||
|
Write-LabLog 'dc01: DHCP scope 10.10.10.100-200 created'
|
||||||
|
}
|
||||||
|
Set-DhcpServerv4OptionValue -ScopeId '10.10.10.0' `
|
||||||
|
-DnsServer '@@LAB_DC_IP@@' -DnsDomain '@@DOMAIN@@'
|
||||||
|
Set-Service -Name DHCPServer -StartupType Automatic -ErrorAction SilentlyContinue
|
||||||
|
Start-Service -Name DHCPServer -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# ------------------------------------------------------------ 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.
|
||||||
|
|||||||
@@ -135,6 +135,16 @@ cette VM, installez WireGuard et collez la configuration produite par :
|
|||||||
Chaque participant importe son fichier `.conf` : il obtient une adresse dans `10.10.10.0/24` et
|
Chaque participant importe son fichier `.conf` : il obtient une adresse dans `10.10.10.0/24` et
|
||||||
n'a plus qu'à suivre `docs/prerequis.md` (sans l'étape de route, le tunnel la fournit).
|
n'a plus qu'à suivre `docs/prerequis.md` (sans l'étape de route, le tunnel la fournit).
|
||||||
|
|
||||||
|
## DHCP du laboratoire
|
||||||
|
|
||||||
|
DC01 sert aussi DHCP sur le segment du laboratoire (plage `10.10.10.100-200`, DNS et domaine
|
||||||
|
fournis, **aucune passerelle** : le laboratoire est isolé). Tout appareil branché sur le pont se
|
||||||
|
configure seul. Une réservation fixe `10.10.10.101` est créée pour la VM Kali.
|
||||||
|
|
||||||
|
Conséquence pratique : les participants qui amènent leur propre machine sur `192.168.10.0/24`
|
||||||
|
suivent toujours `docs/prerequis.md` (route + DNS), mais une machine branchée directement sur le
|
||||||
|
pont n'a rien à configurer.
|
||||||
|
|
||||||
## Réseau et isolation
|
## Réseau et isolation
|
||||||
|
|
||||||
L'hôte a une adresse sur `br-lab` (`10.10.10.230`) et une sur le réseau du bureau. Le pare-feu
|
L'hôte a une adresse sur `br-lab` (`10.10.10.230`) et une sur le réseau du bureau. Le pare-feu
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ backend_stop() {
|
|||||||
|
|
||||||
# ACPI powerdown is best-effort; Server 2022 often ignores it. Asking the
|
# ACPI powerdown is best-effort; Server 2022 often ignores it. Asking the
|
||||||
# guest to shut itself down over WinRM is what actually works.
|
# 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
|
if backend_ps "$name" "shutdown.exe /s /t 3 /f" >/dev/null 2>&1; then
|
||||||
detail "shutdown requested over WinRM"
|
detail "shutdown requested over WinRM"
|
||||||
elif [[ -S $sock ]]; then
|
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
|
||||||
|
|||||||
@@ -51,6 +51,16 @@ LAB_ADMIN_PASSWORD="${LAB_ADMIN_PASSWORD:-Norbourg!2026}"
|
|||||||
LAB_SAFE_MODE_PASSWORD="${LAB_SAFE_MODE_PASSWORD:-NorbourgDsrm!2026}"
|
LAB_SAFE_MODE_PASSWORD="${LAB_SAFE_MODE_PASSWORD:-NorbourgDsrm!2026}"
|
||||||
WINDOWS_IMAGE_INDEX=2 # 2 = Standard, Desktop Experience
|
WINDOWS_IMAGE_INDEX=2 # 2 = Standard, Desktop Experience
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------- kali
|
||||||
|
# Optional attacker VM (official Kali QEMU image, full toolset).
|
||||||
|
KALI_ARCHIVE_URL="https://cdimage.kali.org/kali-2026.3/kali-linux-2026.3-qemu-amd64.7z"
|
||||||
|
KALI_IP="10.10.10.101"
|
||||||
|
KALI_RAM=4096
|
||||||
|
KALI_VCPU=2
|
||||||
|
KALI_DISK_GB=40
|
||||||
|
KALI_SSH_PORT=2222
|
||||||
|
KALI_VNC_DISPLAY=9
|
||||||
|
|
||||||
# ---------------------------------------------------------------- tuning
|
# ---------------------------------------------------------------- tuning
|
||||||
DISK_FILL_RATIO=30 # percent of the nominal disk actually used (measured ~26%)
|
DISK_FILL_RATIO=30 # percent of the nominal disk actually used (measured ~26%)
|
||||||
ISO_BUDGET_GB=8
|
ISO_BUDGET_GB=8
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export LAB_DIR ROOT_DIR CONTENT_DIR PLATFORM
|
|||||||
|
|
||||||
source "$CONTENT_DIR/lib/common.sh"
|
source "$CONTENT_DIR/lib/common.sh"
|
||||||
for _lib in check cmd_init cmd_isos cmd_seeds cmd_build cmd_provision cmd_web \
|
for _lib in check cmd_init cmd_isos cmd_seeds cmd_build cmd_provision cmd_web \
|
||||||
cmd_snapshot cmd_doctor cmd_misc; do
|
cmd_snapshot cmd_doctor cmd_misc cmd_kali; do
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$CONTENT_DIR/lib/${_lib}.sh"
|
source "$CONTENT_DIR/lib/${_lib}.sh"
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user