proxmox: turnkey RDP exposure for the Kali seats

kali rdp writes one systemd unit per seat (3381..338N) forwarding to the
seat's 3389, and rdp-off removes them. The xrdp bake now pulls xorgxrdp,
uses LAB_HOST_IP for the temporary proxy instead of a hardcoded address,
and restores any pre-existing squid configuration afterwards. Docs use the
command instead of a manual socat loop and mention the PVE firewall.
This commit is contained in:
2026-10-27 20:13:07 -04:00
parent 2c46b78712
commit 7340e4cd54
3 changed files with 49 additions and 13 deletions
+1 -1
View File
@@ -143,7 +143,7 @@ Tout ce que demande l'atelier est déjà dans l'image, et la liste de mots arriv
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.
graphique via un client RDP. `./lab.sh kali rdp` expose un port par siège (3381, 3382…).
## Participants
+7 -7
View File
@@ -222,18 +222,18 @@ Avec `KALI_XRDP=1` (valeur par défaut), `xrdp` est installé **dans le gabarit*
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 :
Pour donner RDP aux participants, exposez un port par siège — une unité systemd par port, donc
persistante :
```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
./lab.sh kali rdp # 3381 … 338N, un port par siège
./lab.sh kali rdp-off # retire les redirections
```
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.
Un client RDP sur `<hôte>:3381` … `:3385`, utilisateur `kali`, mot de passe `kali`. La commande
imprime la correspondance siège → port et le nom d'hôte à utiliser. Si le pare-feu Proxmox est
actif, ouvrez ces ports vers votre réseau de participants.
SSH reste disponible sur les sièges (port 22) et donne un terminal sans passer par une session
graphique.
+41 -5
View File
@@ -511,7 +511,7 @@ _px_kali_bake_xrdp() {
&& cp /etc/squid/squid.conf /root/squid.conf.norbourg
cat >/etc/squid/squid.conf <<EOF
http_port 10.10.10.1:3128
http_port ${LAB_HOST_IP:-10.10.10.1}:3128
acl lab src ${probe}/32
http_access allow lab
http_access deny all
@@ -538,11 +538,11 @@ 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
ip route replace ${LAB_HOST_IP:-10.10.10.1}/32 dev "\$iface" src ${probe}
printf 'Acquire::http::Proxy "http://${LAB_HOST_IP:-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
apt-get install -y -qq xrdp xorgxrdp
rm -f /etc/apt/apt.conf.d/99proxy
if [ -d /home/kali ]; then
echo startxfce4 > /home/kali/.xsession
@@ -567,6 +567,9 @@ GUEST
pve_running "$tpl" && qm stop "$tpl" >/dev/null 2>&1 || true
systemctl disable --now squid >/dev/null 2>&1 || true
if [[ -f /root/squid.conf.norbourg ]]; then
mv -f /root/squid.conf.norbourg /etc/squid/squid.conf
fi
ok "xrdp installed in the Kali template"
}
@@ -822,6 +825,39 @@ cmd_kali() {
_px_kali_configure "$vmid" "kali-$(printf '%02d' "$i")" "$(kali_ip "$i")" || true
done
;;
rdp)
have_cmd socat || die "socat required (apt install socat)"
local host; host=${PVE_WEB_HOST:-$(hostname -f 2>/dev/null || hostname)}
local unit
for i in $(seq 1 "$count"); do
pve_exists "$(kali_vmid "$i")" || { warn "kali-$(printf '%02d' "$i") does not exist — ./lab.sh kali install"; continue; }
unit="/etc/systemd/system/norbourg-kali-rdp-$i.service"
cat > "$unit" <<EOF
[Unit]
Description=Norbourg Kali seat $i (RDP)
After=network-online.target
[Service]
ExecStart=/usr/bin/socat TCP-LISTEN:$((3380 + i)),fork,reuseaddr TCP:$(kali_ip "$i"):3389
Restart=always
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now "norbourg-kali-rdp-$i" >/dev/null 2>&1 \
|| { warn "could not start the forward for kali-$(printf '%02d' "$i")"; continue; }
ok "$(printf 'kali-%02d rdp://%s:%s (kali/kali)' "$i" "$host" "$((3380 + i))")"
done
;;
rdp-off)
for i in $(seq 1 "$count"); do
systemctl disable --now "norbourg-kali-rdp-$i" >/dev/null 2>&1 || true
rm -f "/etc/systemd/system/norbourg-kali-rdp-$i.service"
done
systemctl daemon-reload
ok "RDP forwards removed"
;;
reset)
for i in $(seq 1 "$count"); do
local vmid; vmid=$(kali_vmid "$i")
@@ -833,7 +869,7 @@ cmd_kali() {
done
;;
*)
info "usage: ./lab.sh kali install|up|down|status|configure|reset"
info "usage: ./lab.sh kali install|up|down|status|configure|rdp|rdp-off|reset"
return 2
;;
esac