microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.25k stars 812 forks source link

External Wifi Adapter Support #8240

Open morpheuslord opened 2 years ago

morpheuslord commented 2 years ago

hello, I am a tester and I find using WSL over any other virtualization easy and when I am doing WIFI pentesting I need to use a external adapter which can support monitor mode but I looked up every single blog on the internet and none have pleasing results please help.

akuropka commented 2 years ago

https://github.com/dorssel/usbipd-win for attaching external USB devices. You should’ve come across if you checked every single piece of the i-net.

morpheuslord commented 2 years ago

Well I have tried it and this also has a lot of issues like I could not understand how should I update my kernel and secondly the build libraries for the adapter also won't install as the general libraries for the specific kernel is not present in the repository and in short I wanted to say that:

kernel update or upgrade is a hassle kernel repository not found mirrors not getting installed

The above won't allow me to link the usb adapter and them install the drivers for the adapters.

Thank you and hope you understand

EDLLT commented 2 years ago

Well I have tried it and this also has a lot of issues like I could not understand how should I update my kernel and secondly the build libraries for the adapter also won't install as the general libraries for the specific kernel is not present in the repository and in short I wanted to say that:

kernel update or upgrade is a hassle kernel repository not found mirrors not getting installed

The above won't allow me to link the usb adapter and them install the drivers for the adapters.

Thank you and hope you understand

Hey bro, I am facing the exact same problem did you find any solution to the problem?

Currently, I am messing around with the WSL kernel build trying to get my driver load in but with no avail

morpheuslord commented 2 years ago

No bro

EDLLT commented 2 years ago

No bro

I MADE IT! IT WORKED!!!

THIS WAS ONE OF THE MOST COMPLICATED THINGS IN MY LIFE PROBABLY LOL

Okay so, holy crap that wasn't easy I had to stay up late till night for about 4 days trying to figure out how to do this as I had never compiled a kernel before. it was a very very steep learning curve for me

Now, everything works wlan0 is appearing as an external wifi adapter, injections work etc etc

I am gonna create a fork of that original project put everything there along with how to do it

ngl, I thought that it was impossible and was just playing around, and suddenly everything clicked and it worked

EDLLT commented 2 years ago

Here https://github.com/EDLLT/WSL2-Linux-Kernel

morpheuslord commented 2 years ago

bro can you make a detailed a youtube vid on the installation and everything this will be a life save for hackers man

GamerGirlandCo commented 1 year ago

bro can you make a detailed a youtube vid on the installation and everything this will be a life save for hackers man

just clone https://github.com/microsoft/WSL2-Linux-Kernel.git and apply this patch :)

morpheuslord commented 1 year ago

Gonna try it and will update of it worked

morpheuslord commented 1 year ago

I am a complete noob when it comes to working with makefiles and their patches 😢 help please

akuropka commented 1 year ago

@morpheuslord: Hmm, a "hacker" should be aware of such basics. The link in https://github.com/microsoft/WSL/issues/8240#issuecomment-1112581581 should bring you further without building by yourself.

morpheuslord commented 1 year ago

@akuropka it's not like I don't understand the process or how it's done but when it comes to C programming and concepts like bug fixing in C is really not the strong suite I tried compiling and made sure it works for my WLS once but I could not successfully imply these patches I always ran into some weird errors which had no certain answer.

ishaan-kapoor commented 7 months ago

hey, could you get it to work?

morpheuslord commented 7 months ago

nope not working.

TheAjaykrishnanR commented 3 months ago

It works ! for anybody wondering. Tried it with rtl8821au. You are a legend @EDLLT

TheAjaykrishnanR commented 3 months ago

nope not working.

https://youtu.be/l7VQQJdePlk

morpheuslord commented 3 months ago

nope not working.

https://youtu.be/l7VQQJdePlk

hey so I tried it but was not able to find the drivers for Qualcomm Atheros AR9271 to run it according to the video 🥹. I am facing a compilation issue.

TheAjaykrishnanR commented 3 months ago

nope not working.

https://youtu.be/l7VQQJdePlk

hey so I tried it but was not able to find the drivers for Qualcomm Atheros AR9271 to run it according to the video 🥹

