Giter VIP home page Giter VIP logo

rpsowmi's Introduction

Remote PowerShell over WMI

Built-in support for Cyrillic (DOS) encoding!

Remote PowerShell over WMI (RPSoWMI) enables you to run PowerShell code with support of STDIN, STDOUT, STDERR and return code through Windows Management Instrumentation (WMI) on remote host.

Communication with your PowerShell code is done through 2 named pipes (one for outbound and another for inbound) being created on executor's machine, that means your access rights must be enough privileged not only for creation of new process on remote machine but also for access to the named pipes on executor's machine from remote machine.

Getting started:

pip install WMI
pip install git+https://github.com/surik00/rpsowmi.git

# OR:
# 1. download archive: https://github.com/surik00/rpsowmi/releases/tag/v0.1
# 2. Unarchive, go to dir
python .\setup.py install

How to use RPSoWMI:

from rpsowmi import RemotePowerShellOverWmi as RPSoWMI
from wmi import WMI  # https://pypi.python.org/pypi/WMI/

rps = RPSoWMI(WMI())
r = rps.execute("Write-Host 'Hello, world'")
print(r.stdout)  # Just showing 'Hello, world'.

Advanced example for Exchange:

from rpsowmi import RemotePowerShellOverWmi as RPSoWMI
from wmi import WMI


PS_PATH = 'C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe'

PS_GET_DIST_GROUPS_CMD = '''Import-Module activedirectory
ForEach ($group in (Get-ADGroup -Properties Name, Mail -Filter 'groupcategory -eq "distribution"' -Server "{DC}")) {{
    Write-Host ($group.Name, $group.Mail) -Separator "{sep}"
}}
'''

command = PS_GET_DIST_GROUPS_CMD.format(DC='DC.my_domain.com', sep=' | ')

rps = RPSoWMI(WMI(), ps_cmd=PS_PATH)
r = rps.execute(command)
print(r.stdout)

For more details, read pydoc of rpsowmi.RemotePowerShellOverWmi.

Known problems

  • Length of your PowerShell code is limited up to around 2,800 characters because the code is tranfered as a part of command line arguments.
  • Line separators - CR, LF and CRLF are unified to LF (\\n) somewhere in communication between RPSoWMI and your PowerShell code.
  • Line separator - LF (\\n) may be appended to STDOUT and STDERR even though your PowerShell code doesn't do it.

rpsowmi's People

Contributors

sakurai-youhei avatar mahenzon avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.