0xAffe
0xAffe

Reputation: 1206

Access WMI via Python from Linux

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

Upvotes: 4

Views: 22068

Answers (2)

beto
beto

Reputation: 146

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

Upvotes: 4

Cas
Cas

Reputation: 2267

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/

Upvotes: 2

Related Questions