https://cateee.net/lkddb/web-lkddb/ATH9K_HTC.html - i think its in there by default, https://github.com/EDLLT/WSL2-Linux-Kernel/tree/linux-msft-wsl-5.10.y/drivers/net/wireless/ath/ath9k

image

can you try enabling this ?

morpheuslord commented 3 months ago

nope not working.

https://youtu.be/l7VQQJdePlk

hey so I tried it but was not able to find the drivers for Qualcomm Atheros AR9271 to run it according to the video 🥹

https://cateee.net/lkddb/web-lkddb/ATH9K_HTC.html - i think its in there by default, https://github.com/EDLLT/WSL2-Linux-Kernel/tree/linux-msft-wsl-5.10.y/drivers/net/wireless/ath/ath9k

image

can you try enabling this ?

I had to elaborate, i did this but this is the issue during compilation " AR init/built-in.a LD vmlinux.o ld: warning: arch/x86/lib/retpoline.o: missing .note.GNU-stack section implies executable stack ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker MODPOST vmlinux.symvers MODINFO modules.builtin.modinfo GEN modules.builtin LD .tmp_vmlinux.btf ld: warning: arch/x86/lib/retpoline.o: missing .note.GNU-stack section implies executable stack ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker ld: warning: .tmp_vmlinux.btf has a LOAD segment with RWX permissions BTF .btf.vmlinux.bin.o LD .tmp_vmlinux.kallsyms1 ld: warning: .btf.vmlinux.bin.o: missing .note.GNU-stack section implies executable stack ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker ld: warning: .tmp_vmlinux.kallsyms1 has a LOAD segment with RWX permissions KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 ld: warning: .btf.vmlinux.bin.o: missing .note.GNU-stack section implies executable stack ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker ld: warning: .tmp_vmlinux.kallsyms2 has a LOAD segment with RWX permissions KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD vmlinux ld: warning: .btf.vmlinux.bin.o: missing .note.GNU-stack section implies executable stack ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker ld: warning: vmlinux has a LOAD segment with RWX permissions BTFIDS vmlinux FAILED: load BTF from vmlinux: Unknown error -22make: *** [Makefile:1179: vmlinux] Error 255

"

I am using kali-linux for this process.

TheAjaykrishnanR commented 3 months ago

@morpheuslord ignoring the compiler's warning flags, this is the main error : FAILED: load BTF from vmlinux: Unknown error -22make: *** [Makefile:1179: vmlinux] Error 255 Where are you running this on ? Do you have around 10 GBs of RAM ?

morpheuslord commented 3 months ago

@morpheuslord ignoring the compiler's warning flags, this is the main error : FAILED: load BTF from vmlinux: Unknown error -22make: *** [Makefile:1179: vmlinux] Error 255 Where are you running this on ? Do you have around 10 GBs of RAM ?

on a VM and I have 16Gb of RAM on it.

TheAjaykrishnanR commented 3 months ago

@morpheuslord ignoring the compiler's warning flags, this is the main error : FAILED: load BTF from vmlinux: Unknown error -22make: *** [Makefile:1179: vmlinux] Error 255 Where are you running this on ? Do you have around 10 GBs of RAM ?

on a VM and I have 16Gb of RAM on it.

can you try changing CONFIG_DEBUG_INFO_BTF=y to CONFIG_DEBUG_INFO_BTF=n in Microsoft/config-wsl ? Are you really giving 16 gbs of ram on your VM ?

morpheuslord commented 3 months ago

@morpheuslord ignoring the compiler's warning flags, this is the main error : FAILED: load BTF from vmlinux: Unknown error -22make: *** [Makefile:1179: vmlinux] Error 255 Where are you running this on ? Do you have around 10 GBs of RAM ?

on a VM and I have 16Gb of RAM on it.

can you try changing CONFIG_DEBUG_INFO_BTF=y to CONFIG_DEBUG_INFO_BTF=n in Microsoft/config-wsl ? Are you really giving 16 gbs of ram on your VM ?

Yes I have 16GB on a VM, its currently late in the night so I will test it and update it tomorrow.

TheAjaykrishnanR commented 3 months ago

@morpheuslord ignoring the compiler's warning flags, this is the main error : FAILED: load BTF from vmlinux: Unknown error -22make: *** [Makefile:1179: vmlinux] Error 255 Where are you running this on ? Do you have around 10 GBs of RAM ?

