Module sysbot.connectors.winrm
WinRM Connector Module
This module provides Windows Remote Management (WinRM) connectors for remote Windows system management. It supports PowerShell execution over WinRM using the pywinrm library for establishing and managing sessions.
Classes
class Powershell (port=5986)-
This class provides methods for interacting with Windows systems using the Windows Remote Management (WinRM) protocol. It uses the pywinrm library to establish and manage sessions.
Initialize WinRM PowerShell connector with default port.
Args
port:int- Default WinRM HTTPS port (default: 5986).
Ancestors
- ConnectorInterface
- abc.ABC
Methods
def close_session(self, session)-
Closes the WinRM session to a Windows system.
Args
session:dict- The session dictionary containing the protocol and shell.
Raises
Exception- If there is an error closing the session.
def execute_command(self, session, command, runas=False, username=None, password=None)-
Executes a PowerShell command on a Windows system via WinRM.
Args
session:dict- The session dictionary containing the protocol and shell.
command:str- The PowerShell command to execute on the Windows system.
runas:bool- Whether to run with elevated privileges
username:str- Username for elevated execution (if different from session user)
password:str- Password for elevated execution (if required)
Returns
str- The output of the command.
Raises
Exception- If there is an error executing the command.
def open_session(self, host, port=None, login=None, password=None)-
Opens a WinRM session to a Windows system.
Args
host:str- Hostname or IP address of the Windows system.
port:int- Port of the WinRM service. If None, uses default_port.
login:str- Username for the session.
password:str- Password for the session.
Returns
dict- A dictionary containing the protocol and shell objects.
Raises
Exception- If there is an error opening the session.