Module sysbot.connectors.local
Local Execution Connector Module
This module provides connectors for executing commands locally on the system without requiring SSH or WinRM connections. It supports both Bash/Shell and PowerShell execution depending on the platform.
Classes
class Bash (port=None)-
This class provides methods for executing bash/shell commands locally without requiring SSH connection.
Initialize Local Bash connector.
Args
port:int- Not used for local execution, kept for interface compatibility.
Ancestors
- ConnectorInterface
- abc.ABC
Methods
def close_session(self, session)-
Closes a local session (no action needed for local execution).
Args
session:dict- The local session object to close.
Raises
Exception- If there is an error closing the session.
def execute_command(self, session, command, runas=False, password=None)-
Executes a command locally using bash.
Args
session:dict- The local session object
command:str- The command to execute
runas:bool- Whether to run with elevated privileges using sudo
password:str- Password for sudo authentication (if required) Note: Password is passed via echo which may be visible in process lists
Returns
str- The output of the command execution
Raises
Exception- If there is an error executing the command
def open_session(self, host=None, port=None, login=None, password=None)-
Opens a local session (no actual connection needed).
Args
host:str- Not used for local execution, kept for interface compatibility.
port:int- Not used for local execution, kept for interface compatibility.
login:str- Not used for local execution, kept for interface compatibility.
password:str- Not used for local execution, kept for interface compatibility.
Returns
dict- A session dictionary containing system information.
Raises
Exception- If there is an error opening the session.
class Powershell (port=None)-
This class provides methods for executing PowerShell commands locally without requiring SSH or WinRM connection.
Initialize Local PowerShell connector.
Args
port:int- Not used for local execution, kept for interface compatibility.
Ancestors
- ConnectorInterface
- abc.ABC
Methods
def close_session(self, session)-
Closes a local session (no action needed for local execution).
Args
session:dict- The local session object to close.
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 locally.
Args
session:dict- The local session object
command:str- The PowerShell command to execute
runas:bool- Whether to run with elevated privileges
username:str- Username for elevated execution (if different from current user)
password:str- Password for elevated execution (if required) Note: Password is embedded in PowerShell script which may be visible
Returns
str- The output of the command execution
Raises
Exception- If there is an error executing the command
def open_session(self, host=None, port=None, login=None, password=None)-
Opens a local session (no actual connection needed).
Args
host:str- Not used for local execution, kept for interface compatibility.
port:int- Not used for local execution, kept for interface compatibility.
login:str- Not used for local execution, kept for interface compatibility.
password:str- Not used for local execution, kept for interface compatibility.
Returns
dict- A session dictionary containing system information.
Raises
Exception- If there is an error opening the session.