on a VM and I have 16Gb of RAM on it.

can you try changing CONFIG_DEBUG_INFO_BTF=y to CONFIG_DEBUG_INFO_BTF=n in Microsoft/config-wsl ? Are you really giving 16 gbs of ram on your VM ?

Yes I have 16GB on a VM, its currently late in the night so I will test it and update it tomorrow.

sure ! im building it myself, will share it if it works

morpheuslord commented 3 months ago

@TheAjaykrishnanR yup it's built with no errors, but wsl won't boot. It has now been 30min and there has been no reaction from wsl.

TheAjaykrishnanR commented 3 months ago

@TheAjaykrishnanR yup it's built with no errors, but wsl won't boot. It has now been 30min and there has been no reaction from wsl.

can you run wsl -l -v to make sure you are running wsl 2 ? anyways i had built it without changing that flag, check this kernel image after extracting the archive : https://www.dropbox.com/scl/fi/3cm7twaf4inlf4zqwviid/kernel_plus_modules_ath9k.tar.gz?rlkey=987wkudxvusrqms8ezzulfz5v&st=pge88leq&dl=0

morpheuslord commented 3 months ago

@

TheAjaykrishnanR commented

It worked, thanks man. I dont know what was wrong with my current build but yours did work. now its booting. but drivers wont work.

$ iwconfig
lo        no wireless extensions.

bond0     no wireless extensions.

dummy0    no wireless extensions.

tunl0     no wireless extensions.

sit0      no wireless extensions.

eth0      no wireless extensions.

I lost hope at this point 🥹 .

dmesg | grep ath

[   15.420949] usb 1-1: ath9k_htc: Firmware ath9k_htc/htc_9271-1.4.0.fw requested
[   15.421674] usbcore: registered new interface driver ath9k_htc
[   15.422262] usb 1-1: Direct firmware load for ath9k_htc/htc_9271-1.4.0.fw failed with error -2
[   15.422953] usb 1-1: ath9k_htc: Firmware htc_9271.fw requested
[   15.424404] usb 1-1: ath9k_htc: Failed to get firmware htc_9271.fw
[   15.424946] usb 1-1: ath9k_htc: USB layer deinitialized

I installed the firmware firmware-atheros and restarted wsl but still no luck.

TheAjaykrishnanR commented 3 months ago

@

TheAjaykrishnanR commented

It worked, thanks man. I dont know what was wrong with my current build but yours did work. now its booting. but drivers wont work.

$ iwconfig
lo        no wireless extensions.

bond0     no wireless extensions.

dummy0    no wireless extensions.

tunl0     no wireless extensions.

sit0      no wireless extensions.

eth0      no wireless extensions.

I lost hope at this point 🥹 .

dmesg | grep ath

[   15.420949] usb 1-1: ath9k_htc: Firmware ath9k_htc/htc_9271-1.4.0.fw requested
[   15.421674] usbcore: registered new interface driver ath9k_htc
[   15.422262] usb 1-1: Direct firmware load for ath9k_htc/htc_9271-1.4.0.fw failed with error -2
[   15.422953] usb 1-1: ath9k_htc: Firmware htc_9271.fw requested
[   15.424404] usb 1-1: ath9k_htc: Failed to get firmware htc_9271.fw
[   15.424946] usb 1-1: ath9k_htc: USB layer deinitialized

I installed the firmware firmware-atheros and restarted wsl but still no luck.

bro did you follow the entire tutorial ? Did you install the built modules ? copy the wsl2-modules into /lib. You have to use modprobe to load the .ko file each time you log onto wsl. Also use USB IPD to share the adapter with wsl. Follow the steps exactly. Also where does it say to install the firmware-atheros ?

All you have to do is :

  1. cd /lib/modules/5.10.102.1-microsoft-standard-WSL2+/kernel/drivers/net/wireless/ath/
  2. sudo modprobe ath9k_htc
  3. lsmod to check if the module is loaded
morpheuslord commented 3 months ago

@TheAjaykrishnanR yes its loaded.

image

image

TheAjaykrishnanR commented 3 months ago

@morpheuslord do you have the htc_9271.fw file in /lib/firmware ?

Anyways, I added the firmware directly to the kernel using CONFIG_EXTRA_FIRMWARE and compiled it again.

