proxmox: bake xrdp into the Kali template
KALI_XRDP=1 installs xrdp while the template is still a VM, so every clone and every kali reset keeps it. The lab has no Internet, so the host runs a temporary squid bound to 10.10.10.1 and restricted to the probe address (10.10.10.249); it is stopped and disabled afterwards. A ~/.xsession is written for kali so the xfce session starts under xrdp. Docs cover exposing one RDP port per seat with socat (3381..3385).
This commit is contained in:
@@ -141,6 +141,9 @@ Les Kali n'ont **pas** Internet : c'est volontaire, le pont n'a aucun port vers
|
|||||||
Tout ce que demande l'atelier est déjà dans l'image, et la liste de mots arrive par l'ISO
|
Tout ce que demande l'atelier est déjà dans l'image, et la liste de mots arrive par l'ISO
|
||||||
d'outils.
|
d'outils.
|
||||||
|
|
||||||
|
`KALI_XRDP=1` (par défaut) installe `xrdp` dans le gabarit pour ceux qui veulent un bureau
|
||||||
|
graphique via un client RDP ; voir `docs/instructeur.md` pour exposer les ports.
|
||||||
|
|
||||||
## Participants
|
## Participants
|
||||||
|
|
||||||
Chaque personne reçoit un compte Proxmox limité à sa propre VM :
|
Chaque personne reçoit un compte Proxmox limité à sa propre VM :
|
||||||
|
|||||||
@@ -213,6 +213,30 @@ Côté disque, l'image Kali occupe environ 22 Go une fois importée. Un clone li
|
|||||||
`dir`, Proxmox refuse le clone lié et le script bascule sur des copies complètes — prévoyez
|
`dir`, Proxmox refuse le clone lié et le script bascule sur des copies complètes — prévoyez
|
||||||
alors `KALI_COUNT × 22 Go`.
|
alors `KALI_COUNT × 22 Go`.
|
||||||
|
|
||||||
|
### GUI des Kali : xrdp (`KALI_XRDP=1`)
|
||||||
|
|
||||||
|
Avec `KALI_XRDP=1` (valeur par défaut), `xrdp` est installé **dans le gabarit** au moment de
|
||||||
|
`kali install`. Le pont n'ayant pas Internet, le script démarre un `squid` temporaire sur
|
||||||
|
`10.10.10.1`, n'accepte que l'adresse de la VM de préparation (`10.10.10.249`), installe le
|
||||||
|
paquet, puis arrête et désactive le proxy. Chaque clone — et chaque `kali reset` — garde donc
|
||||||
|
xrdp.
|
||||||
|
|
||||||
|
Pour donner RDP aux participants, exposez un port par siège sur l'hôte :
|
||||||
|
|
||||||
|
```bash
|
||||||
|
apt install -y socat
|
||||||
|
for i in 1 2 3 4 5; do
|
||||||
|
socat TCP-LISTEN:$((3380+i)),fork,reuseaddr TCP:10.10.10.$((40+i)):3389 &
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
Un client RDP sur `<hôte>:3381` … `:3385`, utilisateur `kali`, mot de passe `kali`. Comme pour
|
||||||
|
SSH, ces redirections ne survivent pas à un redémarrage : recréez-les ou passez par des unités
|
||||||
|
systemd.
|
||||||
|
|
||||||
|
SSH reste disponible sur les sièges (port 22) et donne un terminal sans passer par une session
|
||||||
|
graphique.
|
||||||
|
|
||||||
### Accès des participants : console web (recommandé)
|
### Accès des participants : console web (recommandé)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -494,6 +494,82 @@ backend_finalize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------ kali
|
# ------------------------------------------------------------------ kali
|
||||||
|
|
||||||
|
# Install packages in the Kali template through a proxy on the PVE host.
|
||||||
|
# The lab has no Internet by design; squid listens on the lab bridge and only
|
||||||
|
# accepts the probe address, so no other guest can use it.
|
||||||
|
_px_kali_bake_xrdp() {
|
||||||
|
local tpl=$1 probe=10.10.10.249
|
||||||
|
|
||||||
|
step "Kali template: xrdp"
|
||||||
|
if ! dpkg -s squid >/dev/null 2>&1; then
|
||||||
|
apt-get update -qq >/dev/null 2>&1 || true
|
||||||
|
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq squid >/dev/null 2>&1 \
|
||||||
|
|| { warn "could not install squid on this host"; return 1; }
|
||||||
|
fi
|
||||||
|
[[ -f /etc/squid/squid.conf && ! -f /root/squid.conf.norbourg ]] \
|
||||||
|
&& cp /etc/squid/squid.conf /root/squid.conf.norbourg
|
||||||
|
|
||||||
|
cat >/etc/squid/squid.conf <<EOF
|
||||||
|
http_port 10.10.10.1:3128
|
||||||
|
acl lab src ${probe}/32
|
||||||
|
http_access allow lab
|
||||||
|
http_access deny all
|
||||||
|
EOF
|
||||||
|
systemctl restart squid >/dev/null 2>&1 || { warn "squid failed to start"; return 1; }
|
||||||
|
|
||||||
|
qm start "$tpl" >/dev/null 2>&1 || { systemctl stop squid; return 1; }
|
||||||
|
|
||||||
|
local deadline=$(( SECONDS + 240 ))
|
||||||
|
while (( SECONDS < deadline )); do
|
||||||
|
qm guest exec "$tpl" --timeout 10 -- /bin/true >/dev/null 2>&1 && break
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
if ! qm guest exec "$tpl" --timeout 10 -- /bin/true >/dev/null 2>&1; then
|
||||||
|
warn "kali template: guest agent did not answer"
|
||||||
|
qm stop "$tpl" >/dev/null 2>&1 || true
|
||||||
|
systemctl stop squid >/dev/null 2>&1 || true
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local script b64
|
||||||
|
script=$(cat <<GUEST
|
||||||
|
set -e
|
||||||
|
iface=\$(ip -o link show | awk -F': ' '\$2 != "lo" && \$2 !~ /^docker/ {print \$2; exit}')
|
||||||
|
ip addr add ${probe}/24 dev "\$iface" || true
|
||||||
|
ip link set "\$iface" up
|
||||||
|
ip route replace 10.10.10.1/32 dev "\$iface" src ${probe}
|
||||||
|
printf 'Acquire::http::Proxy "http://10.10.10.1:3128";\n' > /etc/apt/apt.conf.d/99proxy
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq xrdp
|
||||||
|
rm -f /etc/apt/apt.conf.d/99proxy
|
||||||
|
if [ -d /home/kali ]; then
|
||||||
|
echo startxfce4 > /home/kali/.xsession
|
||||||
|
chmod +x /home/kali/.xsession
|
||||||
|
chown kali:kali /home/kali/.xsession
|
||||||
|
fi
|
||||||
|
systemctl enable xrdp >/dev/null 2>&1 || true
|
||||||
|
ip addr del ${probe}/24 dev "\$iface" || true
|
||||||
|
GUEST
|
||||||
|
)
|
||||||
|
b64=$(printf '%s' "$script" | base64 -w0)
|
||||||
|
qm guest exec "$tpl" --timeout 1800 -- /bin/bash -c \
|
||||||
|
"echo $b64 | base64 -d > /tmp/xrdp.sh; bash /tmp/xrdp.sh" >/dev/null 2>&1 \
|
||||||
|
|| warn "the xrdp install reported an error (see the template's apt output)"
|
||||||
|
|
||||||
|
qm shutdown "$tpl" --timeout 90 >/dev/null 2>&1 || qm stop "$tpl" >/dev/null 2>&1 || true
|
||||||
|
deadline=$(( SECONDS + 120 ))
|
||||||
|
while (( SECONDS < deadline )); do
|
||||||
|
pve_running "$tpl" || break
|
||||||
|
sleep 3
|
||||||
|
done
|
||||||
|
pve_running "$tpl" && qm stop "$tpl" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
systemctl disable --now squid >/dev/null 2>&1 || true
|
||||||
|
ok "xrdp installed in the Kali template"
|
||||||
|
}
|
||||||
|
|
||||||
# One attacker VM per participant. Configured through the QEMU guest agent
|
# One attacker VM per participant. Configured through the QEMU guest agent
|
||||||
# (the Kali image ships it as a static unit, so Proxmox starts it), reached
|
# (the Kali image ships it as a static unit, so Proxmox starts it), reached
|
||||||
# entirely through the Proxmox web console: no VPN, no client setup.
|
# entirely through the Proxmox web console: no VPN, no client setup.
|
||||||
@@ -565,6 +641,13 @@ _px_kali_template() {
|
|||||||
qm set "$tpl" --sata0 "$vol" --boot order=sata0 >/dev/null \
|
qm set "$tpl" --sata0 "$vol" --boot order=sata0 >/dev/null \
|
||||||
|| die "could not attach the imported disk"
|
|| die "could not attach the imported disk"
|
||||||
qm set "$tpl" --delete unused0 >/dev/null 2>&1 || true
|
qm set "$tpl" --delete unused0 >/dev/null 2>&1 || true
|
||||||
|
|
||||||
|
# Optional extras (xrdp) are installed before the template is sealed, so
|
||||||
|
# every clone and every `kali reset` keeps them.
|
||||||
|
if [[ ${KALI_XRDP:-0} == 1 ]]; then
|
||||||
|
_px_kali_bake_xrdp "$tpl" || warn "xrdp was not baked into the Kali template"
|
||||||
|
fi
|
||||||
|
|
||||||
qm template "$tpl" >/dev/null
|
qm template "$tpl" >/dev/null
|
||||||
rm -rf "$work"
|
rm -rf "$work"
|
||||||
ok "Kali template ${tpl} created"
|
ok "Kali template ${tpl} created"
|
||||||
|
|||||||
@@ -86,6 +86,10 @@ KALI_IP_BASE=41 # 10.10.10.41 .. .4N, outside the DHCP pool
|
|||||||
KALI_VMID_BASE=1300 # template at +90 (windows templates use 1200+)
|
KALI_VMID_BASE=1300 # template at +90 (windows templates use 1200+)
|
||||||
KALI_LINKED_CLONE=1 # 0 = full copies (needs more disk)
|
KALI_LINKED_CLONE=1 # 0 = full copies (needs more disk)
|
||||||
KALI_ARCHIVE_URL="https://cdimage.kali.org/kali-2026.3/kali-linux-2026.3-qemu-amd64.7z"
|
KALI_ARCHIVE_URL="https://cdimage.kali.org/kali-2026.3/kali-linux-2026.3-qemu-amd64.7z"
|
||||||
|
# Bake xrdp into the Kali template (GUI over RDP, port 3389 inside the seat).
|
||||||
|
# Needs Internet on the PVE host for one apt install, done through a temporary
|
||||||
|
# squid that only accepts the probe address. Set to 0 to skip.
|
||||||
|
KALI_XRDP=1
|
||||||
|
|
||||||
# ---------------------------------------------------------------- participants
|
# ---------------------------------------------------------------- participants
|
||||||
# WireGuard endpoint for the router VM option; peers/ writes configs here.
|
# WireGuard endpoint for the router VM option; peers/ writes configs here.
|
||||||
|
|||||||
Reference in New Issue
Block a user