Ever since the first version of the Windows Subsystem For Linux (WSL), people have been seeing major benefits of the feature in the Windows ecosystem. The ability to run Linux compiled applications on Windows offers the plethora of tools you could not otherwise use. It also streamlines the workflow for Linux development offering quick, lightweight access to a Linux kernel.
Microsoft’s first version initially mimicked the Linux kernel by implementing it as a DLL. It acted as an interpretation layer to transform Linux kernel calls to Windows kernel calls for it to work. Due to speed and compatibility issues, they eventually scrapped that idea. In its place, they decided to maintain their own modified version of the Linux kernel and run it through a thin layered Hyper-V.
By enabling this native feature, you can install major Linux distributions compatible with WSL from the Windows store to use. Distributions like Ubuntu, Debian, OpenSuse and more.
Let’s install the network penetration distribution, Kali Linux, to try it out.
Enabling the Window’s Subsystem for Linux.
We want to use WSL 2 but you will need Windows Build 19041 or higher.
Open Powershell in administrator mode and execute the following command to enable the Window’s Subsystem for Linux. You will have to perform a system boot after enabling the feature.
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
If you don’t meet the requirements for WSL 2, you can still enable WSL 1 with this command.
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Installing Kali Linux for WSL
Go to the Windows Store and search Kali Linux at the top. Click the drop down, then hit “Install”.
Once it is finished, hit “launch”.
You will have to to create a new user and confirm password.
After that you should have a prompt.
Let’s update our repositories.
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
Since the distribution does not come with any penetration testing applications out of the box, here are some goodies to get you started. Everything else can be downloaded from Kali’s repository as with an traditional Kali installation.
sudo apt-get install git neovim neofetch ranger john hydra nmap wireshark nikto yersinia hashcat macchanger pixiewps wifite lynis wpscan skipfish apktool sqlmap snort autopsy ophcrack set
If you want to explore Kali Linux tools, you can check them out here.
You will need to exclude your Kali Linux directory from Window’s Defender by adding the directory it is installed to to the exclusion list. Otherwise, your Defender will go off with multiple hits as you download certain Kali packages. We can easily do this from Powershell with escalated privileges.
Add-MpPreference -ExclusionPath "C:\Users\<User>\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg"
WSL2 fails and wins
There are some failings when it comes to WSL. For now, there is no GUI support so applications that rely on X-Server will not work out of the box. So that means only terminal based applications at this point. You also cannot rely on system services like SystemD. You will have to start processes up when you boot up the first Linux shell.
The benefits outweigh the the negatives with WSL. It allows you to run multiple Linux distributions from one unified Kernel leaving a less resource intensive option as opposed to running full blown Linux virtual machines with a virtualization software. You can compile and run applications developed for the Linux kernel. With the ability to reach out to Linux distribution repositories, it leaves you with options that would only be offered on Linux. If you need that a specific job done and the only tool out there to do it is only compatible with Linux, it comes in a pinch. Overall, the ability to debug and run Linux applications without leaving your Windows environment is an outstanding feat accomplished by Microsoft.