Use this kernel and it should hopefully work : https://www.dropbox.com/scl/fi/ik09bxk2uga3w3pniw6oe/kernel-plus-modules-ath9k-htc9271-fw.tar.gz?rlkey=uulfkbsonwe9hlwero73kv6ca&st=u1eltkxr&dl=0

morpheuslord commented 3 months ago

@morpheuslord do you have the htc_9271.fw file in /lib/firmware ?

Anyways, I added the firmware directly to the kernel using CONFIG_EXTRA_FIRMWARE and compiled it again.

Use this kernel and it should hopefully work : https://www.dropbox.com/scl/fi/ik09bxk2uga3w3pniw6oe/kernel-plus-modules-ath9k-htc9271-fw.tar.gz?rlkey=uulfkbsonwe9hlwero73kv6ca&st=u1eltkxr&dl=0

Yes I tried both types of the .fx files but now worked I managed to get it to load but the dmesg says another story.

TheAjaykrishnanR commented 3 months ago

@morpheuslord do you have the htc_9271.fw file in /lib/firmware ? Anyways, I added the firmware directly to the kernel using CONFIG_EXTRA_FIRMWARE and compiled it again. Use this kernel and it should hopefully work : https://www.dropbox.com/scl/fi/ik09bxk2uga3w3pniw6oe/kernel-plus-modules-ath9k-htc9271-fw.tar.gz?rlkey=uulfkbsonwe9hlwero73kv6ca&st=u1eltkxr&dl=0

Yes I tried both types of the .fx files but now worked I managed to get it to load but the dmesg says another story.

you dont need the .fw files anymore, its embedded in the kernel image

morpheuslord commented 3 months ago

@morpheuslord do you have the htc_9271.fw file in /lib/firmware ? Anyways, I added the firmware directly to the kernel using CONFIG_EXTRA_FIRMWARE and compiled it again. Use this kernel and it should hopefully work : https://www.dropbox.com/scl/fi/ik09bxk2uga3w3pniw6oe/kernel-plus-modules-ath9k-htc9271-fw.tar.gz?rlkey=uulfkbsonwe9hlwero73kv6ca&st=u1eltkxr&dl=0

Yes I tried both types of the .fx files but now worked I managed to get it to load but the dmesg says another story.

you dont need the .fw files anymore, its embedded in the kernel image

your new kernel worked, as I was talking about before. image

Thanks for that man, really appreciate it 👍.

snehashis365 commented 2 months ago

It works ! for anybody wondering. Tried it with rtl8821au. You are a legend @EDLLT

Hey man I have been trying to compile for this chipset but I keep running into memory bottleneck since you have already compiled for this can you share me the final tarball with the 8821au module, I tried by disabling the debug btf flag but it won't boot in that case

TheAjaykrishnanR commented 2 months ago

It works ! for anybody wondering. Tried it with rtl8821au. You are a legend @EDLLT

Hey man I have been trying to compile for this chipset but I keep running into memory bottleneck since you have already compiled for this can you share me the final tarball with the 8821au module, I tried by disabling the debug btf flag but it won't boot in that case

yeah here you go : https://www.dropbox.com/scl/fi/ex9q3ba9rqz3tt3w37k0l/wsl2-kernel-plus-modules-rtl8821au.tar.gz?rlkey=yhbjc00cls7iecu2u2b97h8ak&st=672dtq1d&dl=0

snehashis365 commented 2 months ago

yeah here you go : https://www.dropbox.com/scl/fi/ex9q3ba9rqz3tt3w37k0l/wsl2-kernel-plus-modules-rtl8821au.tar.gz?rlkey=yhbjc00cls7iecu2u2b97h8ak&st=672dtq1d&dl=0

Thanks it worked!!

Geofferey commented 2 months ago

I was able to sucessfully compile the latest WSL kernel relatively easily given all the information here. However, I experienced issue where flipping into monitor mode would crash WSL. Turns out the driver I had used wasn't good for whatever reason.

Here is the driver that worked for me: https://github.com/ivanovborislav/rtl8821au

The driver I initially chose: https://github.com/aircrack-ng/rtl8812au

mieucun123 commented 5 days ago

It works ! for anybody wondering. Tried it with rtl8821au. You are a legend @EDLLT

can you please help me with the TL-WN722N V1?