Bureau Kali sur Windows 10

Install Kali Linux on Windows 10 with WSL 2 in 2024

Published at 6/4/2024, 8:25:00 AM

Regardless of the thorough official documentation, installing Kali on WSL 2 was not as easy as Network Chuck made me expect. Since my beginnings in IT, I had taken a habit of launching virtual machines with third party softwares like VirtualBox or VmWare, in order to have the distribution I need, at my disposal. Resources are shared between the host's operating system and the one of the virtual machine. Which makes using both at the same time a computer killer from time to time, especially if you have less than 16Gb of RAM on your workstation...

Install Kali Linux like it was an app, directly from the microsoft store

That's a promising thought, and I tried it immediately. I recently needed to reproduce the environment of a production server. I managed to install Ubuntu directly from the Microsoft store, in 1 click, and using it was pretty smooth. I had indeed access to an Ubuntu Cli directly from the good old Windows search bar, and could easily run the needed stuff to make my development version work.

After that experience, and mostly after a competition on which I mainly struggled with my components, I figured I should give it a shot for Kali. Here's how to proceed, with administrator rights on a Powershell window, according to the official Kali distribution's documentation:

Install Kali with WSL 2

Easy peasy! And we now have access to Kali Linux's command line interface, running as an app on our PC. Now it's time to update and upgrade the new machine, with the apropriate package manager, like we do at every new VM. However that's when the problems began:

Nothing to restart...

Indeed, running the command doesn't throw an error message, but will stay undefinitely hanging on the line "Nothing to restart".

┌──(starlord㉿synthweb)-[~]
└─$ sudo apt upgrade -y

Response:

Unpacking libc6:amd64 (2.38-10) over (2.37-12) ...
Setting up libc6:amd64 (2.38-10) ...
Checking for services that may need to be restarted...
Checking init scripts...
Nothing to restart.

Troubleshooting installation errors

This error is relative to the Linux environment, which can't find systemd services to restart for the last package in the list, then hangs when no running service is found.

Thankfully, there are a few ways to get out of it:

1. Direct and dirty way

If you followed the official Kali documentation and you encountered the error describe above, the rest is for you. If you didn't attempt an upgrade yet, you can skip to point 2.

The first thing to do is to reopen a new Powershell window and run Kali again:

Windows PowerShell
Copyright (C) Microsoft Corporation. Tous droits réservés.

Testez le nouveau système multiplateforme PowerShell https://aka.ms/pscore6

PS C:\Users\starlord> wsl -l -v
  NAME                   STATE           VERSION
* docker-desktop         Running         2
  Ubuntu                 Stopped         2
  docker-desktop-data    Stopped         2
  kali-linux             Running         2
PS C:\Users\starlord> wsl -s kali-linux
L’opération a réussi.
PS C:\Users\starlord> wsl
  • -l for a list of locally installed distributions,
  • -v pour more verbosity,
  • -s for --set-default, or the default behavior of the wsl command alone

Inside Kali's command line, you can use the following commands to quickly recover your apt and dpkg, stop the failing upgrade:

# show a list of running processes
$ ps aux 

# kill processes
$ sudo kill -9 <pid>

# might throw an error
$ sudo dpkg --configure -a

$ sudo apt purge libc6

$ sudo apt install -f libc6
$ sudo apt install -f libc-bin
$ sudo apt install -f
$ sudo apt upgrade 
# to finish what was started

2. Clean and error free method

The libc6 package is an essential package, containing shared C GNU libraries, allowing for most distributions like Debian or Kali to run. The problem can be overcome with the following commands, if you didn't start the upgrade yet:

$ sudo apt update
$ sudo apt purge libc6
$ sudo apt install -f libc-bin -y
$ sudo apt install -f libc6 -y
$ sudo apt upgrade

-f for --fix-broken which will repair the target components' installation.

If you need to delete your Kali Linux installation, you can do it in 2 steps, once Kali is shutdown with --terminate. It needs to be deleted from the Windows applications or programs, by looking for it in the Windows search bar, then typing the following commands in your priviledged Powershell window:

PS C:\Users\starlord> wsl -t kali-linux
PS C:\Users\starlord> wsl --unregister kali-linux

Install a GUI and Win-KeX for optimal integration

Now that Kali is finally upgraded properly, it's time to install some quality of life components, like a GUI and Win-KeX. Still inside Kali's command line:

$ sudo apt install kali-desktop-xfce -y

$ sudo apt install -y kali-win-kex

With Win-KeX, it is possible to quickly lauch the Kali desktop, like a Windows app, in 3 different modes, with sound portage.

# Window Mode
$ kex --win -s

# Seamless Mode
$ kex --sl -s

# Enhanced Session Mode
$ kex --esm --ip -s

H4ppy pentesting!

Kali Windows KeX on WSL 2

starlord-profile

Star-Lord - Développeur


Synthweb.ch - création de site web en Suisse, LinkedIn, Instagram