{"id":25556897,"url":"https://github.com/kevin-doolaeghe/wsl-kernel-modules","last_synced_at":"2025-04-12T02:11:55.841Z","repository":{"id":181214656,"uuid":"590430890","full_name":"kevin-doolaeghe/wsl-kernel-modules","owner":"kevin-doolaeghe","description":"Build kernel modules for WSL2 distros","archived":false,"fork":false,"pushed_at":"2023-01-28T23:21:01.000Z","size":34,"stargazers_count":28,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T02:11:50.499Z","etag":null,"topics":["driver","kali-linux","kernel-module","rtl8812au","wsl2"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevin-doolaeghe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-01-18T12:00:07.000Z","updated_at":"2025-04-01T05:56:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"2066f6d6-3649-47b2-9472-76ca120aa7ff","html_url":"https://github.com/kevin-doolaeghe/wsl-kernel-modules","commit_stats":null,"previous_names":["kevin-doolaeghe/wsl-kernel-modules"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-doolaeghe%2Fwsl-kernel-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-doolaeghe%2Fwsl-kernel-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-doolaeghe%2Fwsl-kernel-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevin-doolaeghe%2Fwsl-kernel-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevin-doolaeghe","download_url":"https://codeload.github.com/kevin-doolaeghe/wsl-kernel-modules/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248505928,"owners_count":21115354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["driver","kali-linux","kernel-module","rtl8812au","wsl2"],"created_at":"2025-02-20T14:56:13.600Z","updated_at":"2025-04-12T02:11:55.815Z","avatar_url":"https://github.com/kevin-doolaeghe.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kali WSL2 - Custom Kernel and `rtl8812au` driver installation\n\n:pushpin: This tutorial demonstrates how to build and use a custom kernel for WSL2 distros.\n\n## Setup Kali WSL2\n\n* Disable password prompt when using `sudo` command :\n```\necho \"kevin ALL=(ALL) NOPASSWD: ALL\" | sudo tee -a /etc/sudoers.d/010_kevin-nopasswd \u003e /dev/null\n```\n\n* Update the system :\n```\nsudo apt update \u0026\u0026 sudo apt upgrade\n```\n\n* Install useful packages :\n```\nsudo apt install bash-completion build-essential gcc g++ avr-libc avrdude default-jre default-jdk git clang make nano xz-utils usbip wget\nsource .bashrc\n```\n\n* Install Kali packages :\n```\nsudo apt install kali-linux-large\n```\n\n* Setup remote access :\n```\nsudo apt install kali-win-kex\nkex --esm -s\n```\n\n## Build and install a custom WSL2 kernel\n\n* Install required packages :\n```\nsudo apt install flex bison libssl-dev libelf-dev git dwarves bc\n```\n\n* Download official WSL2 kernel and prepare the installation :\n```\nwget https://github.com/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-$(uname -r | cut -d- -f 1).tar.gz\ntar -xvf linux-msft-wsl-$(uname -r | cut -d- -f 1).tar.gz\ncd WSL2-Linux-Kernel-linux-msft-wsl-$(uname -r | cut -d- -f 1)\ncat /proc/config.gz | gunzip \u003e .config\nmake prepare modules_prepare -j $(expr $(nproc) - 1)\n```\n\n* Open the kernel's configuration menu to add `cfg80211` wireless modules (802.11 protocols) :\n```\nmake menuconfig -j $(expr $(nproc) - 1)\n```\n\n* Build and install modules :\n```\nmake modules -j $(expr $(nproc) - 1)\nsudo make modules_install\nmake -j $(expr $(nproc) - 1)\nsudo make install\n```\nNote : Kernel headers are going to be installed in the `/lib/modules/` directory.\n\n* Copy the built kernel image to `C:\\Users\\\u003cUser\u003e\\` :\n```\ncp vmlinux /mnt/c/Users/Kevin/\n```\n\n* Create a `.wslconfig` file to declare the new kernel :\n```\nnano /mnt/c/Users/Kevin/.wslconfig\n```\n\n* Paste the following content into this file :\n```\n[wsl2]\nkernel=C:\\\\Users\\\\Kevin\\\\vmlinux\n```\n\n* Switch to Powershell and shutdown running WSL2 distros :\n```\nwsl --shutdown\n```\n:triangular_flag_on_post: When a WSL2 distro will be rebooted, the default WSL2 kernel located in `C:\\Windows\\System32\\lxss\\tools\\kernel` will be replaced by the newly built kernel.\n\n## Compile and load a kernel module\n\nNote : This example illustrates how to build and load the `rtl8812au` module to the WSL2 kernel.\n\n* Clone the `aircrack-ng/rtl8812au` Github repository :\n```\ngit clone https://github.com/aircrack-ng/rtl8812au\ncd rtl8812au\n```\n\n* Build the module with the new kernel headers :\n```\nsudo make\n```\n:white_check_mark: This commands generates a `.ko` file which correspond to the built module.  \n:warning: The headers must be installed in the `/lib/modules/$(uname -r)/build` directory.  \nYou can check your WSL2 version by running `uname -r`.\n\nTest : Enable `cfg80211` and `88XXau.ko` modules :\n```\nsudo modprobe cfg80211\nsudo insmod 88XXau.ko\nlsmod\n```\n:warning: `cfg80211` module must be loaded before `88XXau.ko`.\n\n* Install the module :\n```\nsudo mkdir -p /lib/modules/$(uname -r)/kernel/drivers/net/wireless\nsudo make install\n```\nNote : Now, `sudo modprobe 88XXau` command will work.\n\n* Enable the module :\n```\nsudo modprobe 88XXau\n```\n\n## Load modules at boot time\n\n* Add modules that need to be loaded at boot time to the `/etc/modules-load.d/` directory :\n```\necho \"cfg80211\" | sudo tee -a /etc/modules-load.d/cfg80211.conf\necho \"88XXau\" | sudo tee -a /etc/modules-load.d/88XXau.conf\n```\n:warning: Don't add `.ko` extension to the module name.\n\n## Wi-Fi adapter connection using `rtl8812au` driver :\n\n* Attach a USB device using `usbip` :\n```\nsudo usbip list --remote=\u003cIP\u003e\nsudo usbip attach --remote=\u003cIP\u003e --busid=\u003cBUS-ID\u003e\nip a\n```\n\n* Install `aircrack-ng` packages :\n```\nsudo apt install aircrack-ng pciutils\n```\n\n* Set the adapter in monitor mode :\n```\nsudo airmon-ng\nsudo ip link set wlan0 stop\nsudo airmon-ng start wlan0\n```\n\n* Search WEP networks with `airodump-ng` :\n```\nsudo airodump-ng wlan0 --encrypt WEP\n```\n\n* Test wireless packet injection :\n```\nsudo aireplay-ng -9 -e [SSID] -a [BSSID] --ignore-negative-one wlan0\n```\n\n* Capture IVs and decode WEP key :\n```\nsudo besside-ng -c 11 -b 82:A9:40:96:BE:48 wlan0\n```\n\n* Launch `aircrack-ng` to crack WEP key :\n```\nsudo aircrack-ng wep.cap\n```\n\n* Disable monitor mode on `wlan0` interface :\n```\nairmon-ng stop wlan0\n```\n\n* Detach USB device :\n```\nsudo usbip port\nsudo usbip detach --port=\n```\n\n## Create `usbip` scripts\n\n### Attach a USB device\n\n* Create and edit a file called `musb` :\n```\nnano musb\n```\n\n* Add the following content to this file :\n```\n#!/bin/bash\n\nif ! [ $(id -u) = 0 ]; then\n   echo \"The script need to be run as root.\" \u003e\u00262\n   exit 1\nfi\n\necho \"Enter the IP address of the foreign device :\"\nread ip\n\necho \"\"\nusbip list -r $ip\n\necho \"Enter the name of the shared USB device to import :\"\nread usb\n\necho \"\"\nusbip attach -r $ip -b $usb\n\nsleep 1\nusbip port\n```\n\n* Add execution permissions to the file :\n```\nchmod +x musb\n```\n\n* Run the script :\n```\nsudo ./musb\n```\n\n### Detach a USB device\n\n* Create and edit a file called `musb` :\n```\nnano uusb\n```\n\n* Add the following content to this file :\n```\n#!/bin/bash\n\nif ! [ $(id -u) = 0 ]; then\n   echo \"The script need to be run as root.\" \u003e\u00262\n   exit 1\nfi\n\nusbip port\n\necho \"\"\necho \"Enter the USB device to detach :\"\nread usb\n\necho \"\"\nusbip detach -p $usb\n\nsleep 1\nusbip port\n```\n\n* Add execution permissions to the file :\n```\nchmod +x uusb\n```\n\n* Run the script :\n```\nsudo ./uusb\n```\n\n## References\n\n* [Microsoft Github Repository - WSL2-Linux-Kernel](https://github.com/microsoft/WSL2-Linux-Kernel)\n* [WSL2 `/lib/modules` Stack Exchange Discussion](https://unix.stackexchange.com/questions/594470/wsl-2-does-not-have-lib-modules)\n* [Github Gist - Custom WSL2 Kernel Build](https://gist.github.com/charlie-x/96a92aaaa04346bdf1fb4c3621f3e392)\n* [`RTL8812AU` Driver Installation On RPI](https://raspberrypi.stackexchange.com/questions/120134/install-drivers-for-rtl8812au-for-raspibian-kernel-5-4-79-v71-rpi-4)\n* [Basic `RTL8812AU` Drive Configuration](https://adam-toscher.medium.com/configure-your-new-wireless-ac-1fb65c6ada57)\n* [`aircrack-ng` Deauthentication Attack](https://hackernoon.com/forcing-a-device-to-disconnect-from-wifi-using-a-deauthentication-attack-f664b9940142)\n* [WEP Wi-Fi Network Cracking](https://www.aircrack-ng.org/doku.php?id=simple_wep_crack)\n* [Windows `aireplay-ng` Packet Injection](https://web.archive.org/web/20080921000952/http://airdump.net/aireplay-packet-injection-windows/)\n* [Wireless Capture On Windows](https://blog.packet-foo.com/2019/04/wireless-capture-on-windows/comment-page-1/)\n* [NPCAP Developer Guide](https://npcap.com/guide/npcap-devguide.html)\n* [USB-IP For Windows](https://github.com/kevin-doolaeghe/usbip-win)\n* [WSL2 Setup Guide](https://learn.microsoft.com/fr-fr/windows/wsl/install)\n* [Kali Tools Guide](https://www.kali.org/tools/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevin-doolaeghe%2Fwsl-kernel-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevin-doolaeghe%2Fwsl-kernel-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevin-doolaeghe%2Fwsl-kernel-modules/lists"}