Automating Vulnhub VM Imports to Proxmox with PowerShell

In this post, I demonstrate how to install PowerShell and use PowerShell scripts to automate importing Vulnhub VMs in Proxmox.
In: Proxmox, PowerShell, Vulnhub, Home Lab, CTF

In the module on importing Vulnhub VMs into your Proxmox home lab, I show you the steps to manually import a Vulnhub VM using Bash. It's good to know how to do it manually before you automate, so you can troubleshoot scripts if something goes wrong.

Adding Vulnhub VMs to the Cyber Range
In this module, we will look at how to import VMs from Vulnhub into our Proxmox home lab

Proxmox VE runs on top of Debian and since PowerShell 6, PowerShell Core can now run on multiple platforms including Linux. I prefer PowerShell scripting to BASH scripting, because it is object oriented, which enables several powerful features when it comes to systems administration tasks.

Installing PowerShell on Proxmox VE 8

You can install PowerShell on Proxmox VE 7 – which runs on Debian 11 (bullseye) – by running these commands in Bash.

# Download the Microsoft repository GPG keys

# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb

# Update the list of products
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

Download the PowerShell Script

I keep my PowerShell lab scripts in this GitHub repository. This particular script is the one I wrote to automate the Vulnhub VM import.

Proxmox-Lab-Scripts/New-VulnhubVM.ps1 at master · 0xBEN/Proxmox-Lab-Scripts
Adding PowerShell scripts that I use on my Proxmox server to automate certain tasks. - Proxmox-Lab-Scripts/New-VulnhubVM.ps1 at master · 0xBEN/Proxmox-Lab-Scripts

You can click Raw button to download the script to your Proxmox host:

# Navigate to the root user's home directory
cd /root

# Create a Scripts directory
mkdir -p ./Scripts/PowerShell

# Move into the directory
cd ./Scripts/PowerShell

# Download the script

You now have the script downloaded to your Machine. Running it is very simple.

Start PowerShell and Import a VM

Start PowerShell

To start PowerShell in Proxmox, just run this command:

# Start PowerShell

PowerShell should now be running. You should see something like this:

I've got the script download here.

Checking the Script Syntax

Get-Help ./New-VulnhubVM.ps1

We can see it takes the following parameters:

  • -VulnhubURI the download URI of the Vulnhub VM
  • -DownloadDirectory where to download the VM file for processing
  • -VMID the numeric ID in Proxmox
  • -GuestOSType press the Tab key here to auto-complete
  • -VMDiskStorageVolume something like local-lvm but depends on your setup
  • -NetworkBridge the switch in Proxmox to attach to
  • -VlanTag any VLAN tag you want to assign
  • -VMName the name for the VM in Proxmox
  • -MemoryMiB the amount of RAM to give the VM
  • -CommonParameters are not related to the script and are provided by [CmdletBinding()] and not in the scope of this article

Running the Script

Here's an example of an import I did.

./New-VulnhubVM.ps1 -VulnhubURI -DownloadDirectory /tmp -VMID 903 -GuestOSType l26 -VMDiskStorageVolume Guest_Disks -NetworkBridge vmbr1 -VlanTag 999 -VMName digital-world-fall -MemoryMiB 2048

More from 0xBEN
Table of Contents
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to 0xBEN.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.