Linux on Windows 10 (WSL)
In the previous posts, we focused on how to Install Kali on Windows 10 and useful Kali Linux commands for Windows 10, in this period of time the Windows Subsystem on Linux has changed and received many updates and new capabilities.
Alongside distributions such as KALI, Microsoft made it easier to run multiple Linux distros inside Windows 10. All you need to do is enable the WSL, using turn Windows Features On and Off, and then install any supported distribution from the Windows Store. You can run multiple distributions simultaneously, isolated from each other.
Windows Subsystem for Linux (WSL) is a compatibility layer for running Linux binary executables (ELF format) natively on Windows 10. WSL provides a Linux-compatible kernel interface developed by Microsoft, which can then run a GNU userland on tops of it, such as that of Ubuntu, openSUSE, SUSE Linux Enterprise Server, Debian, and Kali Linux. Such a userland might contain a Bash shell and command language, with native GNU/Linux command-line tools (sed, awk, etc.) and programming language interpreters (Ruby, Python, etc.).
Each Linux distribution has its own set of commands and utilities. You can’t run CentOS or openSUSE specific commands on Ubuntu. If you are running any of these distributions on your cloud, access to these distributions on your Windows machine allows you to use native command at both places.
WSL now runs multiple Linux distros
Microsoft continues to add more capabilities to WSL. Now you can even mount drives and run commands locally. You can use it to manage your local systems with all those great Linux command-line tools.
Does that mean you can also run Linux desktop apps on Windows 10? Yes, theoretically, there are workarounds so you can run GUI Linux apps in Windows 10 via WLS, but that’s not the intended goal of the WSL project. The primary goal is to enable developers to run the command-line tools they need.
Then head over to the Windows Store and download Ubuntu, or Debian, or Kali, or whatever.
So, what’s happening is you’re running user-mode Linux without the Linux Kernel. The system calls that these un-modified Linux uses are brokered over to Windows. It a pico process in Windows and shows up in the task manager.
Want to edit Windows files and edit them both in Windows and in Linux? Keep your files/code in /mnt/c/ and you can edit them with other OS. Don’t use Windows to “reach into the Linux file system.”
WSL has got support for long-running background tasks, similar to how the Win32 subsystem has Serviced. This is an impressive change for users of WSL who work with servers like Apache or apps like screen or tmux and now they can run in the background like regular Linux daemons.
With wslpath.exe you can use to convert paths between Windows and Linux. You should run wslpath in a WSL environment.
It comes with the following options:
-a Force result to absolute path format
-u Translate from a Windows path to a WSL path (default)
-w Translate from a WSL path to a Windows path
-m Translate from a WSL path to a Windows path, with ‘/’ instead of ‘\\’
Starting with the Windows 10 (version 1709). You’ve got a command called wslconfig. Try it out, it lists distros you have and controls which one starts when you type bash.
Check out below that my default for bash is Ubuntu 16.04, but I can run 18.04 manually if I like. See how I move from cmd into bash and exit out, then go back in, seamlessly. Again, no VM. You can also pipe things into Linux commands by piping to wsl or bash. If you’re in Windows, running cmd or PowerShell, it’s best to move into Linux by running wsl or bash as it keeps the current directory.
There’s a file in /etc/wsl.conf that lets you control things like if your Linux of choice automounts your Windows drives. You can also control more advanced things like if Windows autogenerates a hosts file or processes /etc/fstab. It’s up to you!
There are a many distros available and more coming, but you can also make your own package for Linux distribution for WSL with packager distro-launcher at GitHub.
Docker and WSL
Wants to know if you can run Docker natively on WSL. No, that’s Inception, and as mentioned, the Linux Kernel is not present. The unmodified elf binaries work fine but Windows does the work.
You can run Docker for Windows and click Expose daemon on localhost:2375 and since Windows and WSL/Linux share the same port space, you CAN run the Docker client very happily on WSL.
Coding and Editing
Do not change Linux files using Windows apps and tools. But, you can share files and edit them with both Windows and Linux by keeping the code on the Windows filesystem.
Let’s take an example if my work is at c:\github so it’s also at /mnt/c/GitHub. I use Visual Studio code and edit my code there and I run the code from Linux. I can even run bash/wsl from within Visual Studio Code using its integrated terminal. Just hit ctrl+p in Visual Studio Code and type select default shell.
WSL and Penetration Testing
My favorite on WSL is the Kali Linux Penetration Testing (PWK), the sources contain a large amount of penetration testing tools from various different niches of the security and forensics.
With PWK on Windows 10, you can simulate a full penetration test from start to finish, by injecting the student into a target-rich, diverse, and vulnerable network environment.
The Tar and Curl commands have also arrived in Windows 10.