Setting Up Kali Linux for Pentesting in WSL 2 (Windows Subsystem for Linux 2)

If you are a penetration tester, or currently learning penetration testing, you probably use Kali Linux (or your hacking Linux distro of choice) in one or all of the following ways:
You use a hypervisor like VMware or Oracle Virtual Box to run a virtual machine of Kali.
You have set up dual boot on your laptop/pc to support your main operating system (maybe windows?) and also Kali.
You have a dedicated laptop or PC running Kali OS.
You use a cloud provider like Microsoft Azure and have a Kali machine setup in the cloud.
You run Kali as a docker container within a Linux OS.
The point is, there are a myriad number of ways to setup your hacking environment and what you choose is completely up to you based on your preferences and needs.
The aim of this article is to merely present an alternative manner of setting up Kali for pentesting. We will be exploring how to setup Kali for pentesting on WSL2 (Windows Subsystem for Linux 2).
What is WSL and How does it Work?
Before we can get started on the practical activities, we first need a basic understanding of the technology that will be used to power the Kali OS on Windows.
WSL is an optional feature in Windows 10 that provides users with a lightweight Linux Console environment within the Windows OS. It allows users to run native Linux command line tools directly on Windows, alongside the traditional Windows desktop and modern store apps. It did this by adding a compatibility layer that translates Linux System calls to Windows Kernel calls while a Linux Distro sits on top, thus eliminating the need for a Linux Kernel. Being optional, the feature is not enabled by default.

WSL is popular because no hypervisor is needed thus making it lighter than running a VM. Furthermore, one can access the Windows 10 filesystem from within it. It's drawbacks are that there is no native Linux Kernel and thus some processes, tasks, and support are limited.
WSL2
Unlike WSL which acts as a translation layer, WSL 2 uses virtualization technology and an actual Linux kernel to enable new features not supported in its predecessor. The main benefits of WSL 2 are:
full system call capability.
increased file system performance.
WSL 2 uses Microsoft's hardware virtualization service: Hyper -V. A traditional VM experience can be slow to boot up, isolated, consumes a lot of resources, and requires management. WSL 2 does not have such attributes but rather offers:
seamless integration between Windows and Linux.
fast boot times.
smaller memory footprint.
Linux GUI support.

Setting up Kali on WSL 2
Requirements
Enable virtualization support in BIOS.
Have the Windows 10 version 2004 installed and updated.
To check which version of Windows 10 you have, type winver in "Run".
Once you do so, it will display which version of Windows 10 you are running.
In case you don't have that particular version, check Updates in your machine's Settings and download and install it. If it isn't there, you can visit Microsoft's support page for details on how to get it.
Next, we need to enable WSL 2. The Virtual Machine Platform and Windows Subsystem for Linux features must be enabled in Turn Windows features on or off. The panel can be accessed by hitting Start and typing “features” or from the Programs and Features icon in the classic Control Panel.
Once those features have been enabled, reboot your machine.
Download and install the latest WSL2 Linux Kernel from here: https://aka.ms/wsl2kernel (direct link).

Then enable WSL2 as the default by entering the following command in a Windows Powershell or command prompt:
wsl --set-default-version 2
Once done, proceed to the Microsoft Store and download the Kali Linux distro.

Following download, click the Launch button on the Microsoft Store app or go to your terminal and type in kali then press enter. This will complete the installation process and may take a few minutes. Afterwards, you will be prompted to provide a username and password. These will be your kali Linux credentials.
Once finished, make sure to update and upgrade your Kali Linux using the commands below:
sudo apt update
sudo apt upgradeAnd that's it, you now have Kali Linux running on WSL 2.

Now let's set up it's Graphical User Interface (GUI).
Installing Win-KeX (Windows + Kali Desktop Experience)
Win-KeX provides a Kali Desktop Experience for Windows Subsystem for Linux (WSL 2) with the following features:
Window mode: start a Kali Linux desktop in a dedicated window
Seamless mode: share the Windows desktop between Windows and Kali apps and menus
Sound support
Unprivileged and Root session support
Shared clipboard for cut and paste support between Kali Linux and Windows apps
Multi-session support: root window & non-priv window & seamless sessions concurrently
To install Win-KeX, run the command below:
sudo apt install kali-win-kexPackages of about 600 megabytes will be downloaded and the amount of occupied space will increase by almost 1.8 gigabytes. You will also be prompted to choose your keyboard layout. Do so and wait until everything is finally completed.
Once finished, in the kali command line, run kex to launch the GUI. In case you want to explore other options of running the GUI e.g. enabling sound mode, run kex --help.
If this is your first time running Win-KeX, you will be prompted to enter a password. We are setting a new VNC password. Therefore, come up with and enter a password twice (at least 6 characters long) and then enter "n", which means that the password gives the right not only to watch what is happening in the system (and nothing will happen there without your participation), but also to move and click the mouse and enter data from the keyboard.
Finally, the Kali Linux graphical desktop environment should open.
NB: However, keep in mind that in order to keep the Kali image small, it does not come pre-installed with all its default tools. You can either install them on a need to basis, or use the command below to automatically install all the default tools.
sudo apt install kali-linux-largeNB 2: Note: Some tools may trigger Antivirus warnings when installed, please plan ahead accordingly. Make sure to visit the Kali WSL tutorial page at https://www.kali.org/news/kali-linux-in-the-windows-app-store for more details.
Last updated
Was this helpful?