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:
@@ -494,6 +494,82 @@ backend_finalize() {
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------ 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
|
||||
# (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.
|
||||
@@ -565,6 +641,13 @@ _px_kali_template() {
|
||||
qm set "$tpl" --sata0 "$vol" --boot order=sata0 >/dev/null \
|
||||
|| die "could not attach the imported disk"
|
||||
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
|
||||
rm -rf "$work"
|
||||
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_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"
|
||||
# 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
|
||||
# WireGuard endpoint for the router VM option; peers/ writes configs here.
|
||||
|
||||
Reference in New Issue
Block a user