Class: Rex::Socket::SSHFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/socket/ssh_factory.rb

Overview

This class exists to abuse the Proxy capabilities in the Net::SSH library to allow the use of Rex::Sockets for the transport layer in Net::SSH. The SSHFactory object will respond to the #open method and create the Tcp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(framework, msfmodule, proxies) ⇒ SSHFactory

Returns a new instance of SSHFactory.



19
20
21
22
23
# File 'lib/rex/socket/ssh_factory.rb', line 19

def initialize(framework, msfmodule, proxies)
  @framework = framework
  @msfmodule   = msfmodule
  @proxies     = proxies
end

Instance Attribute Details

#frameworkObject

Returns the value of attribute framework.



11
12
13
# File 'lib/rex/socket/ssh_factory.rb', line 11

def framework
  @framework
end

#msfmoduleObject

Returns The metasploit module this socket belongs to.

Returns:

  • (Object)

    The metasploit module this socket belongs to



14
15
16
# File 'lib/rex/socket/ssh_factory.rb', line 14

def msfmodule
  @msfmodule
end

#msfraemworkObject

Returns The framework instance object.

Returns:

  • (Object)

    The framework instance object



11
# File 'lib/rex/socket/ssh_factory.rb', line 11

attr_accessor :framework

#proxiesString

Returns Any proxies to use for the connection.

Returns:

  • (String)

    Any proxies to use for the connection



17
18
19
# File 'lib/rex/socket/ssh_factory.rb', line 17

def proxies
  @proxies
end

Instance Method Details

#open(host, port, options = {}) ⇒ Object

Responds to the proxy setup routine Net::SSH will call when initialising the Transport Layer. This will instead create our Tcp and tie the socket back to the calling module

Parameters:

  • host (String)

    The host to open the connection to

  • port (Fixnum)

    the port to open the connection on

  • options (Hash) (defaults to: {})

    the options hash



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rex/socket/ssh_factory.rb', line 31

def open(host, port, options={})
  socket = Rex::Socket::Tcp.create(
    'PeerHost' => host,
    'PeerPort' => port,
    'Proxies' => proxies,
    'Context'  => {
      'Msf'          => framework,
      'MsfExploit'   => msfmodule
    }
  )
  socket
end