- Ethical hacking and penetration testing
- InfoSec, IT, Kali Linux, BlackArch
- How to install Kali Linux with Win-KeX (GUI) in WSL2 (Windows Subsystem for Linux)
- Table of contents
- What is WSL for. What are the limitations of WSL2 (Windows Subsystem for Linux)
- What is Win-KeX
- How to enable WSL2
- How to install Kali Linux in WSL
- How to run Kali Linux in WSL
- Ошибка «WslRegisterDistribution failed with error: 0x80370102»
- Setting up Kali Linux in WSL
- How to use Kali Linux in WSL
- How to install Win-KeX
- How to close Win-KeX
- How to use Win-KeX
- How to install Kali Linux tools in WSL
- How to copy files from Linux to WSL2. Where are Kali Linux files stored in WSL2. How to access Linux filesystem in WSL2
- How to change the password complexity policy in WSL2
- How to use systemctl in WSL2
- How to launch Win-KeX with keyboard shortcut in PowerShell
Ethical hacking and penetration testing
InfoSec, IT, Kali Linux, BlackArch
How to install Kali Linux with Win-KeX (GUI) in WSL2 (Windows Subsystem for Linux)
Table of contents
What is WSL for. What are the limitations of WSL2 (Windows Subsystem for Linux)
This article describes how to install “Kali Linux” on a Windows Subsystem for Linux (WSL2), but you need to be very clear about that:
- we do not actually install Kali Linux
- we do not actually install Linux at all
The Windows Subsystem for Linux is NOT a virtual machine and is NOT real Linux. If you understand what Wine is (which is also not an emulator), then WSL2 is also a Wine vice versa. WSL2 is simply trying to serve as a Linux kernel to the best of its ability for GNU applications, without being a true Linux kernel.
What does this mean from a practical point of view? This means that we get a very similar situation with Wine, which tries to execute Windows functions (again, to the best of its ability) – something will work fine, something will work with errors, and something will not work at all…
In WSL2, 100% will not work (in the coming years, and maybe never at all)
- absolutely all wireless attacks (Wi-Fi, Bluetooth)
- Hashcat and other programs using video cards to perform computations (brute force)
- low-level access to USB devices (for example, to make an image of a disk/flash drive for forensic research)
- background server applications
We are promised support for graphics cards for compute in WSL2 by next year, but by the spring of this year we were promised a real Linux kernel (not yet), so I am skeptical about these plans.
Everything else will work in the range “works fine” to “does not work at all” with intermediate stations for the most exotic errors. Therefore, if you are asking for help with problems somewhere, then be sure to indicate that this is Kali Linux in WSL2 – this is very important.
Do you think I’m exaggerating because I don’t like WSL2? See for yourself, this is an attempt to launch kazam – a simple application that takes screenshots (yes, I wanted to take a screenshot of the desktop for you) and records video, the shortcut of this application is placed on the Kali Linux quick launch bar by default. And it just didn’t work in WSL2.
So what are we actually going to install in this tutorial? Among other things, we will separately download and install the latest version of what acts as the kernel, and for all systems at once – even Kali Linux, even OpenSUSE. Then, at the stage of “installing Kali Linux”, we download a certain image with a set of GNU programs, settings and Kali Linux wallpapers. And this is what will be “Kali Linux” for us.
If you haven’t figured it out yet, I STRONGLY recommend using a regular VirtualBox virtual machine instead of what I will do later in this tutorial. But if I haven’t convinced you, then we continue.
But if you dig even deeper, the situation is a little more complicated (and worse) – if your processor does not support virtualization functions, then WSL2 will NOT work. But at the same time, it is not a full-fledged emulator. I do not know why this is so – for me it is very strange. That is, if you want to use WSL2 somewhere in the cloud with Windows installed, you will not succeed.
By the way, WSL is based on the abandoned Project Astoria, which was developed to run Android applications directly on Windows. IMHO, such a project would make more sense – in vain they decided to remake.
What is Win-KeX
In this tutorial, inside Kali Linux, we will install Win-KeX, which stands for Kali Desktop Experience for Windows (Kali desktop with a graphical user interface). Previously, it was already possible to use Kali Linux with a graphical interface in WSL. To do this, a graphical desktop environment was installed, the RDP server packages were installed, the RDP service was started, it was necessary to look at the IP address of the operating system in WSL, then in Windows it was necessary to launch the RDP client, enter the IP address of the virtual machine into the RDP client and finally connect.
The essence of Win-KeX is that it does it for you, that is, it automates the process. Well, RDP is also replaced by VNC. The rest has not changed.
How to enable WSL2
This manual requires Windows 10 version 2004 or higher – this update is from May 2020, that is, most should already have it installed. If not, start by updating Windows by pressing Win+i → Update and Security → Check for Updates.
To see the exact version of Windows, at a command prompt, type:
WSL2 is disabled by default on Windows. Therefore, if you have not enabled it before, then do it – you can use the graphical interface or the command line. To enable WSL2 in the command line, press Win+x and select “Windows PowerShell (administrator)” in the menu that opens:
It’s important to open PowerShell with elevated rights.
Wait for the download and execution to finish.
Restart your computer by pressing Enter.
Now open PowerShell as administrator again and run:
Restart your computer again.
Download and install the latest WSL2 Linux Kernel from here: https://aka.ms/wsl2kernel (direct link).
Open PowerShell as administrator again and run:
If you already have Kali Linux installed in WSL1, then to update, run the command:
How to install Kali Linux in WSL
In a system-wide search, enter “Microsoft Store” and launch the Microsoft App Store.
In this app store, search for “Kali Linux”.
Click the Get button.
Click No Thanks.
The image is not very large, less than 200 megabytes, wait until it is downloaded.
While downloading, read the information about this application:
The Kali for Windows application allows one to install and run the Kali Linux open-source penetration testing distribution natively, from the Windows 10 OS. To launch the Kali shell, type «kali» on the command prompt, or click on the Kali tile in the Start Menu.
The base image does not contain any tools, or a graphical interface in order to keep the image small, however these can be installed via apt commands very easily. For more information about what you can do with this app, check https://www.kali.org/kali-on-windows-app.
Note: Some tools may trigger Antivirus warnings when installed, please plan ahead accordingly. Make sure to visit our Kali on WSL tutorial page at https://www.kali.org/news/kali-linux-in-the-windows-app-store
Be sure to enable the Windows Subsystem for Linux optional feature before installing the Kali Linux app!
How to run Kali Linux in WSL
As we already know, you can find “Kali Linux” in a system-wide search.
or enter in the command line
Ошибка «WslRegisterDistribution failed with error: 0x80370102»
And here the first pitfall is possible. The installation of the selected distribution should complete, you will be asked for a username and password for the new user. But an error may occur:
The essence of the error is that the central processor does not support virtualization. The reasons can be different:
- you disabled virtualization in BIOS
- the processor does not support virtualization at all
- you run Windows already in a virtual machine (regardless of the model, the processors do not support virtualization there).
The last option is the cause of my problem, so I just rebooted from the virtual machine to the real one.
Setting up Kali Linux in WSL
If everything is fine with your host system, then you will be asked to come up with and enter a username and enter a password twice.
The password is required to use commands with sudo (to run commands as root). The system is logged in without a password. Here you can set any password, including a simple one – I do this, because for me these are test systems that are not used for real work and do not live long. You do not need to enter a password to log in. But there is one remarkable feature – it will be very difficult to change it using the passwd command (more on this issue below).
How to use Kali Linux in WSL
After running on the command line
It may seem that absolutely nothing happened. But in fact, the command line prompt has changed, we are already inside Kali Linux!
The following commands can be used to view the system version:
Pay attention to the kernel version.
How to install Win-KeX
If you are already an experienced Kali Linux user in WSL and already know how to connect to the graphical interface using RDP, then you do not need to install RDP server packages if you want to use Win-KeX.
To install Win-KeX, run:
Enter your Linux user password.
Packages of about 600 megabytes will be downloaded and the amount of occupied space will increase by almost 1.8 gigabytes.
During the installation and update of packages, you will be prompted to select a keyboard layout. Just in case, choose English so as not to be left without it.
It is then easy to add new layouts in the GUI. It is not a graphical interface, so here you can use the arrow keys to select and the Tab key to navigate to the Ok button.
Wait until everything is finally completed.
Now in the Kali Linux command line run:
If this is your first time running Win-KeX, you will be prompted to enter a password.
You might think this is the Linux user’s password, but you didn’t guess – it’s not even entering the password, but 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.
How to close Win-KeX
The usual Kali Linux shutdown buttons in WSL do not work. If you try to end the session, you will find yourself in a black screen from which it is not easy to get out – if you are stuck in this situation, press Ctrl+Alt+Delete and select Task Manager. Then close the Kali Linux window.
You can exit full screen mode by pressing F8 to bring up the TigerVNC context menu.
To properly close Win-KeX and return to the command line interface, run the command:
How to use Win-KeX
As you can see, to turn off Win-KeX you need to know its options. The Win-KeX program has several modes and a number of commands, let’s take a closer look at them.
Start KeX server in window mode and launch KeX client with sound support
Start KeX in seamless mode and launch KeX client with sound support
Start KeX server as root in window mode and launch KeX client
How to install Kali Linux tools in WSL
There are no installed tools by default, you can install them selectively or all at once (a lot of downloaded data and a lot of disk space needed):
See also “Kali Linux Meta-packages” section “Meta-packages for WSL (Windows Subsystems for Linux)”.
How to copy files from Linux to WSL2. Where are Kali Linux files stored in WSL2. How to access Linux filesystem in WSL2
Previously, you had to pick files in%userprofile%\AppData\Local\Packages, and you could really break everything.
Then (now) the the situation has improved and now the distribution files are available along the path (you need to enter in the file manager, File Explorer)
For example, you can find files in Kali Linux along the path:
From within the distribution, you can open Explorer, which allows you to move files from the guest to the host machine and reverse:
But this only works if the corresponding Linux distribution is running.
The future is great, an icon with a penguin will appear in Explorer and you can view the contents of virtual disks of installed distributions.
It seems that it is not even necessary to run them for this.
This future will come this fall, or next spring, or never.
How to change the password complexity policy in WSL2
I wanted to change the password for my Kali Linux in WSL2. It took me about 20 minutes – no kidding … I couldn’t invent a password that the system would accept due to the requirements for password complexity. This is despite the fact that connecting to Linux in WSL2 (actually logging in) is performed without entering a password at all. It’s “delightfully” logical and thoughtful …
The funny thing is that the root user password can be set any – the password strength settings do not apply to it…
This is not a full error screen – I kept trying and trying to come up with a password that the system will accept.
If you need the ability to set a password of any complexity, then open the file /etc/pam.d/common-password:
Find the line in it
And remove from it the word obscure, which is responsible for checking the complexity of the password. To set a password of any length, add minlen=1, I got the following line (this is a test machine in which I often enter commands and I do not want to waste time on a long password with special characters):
How to use systemctl in WSL2
No way. Systemctl is simply absent in WSL2, as are background server processes.
How to launch Win-KeX with keyboard shortcut in PowerShell
In PowerShell 7, you can set a keyboard shortcut to open Kali Linux right away from the GUI.
Since PowerShell 7 is in preview right now, we’ll edit the JSON text configuration file to just set the keyboard shortcut to run the command.
You will be asked which program to open the .json file.
Click More Apps and select Notepad.
Add the following text to the profile list:
This will add a new item.
Instead of this text, you can use a more advanced option – the shortcut will have a Kali icon and will run in the kali home folder.
First, copy the kali-menu.png icon to the c:/users/WINDOWS USER/pictures/icons/ folder, then paste instead of the previous text:
Tip: If you are running different Linux distributions in WSL, you can force win-kex to start in Kali by changing the command line to:
Источник