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
+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