Files
pentest.intro/session1/content/lib/cmd_seeds.sh
T
quoije dcb64ac65e Restructure the repository per session
session1/ now holds the whole live lab (content, platforms, docs, answer key,
README); session2/ keeps the design for the second workshop. The root README
indexes both and states that session2 modifies session1 rather than
duplicating it.

build-bundle.sh builds from session1 and still produces a flat archive, so
the documented paths inside a deployment (platforms/<p>/lab.sh) are
unchanged. .gitignore follows the move.
2026-10-24 14:22:39 -04:00

76 lines
2.6 KiB
Bash

# shellcheck shell=bash
# cmd_seeds — render one unattend + payload per VM and pack a seed ISO.
# Nothing here needs root or a downloaded ISO; it is pure file assembly.
cmd_seeds() {
local tmpl="$CONTENT_DIR/seed/Autounattend.xml.tmpl"
local payload="$CONTENT_DIR/seed/payload"
[[ -r $tmpl ]] || die "missing template: $tmpl"
[[ -d $payload ]] || die "missing payload dir: $payload"
have_cmd genisoimage || have_cmd xorriso || die "genisoimage or xorriso is required"
: "${LAB_ADMIN_PASSWORD:?LAB_ADMIN_PASSWORD is not set in lab.conf}"
mkdir -p "$SEED_DIR"
local i name ip role work iso volid dns
for i in "${!VM_NAMES[@]}"; do
name=${VM_NAMES[$i]}
ip=${VM_IPS[$i]}
role=${VM_ROLES[$i]}
dns=$LAB_DC_IP # every lab VM resolves through the DC
work="$SEED_DIR/$name"
rm -rf "$work"
mkdir -p "$work/norbourg/roles"
sed -e "s|@@HOSTNAME@@|${name}|g" \
-e "s|@@ADMIN_PASSWORD@@|${LAB_ADMIN_PASSWORD}|g" \
-e "s|@@IMAGE_INDEX@@|${WINDOWS_IMAGE_INDEX:-2}|g" \
"$tmpl" > "$work/Autounattend.xml"
cp "$payload/bootstrap.cmd" "$work/norbourg/"
cp "$payload/bootstrap.ps1" "$work/norbourg/"
# Ship the role scripts on the ISO so the guest never needs a file
# transfer: bootstrap copies this tree to C:\norbourg and runs from there.
mkdir -p "$work/norbourg/lib" "$work/norbourg/roles"
cp "$CONTENT_DIR/windows/lib/common.ps1" "$work/norbourg/lib/"
render_role "$CONTENT_DIR/windows/roles/${role}.ps1" "$work/norbourg/roles/${role}.ps1"
if [[ -f $CONTENT_DIR/windows/roles/${role}-post.ps1 ]]; then
render_role "$CONTENT_DIR/windows/roles/${role}-post.ps1" "$work/norbourg/roles/${role}-post.ps1"
fi
cat > "$work/norbourg/config.ps1" <<EOF
\$Config = @{
Hostname = '${name}'
IP = '${ip}'
Prefix = ${LAB_NETMASK}
Gateway = '${LAB_GATEWAY}'
DNS = '${dns}'
Role = '${role}'
Domain = '${DOMAIN}'
}
EOF
# A malformed answer file means a 20-minute silent install failure; catch it here.
python3 - "$work/Autounattend.xml" <<'PY' || die "rendered answer file is not valid XML for ${name}"
import sys, xml.etree.ElementTree as ET
ET.parse(sys.argv[1])
PY
iso="$SEED_DIR/${name}-seed.iso"
volid="NRBG_${name^^}"
if have_cmd genisoimage; then
genisoimage -quiet -volid "$volid" -J -R -o "$iso" "$work"
else
xorriso -as mkisofs -quiet -V "$volid" -J -R -o "$iso" "$work"
fi
ok "$(printf '%-6s %-14s %-4s %s' "$name" "$ip" "$role" "$iso")"
done
printf '\n'
ok "${#VM_NAMES[@]} seed ISO(s) in ${SEED_DIR}"
}