Compare commits

...
2 Commits
Author SHA1 Message Date
quoije 0206eb6110 Docs: platform-qualified commands; destroy stops Kali 2026-10-22 21:26:55 -04:00
quoije 608b559e51 Proxmox hardening from a dry run and stub tests
- PVE has no win2k22 ostype; Server 2022 maps to win11
- drop --startup 0, which is not a valid order value
- after install, repoint the boot order at sata0 and detach the installer
  ISO, so a stray keypress cannot re-enter Setup
- ISO storage detection falls back to storage.cfg when pvesm has no
  --content flag
- router wg0 is now 10.10.10.250/32 with the lab NIC at .251/24: two /24s on
  one host made routing ambiguous
- nft rules use the router's own interface name (WG_LAB_IFACE), not vmbr10
2026-10-22 21:26:37 -04:00
6 changed files with 94 additions and 24 deletions
+8
View File
@@ -83,6 +83,14 @@ _wait_for_boot() {
printf '\n'
ok "all VMs installed and reachable"
if declare -F backend_finalize >/dev/null; then
step "finalize"
for name in "${VM_NAMES[@]}"; do
backend_finalize "$name" || warn "$name: finalize step failed"
done
fi
info " next: ./lab.sh status"
}
+6
View File
@@ -20,6 +20,12 @@ cmd_destroy() {
backend_destroy "$name" || warn "could not fully remove $name"
done
# Kali lives outside the VMS table; stop it but keep its 16 GB base image.
if declare -F _kali_installed >/dev/null && _kali_installed; then
_kali_down >/dev/null 2>&1 || true
info "kali stopped; base image kept ($(du -h "$(_kali_base)" | cut -f1))"
fi
step "generated artifacts"
rm -rf "$LAB_ROOT/seeds" "$LAB_ROOT/run" "$LAB_ROOT/provision"
ok "seed ISOs, runtime state and provisioning scratch removed"
+35 -15
View File
@@ -15,18 +15,19 @@ Les images Windows sont des versions d'évaluation Microsoft : 180 jours pour Se
## Deux plateformes
Les commandes ci-dessous s'écrivent `./lab.sh` ; préfixez-les par la plateforme visée :
Deux points d'entrée, un même jeu de commandes. Chaque plateforme a son propre `lab.conf` :
```bash
./platforms/qemu/lab.sh ... # Linux générique avec KVM
./platforms/proxmox/lab.sh ... # hôte Proxmox VE
./platforms/qemu/lab.sh <commande> # Linux générique avec KVM
./platforms/proxmox/lab.sh <commande> # hôte Proxmox VE
```
Chaque plateforme a son propre `lab.conf` dans son répertoire.
Les commandes marquées « qemu » ci-dessous se lisent avec le premier préfixe.
## Déploiement complet (qemu)
```bash
cd platforms/qemu
./lab.sh check # 10 s — valide hôte, stockage, réseau, config
./lab.sh init # 1 s — arborescence + chattr +C
./lab.sh isos # ~10 min — télécharge 5,6 Go
@@ -57,11 +58,11 @@ autres VM ne peuvent joindre le domaine qu'après. Utilisez `--role dc01` pour n
## Vérifications rapides
```bash
./lab.sh doctor # tout en un : pont, SMB/WinRM, DNS, site, partage
./lab.sh status # les 3 VM répondent sur 5985
nc -zv 10.10.10.10 389 # le DC expose LDAP
curl -s http://10.10.10.20/ | head -5 # le site 2002 est servi
nmap -Pn -p 445,5985 10.10.10.10-31 # surface d'attaque
./platforms/qemu/lab.sh doctor # tout en un : pont, SMB/WinRM, DNS, site, partage
./platforms/qemu/lab.sh status # les 3 VM répondent sur 5985
nc -zv 10.10.10.10 389 # le DC expose LDAP
curl -s http://10.10.10.20/ | head -5
nmap -Pn -p 445,5985 10.10.10.10-31
```
`doctor` est le premier réflexe quand quelque chose cloche : il sépare un problème réseau d'un
@@ -123,17 +124,36 @@ L'archive contient le contenu commun, la plateforme, la documentation et la solu
### Accès des participants : VM routeur WireGuard
C'est la seule étape manuelle restante. Sur l'hôte Proxmox, créez une petite VM (Alpine ou
Debian, 512 Mo) avec deux cartes : `vmbr0` (réseau du bureau) et `vmbr10` (laboratoire). Dans
cette VM, installez WireGuard et collez la configuration produite par :
C'est la seule étape manuelle restante. Créez une petite VM (Alpine ou Debian, 512 Mo, 2 vCPU)
avec deux cartes réseau :
| Carte | Pont | Adresse |
|---|---|---|
| `eth0` | `vmbr0` (réseau du bureau) | DHCP, pour l'administration |
| `eth1` | `vmbr10` (laboratoire) | **`10.10.10.251/24`**, sans passerelle |
`wg0` reçoit **`10.10.10.250/32`** : une adresse seule dans le sous-réseau, pour ne pas entrer en
conflit avec le /24 de `eth1`. Le trafic vers `.250` passe par le tunnel, tout le reste par
`eth1`. Si votre carte laboratoire ne s'appelle pas `eth1`, ajustez `WG_LAB_IFACE` dans
`platforms/proxmox/lab.conf` avant de générer la configuration.
```bash
./platforms/proxmox/lab.sh peers alice bob carol
# écrit une config par participant et le wg0.conf du routeur dans $WG_DIR
# écrit <nom>.conf par participant et wg0.conf pour le routeur dans $WG_DIR
```
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).
Sur le routeur :
```bash
apt install wireguard-tools nftables
cp wg0.conf /etc/wireguard/wg0.conf
chmod 600 /etc/wireguard/wg0.conf
systemctl enable --now wg-quick@wg0
```
Chaque participant importe son `.conf` (NetworkManager, `wg-quick`, ou l'application WireGuard
sur mobile). Il obtient une adresse `10.10.10.10x` et le DNS `10.10.10.10` poussés par le tunnel :
`docs/prerequis.md` devient inutile, il n'y a ni route ni DNS à configurer à la main.
## DHCP du laboratoire
+39 -8
View File
@@ -25,6 +25,18 @@ pve_running() { qm status "$1" 2>/dev/null | grep -q 'status: running'; }
pve_ip() { local i; i=$(vm_index "$1"); printf '%s' "${VM_IPS[$i]}"; }
# ------------------------------------------------------------------ preflight
# Which storages advertise iso content. `pvesm status --content` is not
# available on every version, so fall back to parsing storage.cfg.
pve_iso_storages() {
local out
out=$(pvesm status --content iso 2>/dev/null | awk 'NR>1{print $1}' | tr '\n' ' ')
if [[ -z ${out// /} && -r /etc/pve/storage.cfg ]]; then
out=$(awk '/^[a-z]+: /{name=$2} /^[[:space:]]*content[[:space:]]/ && /iso/ {print name}' \
/etc/pve/storage.cfg | tr '\n' ' ')
fi
printf '%s' "$out"
}
backend_check() {
if ! command -v qm >/dev/null 2>&1; then
_c_fail "qm not found — this script must run on a Proxmox VE host"
@@ -42,7 +54,7 @@ backend_check() {
_c_fail "disk storage ${PVE_STORAGE_DISKS} not found (run pvesm status)"
fi
iso_content=$(pvesm status -content iso 2>/dev/null | awk 'NR>1{print $1}' | tr '\n' ' ')
iso_content=$(pve_iso_storages)
if [[ " $iso_content " == *" ${PVE_STORAGE_ISO} "* ]]; then
_c_ok "iso storage ${PVE_STORAGE_ISO} present"
else
@@ -114,7 +126,7 @@ backend_create_disk() {
--ide2 "${PVE_STORAGE_ISO}:iso/$(basename "$win"),media=cdrom"
--ide0 "${PVE_STORAGE_ISO}:iso/$(basename "$seed"),media=cdrom"
--boot "order=ide2;ide0"
--onboot 0 --startup 0
--onboot 0
)
(( PVE_AGENT )) && args+=( --agent enabled=1 )
@@ -304,7 +316,8 @@ cmd_peers() {
endpoint="${endpoint}:${WG_PORT}"
fi
local i name addr priv pub psk peer_conf router_peers=""
local i name addr priv pub psk router_peers=""
local LAB_IFACE=${WG_LAB_IFACE:-eth1}
for i in "${!names[@]}"; do
name=${names[$i]}
addr="10.10.10.$(( 101 + i ))/32"
@@ -342,15 +355,23 @@ AllowedIPs = ${addr}"
done
cat > "$WG_DIR/wg0.conf" <<CONF
# Router VM — paste into /etc/wireguard/wg0.conf and: systemctl enable --now wg-quick@wg0
# Router VM — /etc/wireguard/wg0.conf, then: systemctl enable --now wg-quick@wg0
#
# The VM needs TWO interfaces:
# eth0 on vmbr0 (your LAN) — optional, for management
# eth1 on vmbr10 (the lab bridge) — give it 10.10.10.251/24
# wg0 is a /32 inside the lab subnet so it does not collide with those /24s:
# traffic to .250 goes through the tunnel, everything else through eth1.
# Adjust LAB_IFACE below if your lab NIC is not eth1.
[Interface]
Address = 10.10.10.250/24
Address = 10.10.10.250/32
ListenPort = ${WG_PORT}
PrivateKey = $(<"$WG_DIR/server.key")
# Participants reach the DC first; the lab subnet is routed over vmbr10.
PostUp = sysctl -w net.ipv4.ip_forward=1
PostUp = nft add rule ip filter forward iifname "wg0" oifname "vmbr10" accept
PostUp = nft add rule ip filter forward iifname "vmbr10" oifname "wg0" ct state established,related accept
PostUp = nft add rule inet filter forward iifname "wg0" oifname "${LAB_IFACE}" accept
PostUp = nft add rule inet filter forward iifname "${LAB_IFACE}" oifname "wg0" ct state established,related accept
PostDown = nft delete rule inet filter forward iifname "wg0" oifname "${LAB_IFACE}" accept
PostDown = nft delete rule inet filter forward iifname "${LAB_IFACE}" oifname "wg0" ct state established,related accept
${router_peers}
CONF
chmod 600 "$WG_DIR/wg0.conf"
@@ -359,3 +380,13 @@ CONF
ok "peer configs in ${WG_DIR}"
info " router config: ${WG_DIR}/wg0.conf (address 10.10.10.250 on the lab bridge)"
}
# After a successful install, stop booting from the installer CD: otherwise
# every boot waits five seconds and a stray keypress re-enters Setup.
backend_finalize() {
local name=$1 vmid
vmid=$(pve_vmid "$name")
qm set "$vmid" --boot 'order=sata0' --delete ide2 >/dev/null 2>&1 || true
ok "$(printf '%-6s boots from disk (installer ISO detached)' "$name")"
}
+2 -1
View File
@@ -37,7 +37,7 @@ PVE_BRIDGE="vmbr10"
# VM ids. dc01=base+0, fs01=base+1, ws01=base+2; templates use base+100.
PVE_VMID_BASE=1100
PVE_OSTYPE="win2k22"
PVE_OSTYPE="win11" # PVE has no win2k22; win11 covers Server 2022
PVE_BIOS="seabios" # Windows 11 would need ovmf + efidisk0 + tpmstate0
PVE_MACHINE="q35"
PVE_CPU="host"
@@ -77,3 +77,4 @@ BUILD_TIMEOUT=2700
WG_PORT=51820
WG_ENDPOINT="" # leave empty to print the LAN address instead
WG_DIR="${WG_DIR:-$HOME/norbourg-peers}"
WG_LAB_IFACE="eth1" # interface name inside the router VM
+4
View File
@@ -305,3 +305,7 @@ backend_destroy() {
rm -f "$(qemu_pidfile "$name")" "$(qemu_monitor "$name")" "$(qemu_log "$name")"
ok "$name removed"
}
# Nothing to do: the boot order was set to "once=d" at launch time.
backend_finalize() { :; }