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/rex/post/channel/socket_abstraction.rb
Views: 11783
# -*- coding: binary -*-12module Rex3module Post4module Channel5module SocketAbstraction6###7#8# This interface is meant to be included by channelized sockets. It updates9# their getname methods to correctly report the information based on the10# channel object (which must have a `#params` attribute).11#12###13module SocketInterface14include Rex::Socket1516def getsockname17return super unless channel1819# Find the first host in our chain (our address)20hops = 021csock = channel.client.sock22while csock.respond_to?('channel')23csock = csock.channel.client.sock24hops += 125end26_address_family, caddr, _cport = csock.getsockname27address_family, raddr, _rport = csock.getpeername_as_array28_maddr = channel.params.localhost29mport = channel.params.localport30[ address_family, "#{caddr}#{(hops > 0) ? "-_#{hops}_" : ''}-#{raddr}", mport ]31end3233def getpeername34return super if !channel3536maddr = channel.params.peerhost37mport = channel.params.peerport38::Socket.sockaddr_in(mport, maddr)39end4041%i[localhost localport peerhost peerport].map do |meth|42define_method(meth) do43return super if !channel4445channel.params.send(meth)46end47end4849def close50super51channel.cleanup_abstraction52channel.close53end5455attr_accessor :channel56end57end58end59end60end616263