Refactor the initialize method to use 'packet'

This commit is contained in:
Spencer McIntyre 2020-02-19 23:25:43 -05:00
parent e5befa676f
commit e5fc41a22f
9 changed files with 20 additions and 23 deletions

View File

@ -37,8 +37,8 @@ class Pool < Rex::Post::Meterpreter::Channel
#
# Passes the initialization information up to the base class
#
def initialize(client, cid, type, flags, response, klass_args)
super(client, cid, type, flags, response, klass_args)
def initialize(client, cid, type, flags, packet, klass_args)
super(client, cid, type, flags, packet, klass_args)
end
##

View File

@ -52,8 +52,8 @@ class File < Rex::Post::Meterpreter::Channels::Pool
##
# Initializes the file channel instance
def initialize(client, cid, type, flags, response, klass_args)
super(client, cid, type, flags, response, klass_args)
def initialize(client, cid, type, flags, packet, klass_args)
super(client, cid, type, flags, packet, klass_args)
end
end

View File

@ -33,8 +33,8 @@ class StreamPool < Rex::Post::Meterpreter::Channels::Pool
##
# Initializes the file channel instance
def initialize(client, cid, type, flags, response, klass_args)
super(client, cid, type, flags, response, klass_args)
def initialize(client, cid, type, flags, packet, klass_args)
super(client, cid, type, flags, packet, klass_args)
initialize_abstraction
end

View File

@ -86,13 +86,13 @@ module SocketAbstraction
#
# Passes the initialization information up to the base class
#
def initialize(client, cid, type, flags, response, klass_args)
def initialize(client, cid, type, flags, packet, klass_args)
# sf: initialize_abstraction() before super() as we can get a scenario where dio_write_handler() is called
# with data to write to the rsock but rsock has not yet been initialized. This happens if the channel
# is registered (client.add_channel(self) in Channel.initialize) to a session and a 'core_channel_write'
# request comes in before we have called self.initialize_abstraction()
initialize_abstraction
super(client, cid, type, flags, response, klass_args)
super(client, cid, type, flags, packet, klass_args)
end
##

View File

@ -63,14 +63,14 @@ class Socket
# Process a response packet and extract TLVs that are relevant for updating
# socket parameters.
#
def self.params_hash_from_response(response)
def self.parameters_from_response(response)
params = {}
TLV_PARAM_MAP.each do |tlv_type, param_key|
value = response.get_tlv_value(tlv_type)
next if value.nil?
params[param_key] = value
end
params
Rex::Socket::Parameters.from_hash(params)
end
##

View File

@ -69,8 +69,8 @@ class TcpClientChannel < Rex::Post::Meterpreter::Stream
#
# Passes the channel initialization information up to the base class.
#
def initialize(client, cid, type, flags, response, klass_args)
super(client, cid, type, flags, response, klass_args)
def initialize(client, cid, type, flags, packet, klass_args)
super(client, cid, type, flags, packet, klass_args)
lsock.extend(SocketInterface)
lsock.extend(DirectChannelWrite)
@ -78,7 +78,7 @@ class TcpClientChannel < Rex::Post::Meterpreter::Stream
rsock.extend(SocketInterface)
rsock.channel = self
@params = klass_args[:sock_params].merge_hash(Socket.params_hash_from_response(response))
@params = klass_args[:sock_params].merge(Socket.parameters_from_response(packet))
end
#

View File

@ -54,8 +54,6 @@ class TcpServerChannel < Rex::Post::Meterpreter::Channel
client_channel = TcpClientChannel.new(client, cid, TcpClientChannel, CHANNEL_FLAG_SYNCHRONOUS, packet, {:sock_params => params})
client_channel.params = params
@@server_channels[server_channel] ||= ::Queue.new
@@server_channels[server_channel].enq(client_channel)
@ -83,9 +81,9 @@ class TcpServerChannel < Rex::Post::Meterpreter::Channel
#
# Simply initialize this instance.
#
def initialize(client, cid, type, flags, response, klass_args)
super(client, cid, type, flags, response, klass_args)
@params = klass_args[:sock_params].merge_hash(Socket.params_hash_from_response(response))
def initialize(client, cid, type, flags, packet, klass_args)
super(client, cid, type, flags, packet, klass_args)
@params = klass_args[:sock_params].merge(Socket.parameters_from_response(packet))
# add this instance to the class variables dictionary of tcp server channels
@@server_channels[self] ||= ::Queue.new
end

View File

@ -61,8 +61,8 @@ class UdpChannel < Rex::Post::Meterpreter::Datagram
#
# Simply initialize this instance.
#
def initialize(client, cid, type, flags, response, klass_args)
super(client, cid, type, flags, response, klass_args)
def initialize(client, cid, type, flags, packet, klass_args)
super(client, cid, type, flags, packet, klass_args)
lsock.extend(Rex::Socket::Udp)
lsock.initsock
@ -73,8 +73,7 @@ class UdpChannel < Rex::Post::Meterpreter::Datagram
# rsock.extend( Rex::Socket::Udp )
rsock.extend(SocketInterface)
rsock.channel = self
@params = klass_args[:sock_params].merge_hash(Socket.params_hash_from_response(response))
@params = klass_args[:sock_params].merge(Socket.parameters_from_response(packet))
end
#

View File

@ -128,7 +128,7 @@ class LocalRelay
end
end
def shudown
def shutdown
# don't need to do anything here, it's only "close" we care about
end