Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checks for Windows Subsystem for Linux on Windows 10 #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mccarrmb
Copy link

@mccarrmb mccarrmb commented Aug 3, 2018

The new Windows Subsystem for Linux allows guest Linux OS's to seamlessly masquerade as an actual Linux host. However, these guests have the ability to run both Windows and Linux binaries - necessitating a need to determine if the underlying OS is actually Windows-based.

This code has been tested in MinGW32, CygWin, macOS, Ubuntu, Ubuntu on WSL, Kali on WSL, and Windows 10.

@rdp
Copy link
Owner

rdp commented Oct 13, 2018 via email

@mccarrmb
Copy link
Author

Yeah this is an odd one because of how WSL works. Normally, Cygwin executables either have hooks for the Cygwin DLL or they're compiled from source under the Cygwn environment. This means that there is an environment limitation that would be helpful for Ruby to be aware of. WSL, however, is like a seamless super-set of both native Linux and Windows NT executable types.

Normally, I would have left the existing behavior as-is since it wasn't really wrong to determine that the environment was Linux. Unfortunately, I'm using these changes to identify a special edge case for browser automation. These changes allow me to use a sane implementation of Ruby while enabling the ability to detect the existence of Microsoft web browser resources.

@rdp
Copy link
Owner

rdp commented Oct 16, 2018 via email

@mccarrmb
Copy link
Author

Maybe a method that detects the type of binary formats that can be executed in the current environment?

@rdp
Copy link
Owner

rdp commented Oct 17, 2018 via email

@mccarrmb
Copy link
Author

mccarrmb commented Mar 19, 2019

I've been thinking about this for a while and have since looked to the official documentation to see how these types of environments determine whether Windows PE executables can be run. According to the Interoperability Documentation, the key determining factor is provided by the /proc/sys/fs/binfmt_misc/WSLInterop file existing and being set to enabled. In fact, setting this to a "disabled" state will prevent any Windows PE code from running in the subsystem at all.

Would it be acceptable to modify this submission to key off of this WSL interop process? My intent with this change would be to determine whether Windows executable resources would be available within an environment that appeared to be Linux-based.

@rdp
Copy link
Owner

rdp commented Mar 21, 2019 via email

@mccarrmb
Copy link
Author

I like your idea of a new method "windows exe's can run" or what not...wait should that include wine? maybe just cygwin and wsl for now? :)

On Tue, Mar 19, 2019 at 3:44 PM Whitey @.***> wrote: I've been thinking about this for a while and have since looked to the official documentation to see how these types of environments determine whether Windows PE executables can be run. According to the Interoperability Documentation https://docs.microsoft.com/en-us/windows/wsl/interop, the key determining factor is provided by the /proc/sys/fs/binfmt_misc/WSLInterop file existing and being set to enabled. In fact, setting this to a "disabled" state will prevent any Windows PE code from running in the subsystem at all. Would it be acceptable to modify this submission to key off of this WSL interop process? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#33 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAw0JWt71FMTScd4gDglq2QB_ye-rErks5vYVojgaJpZM4VuN_h .

I think Wine could eventually be included, I would just have to find a reliable way to determine that it is installed.

WSL is a bit of a special case, though. What differentiates WSL from Wine is that there is no API call translation going on since the host offers native Windows resources. It's also distinct in that the presence of the WSL service implies that the user has at least a minimum installation of Windows binaries at their disposal (for instance, users can run tools such as regedt32.exe, net.exe, ipconfig.exe, etc...). The Linux environment under WSL blends so extremely well into Windows that users may as well settle for the fact that the OS is, in fact, a bare metal Linux machine. In this case, I think treating WSL like an OS feature set akin to 64-bit capability rather than an 'underlying' OS is a better philosophical approach than my original implementation.

In my personal use case, this is extremely important because I use a platform-agnostic Ruby application to run browser automation on Linux, macOS, and Windows hosts. By having my Windows hosts running WSL, it's much easier to port over proper behavior from my existing Linux-specific methods. This allows me to behave and log activity as though it's I'm still in a Linux context, but launch Windows-only browsers such as Internet Explorer and Edge for testing. Definitely makes my implementation easier to maintain.

@rdp
Copy link
Owner

rdp commented Mar 21, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants