CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/lib/rex/post/meterpreter/channels/pool.rb
Views: 1904
# -*- coding: binary -*-12require 'rex/post/meterpreter/channel'34module Rex5module Post6module Meterpreter7module Channels89###10#11# This class acts as a base class for all channels that are classified12# as 'pools'. This means that only one side of the channel, typically13# the client half, acts on the other half of the channel. Examples14# of pools come in the form of files where the remote side never sends15# any unrequested data.16#17# Another key distinction of Pools is that they, in general, support18# the DIO mode 'seek' which allows for changing the position, or offset,19# into the channel.20#21###22class Pool < Rex::Post::Meterpreter::Channel2324class << self25def cls26return CHANNEL_CLASS_POOL27end28end2930##31#32# Constructor33#34##3536#37# Passes the initialization information up to the base class38#39def initialize(client, cid, type, flags, packet, **_)40super(client, cid, type, flags, packet)41end4243##44#45# Channel interaction46#47##4849#50# Checks to see if the EOF flag has been set on the pool.51#52def eof53request = Packet.create_request(COMMAND_ID_CORE_CHANNEL_EOF)5455request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)5657begin58response = self.client.send_request(request)59rescue60return true61end6263if (response.has_tlv?(TLV_TYPE_BOOL))64return response.get_tlv_value(TLV_TYPE_BOOL)65end6667return false68end6970#71# Reads data from the remote side of the pool and raises EOFError if the72# pool has been reached EOF.73#74def read(length = nil)75begin76data = super(length)77rescue78data = nil79end8081if (((data == nil) || (data.length == 0)) &&82(self.eof))83raise EOFError84end8586return data87end8889#90# This method seeks to an offset within the remote side of the pool using91# the standard seek whence clauses.92#93def seek(offset, whence = SEEK_SET)94sane = 09596# Just in case...97case whence98when ::IO::SEEK_SET99sane = 0100when ::IO::SEEK_CUR101sane = 1102when ::IO::SEEK_END103sane = 2104else105raise RuntimeError, "Invalid seek whence #{whence}.", caller106end107108request = Packet.create_request(COMMAND_ID_CORE_CHANNEL_SEEK)109110request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)111request.add_tlv(TLV_TYPE_SEEK_OFFSET, offset)112request.add_tlv(TLV_TYPE_SEEK_WHENCE, sane)113114begin115self.client.send_request(request)116tell117rescue118return -1119end120end121122#123# Synonym for tell.124#125def pos126tell127end128129#130# This method returns the current file pointer position to the caller.131#132def tell133request = Packet.create_request(COMMAND_ID_CORE_CHANNEL_TELL)134pos = -1135136request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)137138begin139response = self.client.send_request(request)140rescue141return pos142end143144# Set the return value to the position that we're at145if (response.has_tlv?(TLV_TYPE_SEEK_POS))146pos = response.get_tlv_value(TLV_TYPE_SEEK_POS)147end148149return pos150end151152protected153attr_accessor :_eof # :nodoc:154155end156157end; end; end; end158159160161