4

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

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
0xAffe
  • 1,156
  • 1
  • 13
  • 29
  • Do you have `wmic` installed on your Linux box? Try running `wmic -U Administrator%password //192.168.1.149 "SELECT * FROM Win32_Processor"`. (This is the equivalent of the command from the wmi-client-wrapper example) – ig0774 Nov 21 '13 at 10:01

2 Answers2

4

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

beto
  • 146
  • 3
  • Hi @beto, I've been trying to find the extent to which WMI is supported/implemented by Impacket. The official line says it is either partial/full, which isn't too helpful. Could you help me out? – batbrat Jun 28 '19 at 13:28
2

The wmi-client-wrapper package, as stated by its name, is a wrapper for the wmic client. So you first need to install wmic for it to work. To install wmic, just run from your linux machine:

sudo aptitude install wmi-client

Having installed WMIC, your wmi-client-wrapper should work as mentioned in the example:

import wmi_client_wrapper as wmi

wmic = wmi.WmiClientWrapper(
    username="Administrator",
    password="password",
    host="192.168.1.149",
)

output = wmic.query("SELECT * FROM Win32_Processor")

You can find more information regarding wmic in this link http://felimwhiteley.wordpress.com/2008/08/15/wmi-calls-from-linux/

Cas
  • 2,077
  • 3
  • 21
  • 24