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

Windows 11 24H2 26100 has WMIC disabled by default #254

Open
HuFlungDu opened this issue Jul 12, 2024 · 13 comments · May be fixed by #255 or Ylianst/MeshCentral#6320
Open

Windows 11 24H2 26100 has WMIC disabled by default #254

HuFlungDu opened this issue Jul 12, 2024 · 13 comments · May be fixed by #255 or Ylianst/MeshCentral#6320

Comments

@HuFlungDu
Copy link

When installing an agent on Windows 11 24H2 26100 (Early preview), I receive the error:

..\microscript\ILibDuktape_ScriptContainer.c:1667 (0,0) uncaught: ‘cannot read property \x27split\x27 of null

I can't verify for sure that this is coming from WMIC missing because it doesn't give me a stack trace, but meshagent does use WMIC and attempt to parse the results, and it is what is in common with the devices on which I have seen this occur, so it seems probable.

WMIC was deprecated in 2021, and it seems like the chickens are finally coming home to roost on this. It also looks like it may need to be replaced with a powershell script, according to this blog post.

@si458
Copy link
Collaborator

si458 commented Jul 12, 2024

This isn't a bug but something wrong with ur setup of windows

Please see issues in main meshcentral about this issue
Ylianst/MeshCentral#3791

Also here in meshagent repo too #121

@HuFlungDu
Copy link
Author

Yeah, it's not a "bug" currently, it's fixable by installing WMIC (The linked post does not fix it, because the issue is that the wmic executable does not exist on the system), but Microsoft is already in the process of removing the WMIC executable, so this will eventually become a problem that is only solvable by modifying the agent source. Even now, the agent does not work on default windows installations from 24H2 26100, and requires an additional installation step which is not documented anywhere as far as I can tell. It's probably a good idea to update the code now, before it becomes totally broken on future windows versions.

@si458
Copy link
Collaborator

si458 commented Jul 12, 2024

if you can share the steps how you installed the WMIC on those version of windows,
we can add it to the docs to help others 👍

@HuFlungDu
Copy link
Author

Open an administrator powershell and run:

DISM /Online /Add-Capability /CapabilityName:WMIC~~~~

This will work as long as you have permissions to do so. Some organizations will block that capability, though. I don't think there's any way around it if your organization does that.

@dinger1986
Copy link

dinger1986 commented Jul 24, 2024

basically need to change the WMIC commands to powershell,

For example (I think cause no very little about JS

 execFile('powershell', ['-Command', 'Get-WmiObject -Query "SELECT OSLanguage FROM Win32_OperatingSystem" | Select-Object -ExpandProperty OSLanguage'], (error, stdout, stderr) => {

could replace

var child = require('child_process').execFile(process.env['windir'] + '\\system32\\wbem\\wmic.exe', ['wmic', 'os', 'get', 'oslanguage','/FORMAT:LIST']);

@si458
Copy link
Collaborator

si458 commented Jul 24, 2024

@dinger1986 if u check the code tho wmic is listed in quite a few places including meshcentral and meshagent

@dinger1986
Copy link

14 functions or commands need replaced, most have drop in replacements ie restarting a service can be done with net stop/net start

@HuFlungDu
Copy link
Author

I would like to try to take a stab at tackling this, but I can't find any information about building the agent and the testing process, etc. Is there any documentation about building the agent on different environments and then testing the newly built code? Just open the sln in visual studio(?), build, and replace the executables in my meshcentral instance? Just guesses, I'm not so familiar with this part of the meshcentral process.

@si458
Copy link
Collaborator

si458 commented Aug 7, 2024

I would like to try to take a stab at tackling this, but I can't find any information about building the agent and the testing process, etc. Is there any documentation about building the agent on different environments and then testing the newly built code? Just open the sln in visual studio(?), build, and replace the executables in my meshcentral instance? Just guesses, I'm not so familiar with this part of the meshcentral process.

That's basically the process!

If it's all C code you need to change, open VS then edit n build, copy, restart let it autouodate machines or download and reinstall For windows agents

However, if you have to change any of the modules in the modules folder, u have to change them. Then, convert them into the tuktape js, then build the meshagent

I'll write a docs later how to do it for you, the is already a few guide in issues explaining how to do it, just can't find links at moment

@dinger1986
Copy link

I would like to try to take a stab at tackling this, but I can't find any information about building the agent and the testing process, etc. Is there any documentation about building the agent on different environments and then testing the newly built code? Just open the sln in visual studio(?), build, and replace the executables in my meshcentral instance? Just guesses, I'm not so familiar with this part of the meshcentral process.

I have looked through the code and found all the references, it should be just a case of replacing the wmic commands with native powershell commands but the outputs will need to be checked that they are the same, there is references both in the client and the server so both places will need changed, Im on the unofficial mesh discord if that helps?

@HuFlungDu
Copy link
Author

HuFlungDu commented Aug 8, 2024

I have looked through the code and found all the references, it should be just a case of replacing the wmic commands with native powershell commands but the outputs will need to be checked that they are the same, there is references both in the client and the server so both places will need changed, I'm on the unofficial mesh discord if that helps?

Yeah, mostly they are replaceable with Get-CimInstance, I've run through both the server and the client and found the replacements for each of them. The output formatting is very different, however, so they need to be parsed very differently. The upside is that, with Select-Object, the parsing should actually be much less work. Mostly it's just a matter of getting it built and testing. The only one I haven't found a great replacement with is:

var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'qfe', 'list', 'full', '/FORMAT:CSV']);

My current plan is Get-CimInstance Win32_QuickFixEngineering, but that doesn't give all the same info as the one I'm replacing. Since the parsing of that command just grabs EVERYTHING it sees there, I can't validate what this should look like. Do you happen to know what wmic qfe does under the hood, or how to make the Get-CimInstance output all the same info as the original?

@si458, there are changes in the modules. I figured out how to get the C built, but I can't figure out how to convert the modules into tuktape; I see that some of the duktape C code contains javascript code as strings, but none of them seem to be the code I'm changing. Is converting a manual process, or is there a compilation tool for that?

@dmikoss
Copy link

dmikoss commented Aug 9, 2024

how to convert the modules into tuktape

I don't know if this is the correct way, but you can integrate JS modules like this (works in windows powershell).
Place 'meshagent.exe' in MeshAgent folder, set current directory MeshAgent. Then run commands:

$pwd = "${PWD}".Replace('\', '/') 
./meshagent -exec "require('code-utils').shrink({modulesPath:'${pwd}/modules',filePath:'${pwd}/microscript/ILibDuktape_Polyfills.c'});process.exit();"

Paths must be with forward slashes.
ILibDuktape_Polyfills.c will contain JS modules in Base64 form.
After recompile agent C code in Visual Studio (don't tried this yet).

@HuFlungDu
Copy link
Author

HuFlungDu commented Aug 9, 2024

Paths must be with forward slashes. ILibDuktape_Polyfills.c will contain JS modules in Base64 form.

Ah, I didn't consider they might be base64. I had to add "expandedModules" to make it work, but it does work. My concern with this is there are some comments in that file currently, and also some ifdefs, but this method doesn't re-generate them. It kinda looks like those comments might have been added manually, since they aren't wholly consistent, but I'm not sure. Either way, it makes me think this may not be the intended workflow, though it will unblock me for doing the actual important fixes now. I can figure out how to integrate them properly before I PR.

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