📜 ⬆️ ⬇️

The option of managing a computer on Windows from under the Linux console

There are tasks when you need to do something from under Linux on a machine that has Windows installed, but not via RDP or VNC. Or, for example, as in my case, the main machine on Linux and you need to manage a group of servers. And for simple tasks, such as a simple query like dsquery group -name "" | dsget group -members | dsget user dsquery group -name "" | dsget group -members | dsget user dsquery group -name "" | dsget group -members | dsget user , which will give a complete list of group members in Active Directory with all the fields - do not start the RDP session for the sake of such a session.
I honestly did not find a simple and convenient toolkit. With the exception of two utilities: wmic and winexe, which are included in the Zenoss and OpenVAS kits. Rather entered the Zenoss. Not the point, I did not find them separately, so I propose further my version, mostly for a specific distribution (Xubuntu 13.04), but with proper skill, everything can be done in any other.
So, let's begin:
 wget http://www.openvas.org/download/wmi/wmi-1.3.14.tar.bz2 tar -xvf wmi-1.3.14.tar.bz2 cd wmi-1.3.14\Samba\source\wineexe\ 
Then either manually or using patch -p0 -i patchfile apply the changes from https://gist.github.com/raw/843062/5bb87c4fa13688f65ca8b1e54fc42676aee42e5a/fix_winexe_service.diff .
Then:
 sudo make 
After which you can already do:
 winexe -U domain/user%password //server 'dsquery group -name ""| dsget group -members | dsget user' 
or
 wmic -U domain/user%password //server 'select * from Win32_ComputerSystem' 
The first winexe command allows you to run any console commands via RPC on a Windows machine, the second allows you to make WMI requests, which in general gives you even more options (here is a reference to WQL, this is a version of SQL for WMI - http://msdn.microsoft. com / en-us / library / windows / desktop / aa394606% 28v = vs.85% 29.aspx ).
However, there is a problem with the console output of winexe from a remote machine, because Microsoft loves both UTF-16, and CP1251, and CP866 at once. And in some places and at all UCS-2. More precisely, in my case, the conclusion was in the good old CP866. The problem is solved very simply:
 luit -encoding cp866 winexe -U domain/user%password //server 'cmd' 
And at the conclusion then we have:
 Microsoft Windows [Version 6.1.7601] (c)   (Microsoft Corporation), 2009.   . C:\Windows\system32> 
However, again in my case, luit 1.1 categorically did not want to see charmaps for cp866 and issued a Warning: couldn't find charset data for locale XXXX; using ISO 8859-1 Warning: couldn't find charset data for locale XXXX; using ISO 8859-1 (similar to https://bugs.launchpad.net/ubuntu/+source/x11-utils/+bug/280449 , there is a fix, there is no package). I decided for myself that it is easier to download the source code of a very fresh luit — http://invisible-island.net/luit . Seeing it in x11-utils, where it usually happens, is unlikely to be possible. Further:
 ./configure 
Perhaps there will not be any dependencies, everything is solved. I flew all quickly.
 sudo make 

Freshly compiled luit 2.0 converts perfectly on the fly from 866 to UTF-8, i.e. In general, my task is completed.
In general, I was guided by the fact that a specific working machine that was configured once would manage any default Windows-based machine that is running RPC and has rights.
I hope for criticism, comments and suggestions.

upd: Thanks to Slipeer for the link to noticeably more recent winexe - http://sourceforge.net/projects/winexe/ !
upd2: The important point to which it is worth paying is that when you start cmd through winexe, the cursor keys and backspace do not work inside. In writing scripts for standard operations, this does not bother me at all :)

')

Source: https://habr.com/ru/post/181103/


All Articles