Module: Rex::Post::Channel::SocketAbstraction::SocketInterface

Includes:
Socket
Included in:
Msf::Sessions::SshCommandShellBind::TcpClientChannel::SocketInterface, Rex::Proto::Http::WebSocket::Interface::Channel::SocketInterface
Defined in:
lib/rex/post/channel/socket_abstraction.rb

Overview

This interface is meant to be included by channelized sockets. It updates their getname methods to correctly report the information based on the channel object (which must have a ‘#params` attribute).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



56
57
58
# File 'lib/rex/post/channel/socket_abstraction.rb', line 56

def channel
  @channel
end

Instance Method Details

#closeObject



50
51
52
53
54
# File 'lib/rex/post/channel/socket_abstraction.rb', line 50

def close
  super
  channel.cleanup_abstraction
  channel.close
end

#getpeernameObject



34
35
36
37
38
39
40
# File 'lib/rex/post/channel/socket_abstraction.rb', line 34

def getpeername
  return super if !channel

  maddr = channel.params.peerhost
  mport = channel.params.peerport
  ::Socket.sockaddr_in(mport, maddr)
end

#getsocknameObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rex/post/channel/socket_abstraction.rb', line 17

def getsockname
  return super unless channel

  # Find the first host in our chain (our address)
  hops = 0
  csock = channel.client.sock
  while csock.respond_to?('channel')
    csock = csock.channel.client.sock
    hops += 1
  end
  _address_family, caddr, _cport = csock.getsockname
  address_family, raddr, _rport = csock.getpeername_as_array
  _maddr = channel.params.localhost
  mport = channel.params.localport
  [ address_family, "#{caddr}#{(hops > 0) ? "-_#{hops}_" : ''}-#{raddr}", mport ]
end