Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/net/winrm/connection.rb
Views: 11779
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'winrm'6require 'net/winrm/stdin_shell'7require 'net/winrm/rex_http_transport'89module Net10module MsfWinRM11# Connection to a WinRM service, using Rex sockets12class RexWinRMConnection < WinRM::Connection13# Factory class to create a shell of the appropriate type.14# Subclassed to be able to provide a StdinShell15class ShellFactory < WinRM::Shells::ShellFactory16def create_shell(shell_type, shell_opts = {})17args = [18@connection_opts,19@transport,20@logger,21shell_opts22]23return StdinShell.new(*args) if shell_type == :stdin2425super(shell_type, shell_opts)26end27end2829# Creates a WinRM transport, subclassed to support Rex sockets30class TransportFactory < WinRM::HTTP::TransportFactory31def create_transport(connection_opts)32raise NotImplementedError unless connection_opts[:transport] == :rexhttp3334super35end3637private3839def init_rexhttp_transport(opts)40RexHttpTransport.new(opts)41end42end4344# Provide an adapter for logging WinRM module messages to the MSF log45class WinRMProxyLogger46def error(msg)47elog(msg, 'winrm')48end4950def warn(msg)51wlog(msg, 'winrm')52end5354def info(msg)55ilog(msg, 'winrm')56end5758def debug(msg)59dlog(msg, 'winrm')60end61end6263def shell_factory64@shell_factory ||= ShellFactory.new(@connection_opts, transport, logger)65end6667def transport68@transport ||= begin69transport_factory = TransportFactory.new70transport_factory.create_transport(@connection_opts)71end72end7374def configure_logger75@logger = WinRMProxyLogger.new76end77end78end79end808182