365labs - Microsoft 365 and cybersecurity consultancy

View Original

Installing Kali 2022.4 on Windows 11 Hyper-V with Enhanced Session Mode

Installing Kali Linux 2022.4

More detailed steps on enabling Hyper-V in Windows and creating a VM are available elsewhere, this is just a basic run-through and assumes the Hyper-V feature is installed on the host operating system. This should also work fine on Windows 10.

Firstly, download the Kali 2022.4 ISO from the website. https://www.kali.org/get-kali/#kali-installer-images

Next, create a Gen2 virtual machine in Hyper-V. Assign 4vCPU and 4GB of RAM, if you can, and turn off dynamic memory.

Select either the default switch for NAT connectivity to the host/internet, or an external switch for the VM to be on your local network.

Select the ISO image on the options screen and choose the downloaded Kali ISO.

Important: Before starting the VM disable secure boot in the VM's settings. This is because the Kali Linux kernel is not signed. Leaving secure boot enabled will prevent the installer/OS from booting.

Start the VM, the Kali graphical installation will start. Choose your required settings or use the defaults.

You'll be prompted to create a standard user account (this is the case since 2020.1) instead of using the root account. Don't leave this password blank and avoid using kali:kali.

Once the installation is completed, and you have logged in, open a terminal and run the following:

sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y

The -y switch (proceed answering yes to everything) should be fine on a clean build, as is the case here, however with a well-worn machine, it might be best to leave it out and review the questions first. This will update the package sources list, upgrade packages and remove unneeded packages.

You'll probably notice that the machines desktop does not fill the screen. If you are not intending to use Enhanced Session Mode or for some reason cannot get it to work then:

Open a terminal window (you can use vi instead of nano if you prefer):

sudo nano /etc/default/grub

Edit the line

“GRUB_CMDLINE_LINUX_DEFAULT=”quiet“

to

“GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash video=Hyper-V_fb:1920×1080″

Note: If pasting the text ensure that the x character has pasted in as an x, if in doubt re-type it.

CTRL+X to exit nano and Y to save. After a reboot, you should see the VM filling the screen.

Note: Hyper-V supports a maximum resolution for Hyper-V guests of 1920x1080. You may also need to adjust this value to suit your hardware and requirements.

kali-tweaks menu screen.

Enhanced Session Mode

Once logged in open a terminal window and execute kali-tweaks

sudo kali-tweaks

Enter your password.

In the kali-tweaks menu scroll down to Virtualization and press Enter. Select the option to configure Enhanced Session Mode. This will download and install xrdp which is required for Enhanced Session Mode.

Exit kali-tweaks and shutdown the VM.

Choose desktop size, clipboard and audio settings.

Next ensure that Enhanced Session Mode is enabled in Hyper-V. This should be enabled in later versions of Windows/Hyper-V, but check it anyway. In Hyper-V Manager, right-click the host and select Hyper-V settings. Ensure that Enhanced Session mode is enabled under both Server and User.

Then, from an elevated Powershell prompt:

Set-VM "<<Your VM name>>" -EnhancedSessionTransportType HVSocket

‘Your VM name’ should match the one displayed in Hyper-V manager.

The xrdp login screen indicating Enhanced Session Mode is active.

Boot the VM and you should see the screen where you can choose the size of your desktop, clipboard and audio settings.

You’ll know when the process is complete when you are presented with the xrdp login screen rather than the kali native one.

If you need to troubleshoot and turn of Enhanced Session Mode this can be done from the view menu of the VM.

Also, you might want to create a snapshot/checkpoint of the VM at this point in case something goes wrong later or you want to revert back to this clean build state.

For more information on Enhanced Session Mode check out the Microsoft website:

https://learn.microsoft.com/en-us/virtualization/community/team-blog/2018/20180228-sneak-peek-taking-a-spin-with-enhanced-linux-vms

See this content in the original post