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

1
  • 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) Commented Nov 21, 2013 at 10:01

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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?
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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.