Windows Subsystem for Linux

Windows Subsystem for Linux

Kali Linux on Windows Subsystem for Linux (WSL)

This doc describes how to install Kali Linux on WSL(v1/v2).

WSL References

  • Manually download the Appx package (no Windows Store access required): https://docs.microsoft.com/en-us/windows/wsl/install-manual
  • Install WSL in Windows 10: https://docs.microsoft.com/en-us/windows/wsl/install-win10
  • Install WSL2: https://docs.microsoft.com/en-us/windows/wsl/wsl2-install

Install

Enable WSL

Run these commands from an elevated powershell prompt then reboot:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

OPTIONAL: Switch to WSLv2

NOTE: Requires Windows 10 build 18917 or higher (Windows Insider program)

Enable Virtual Machine Platform (WSL2 runs inside Hyper-V):

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

Set WSLv2 as the default subsystem:

wsl --set-default-version 2

Install Linux Distro

A list of URLs for Linux distros can be found here: https://docs.microsoft.com/en-us/windows/wsl/install-manual

Install Ubuntu

To Download Ubuntu 18.04 do:

Invoke-WebRequest -Uri https://aka.ms/wsl-ubuntu-1804 -OutFile Ubuntu-2004.appx -UseBasicParsing

To Download Ubuntu 20.04 do:

Invoke-WebRequest -Uri https://aka.ms/wslubuntu2004 -OutFile Ubuntu-2004.appx -UseBasicParsing

Then, finally run the installer

Add-AppxPackage .\Ubuntu-2004.appx

Install Kali

Invoke-WebRequest -Uri https://aka.ms/wsl-kali-linux-new -OutFile Kali.appx -UseBasicParsing

Then, finally run the installer

Add-AppxPackage .\kali.appx

Follow the prompts to setup a new user.

NOTE: if no prompts show up, then go to the folder where the .appx packages was downloaded and double click on it. A window will appear with the option to “install”. Alternatively, change the extension of the package from .appx to .zip and extract/decompress the contents into a directory of your choice (ex. C:\users\username\.wsl\distros\ubuntu2004), then run the installer executable. {.is-warning}

Setup Kali

Once inside Kali in WSL, we should proceed to update APT packages and upgrade the distro

apt-get updateapt-get dist-upgrade

Once we have done this, we need to install some of the tools that we shall use. For this, the Kali guys have prepared metapackages wich are collections of tools targeted to a specific use. The complete list in here

Install All Tools

If you don’t know which metapackages to install you could install them all!. This will take a long time and download about 2GB. The final distro will be about 7GB in size.

NOTE: there is a chance that your AV will detect and block some of these tools
sudo apt-get install kali-linux-everything

Run Desktop Apps from Kali on WSL

Install XFCE Desktop and XRDP Client

XFCE is a fast and lightweight desktop manager for our Linux distributions.

NOTE: installation of these packages might take a while depending on your internet and system speeds. You will also need to answer some questions about keyboard layout right through the installation

Let’s install the required packages:

sudo apt-get install xfce4 kali-desktop-xfce xorg xrdp

Start XRDP Server and Connect using RDP

Once the installation of the previous packages is complete you will need to start xrdp by running:

sudo service xrdp start

Once started you will have to use the displayed TCP port to connect to it, usually 127.0.0.1:3390

NOTE: when you are done using Kali Linux desktop, it’s best to stop the xrdp server by issuing sudo service xrdp stop

Having multiple Kali Distros

Change Install Location

By default your install will be located here:

C:\Users\<user>\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg

This limits how easy it is to install further instances of Kali. To bypass this limitation we need to move the distro. In order to accomplish this, we must export it, uninstall the appx and import it to a new location.

You won’t be able to just type “kali” and run it, but you can have multiple instances of kali and/or backups.

Export Kali Distro

Setup a directory somewhere you want to store your exports and VM’s. In my examples D::

 wsl --export kali-linux d:\wsl\exported\kali-linux.wsl

Go to add/remove programs and uninstall “Kali Linux”. This will remove it from the original path and unregister it.

List all WSL VM’s to ensure it’s gone:

wsl -l

Import a New VM

Import your exported instance, choosing a new name and location:

wsl --import kali-linux d:\wsl\kali-linux D:\wsl\exported\kali-linux.wsl

Now you can run this with:

wsl.exe ~ -d kali-linux -u <username>

You can run this again to install a second instance:

wsl --import kali2 d:\wsl\kali2 D:\wsl\exported\kali-linux.wslwsl.exe ~ -d kali2 -u <username>

WSL Common Commands

Run a specific distribution:

wsl --distribution, -d <Distro>

List registered distributions:

wsl -l all| running -v
wsl -t <Distro>wsl --unregister <Distro>

WSL Common Lore

Where to find *nix filesystem files in Windows

The current path where WSL stores local data is related to which distribution you have installed. So, for Ubuntu it is now located at:

%LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgsc\LocalState\rootfs

SSH Server in Windows

Instructions to setup SSH server are pretty straightforward but the issue is that documentation is not completely up to date.

In order to setup SSH Server follow these instructions.

To allow an admin to login, you must add an administrators_authorized_keys to the folder where SSH is installed C:\ProgramData\ssh. Then assign the right permissions over the file:

$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys
$acl.SetAccessRuleProtection($true, $false)
$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow")
$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow")
$acl.SetAccessRule($administratorsRule)
$acl.SetAccessRule($systemRule)
$acl | Set-Acl

Reference for these steps here.