Access WMI via Python from Linux

0xAffe picture 0xAffe · Nov 21, 2013 · Viewed 17.7k times · Source

I'm looking for a way to access the WMI (Windows Management Instrumantation) from a Pythonscript remotely from a Linux machine (CentOS 6)

Of course there is the python-wmi package, but it uses the Windows API which isn't available on Linux. I found the wmi-client-wrapper which should do something like that. But there is no documentation and even the example isn't working for me.

The reason why I want to do this, is because I want to get all Useraccounts on the System remotely and store them in a Database. Maybe you have any other tipps how to do that.

Thank you

Answer

beto picture beto · Feb 1, 2015

You can use Impacket (https://github.com/CoreSecurity/impacket) that has WMI implemented in Python.

There are two examples that might be useful:

1) https://github.com/CoreSecurity/impacket/blob/master/examples/wmiquery.py: It allows to issue WQL queries and get description of the objects

2) https://github.com/CoreSecurity/impacket/blob/master/examples/wmiexec.py: A similar approach to psexec but executing commands through WMI