2005-04-12 05:37:11 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'Rex/Post/Meterpreter/Channel'
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Post
|
|
|
|
module Meterpreter
|
|
|
|
module Channels
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Pool
|
|
|
|
# ----
|
|
|
|
#
|
|
|
|
# This class acts as a base class for all channels that are classified
|
|
|
|
# as 'pools'. This means that only one side of the channel, typically
|
|
|
|
# the client half, acts on the other half of the channel. Examples
|
|
|
|
# of pools come in the form of files where the remote side never sends
|
|
|
|
# any unrequested data.
|
|
|
|
#
|
|
|
|
# Another key distinction of Pools is that they, in general, support
|
|
|
|
# the DIO mode 'seek' which allows for changing the position, or offset,
|
|
|
|
# into the channel.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Pool < Rex::Post::Meterpreter::Channel
|
|
|
|
|
|
|
|
class <<self
|
|
|
|
def cls
|
|
|
|
return CHANNEL_CLASS_POOL
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Constructor
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
# Passes the initialization information up to the base class
|
|
|
|
def initialize(client, cid, type, flags)
|
|
|
|
super(client, cid, type, flags)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Channel interaction
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-04-12 06:39:33 +00:00
|
|
|
# Synonym for tell
|
|
|
|
def pos
|
|
|
|
return tell
|
|
|
|
end
|
|
|
|
|
|
|
|
# Wraps the read operation to raise end-of-file as necessary
|
|
|
|
def read(length = nil)
|
2005-04-12 15:13:15 +00:00
|
|
|
begin
|
|
|
|
data = super(length)
|
|
|
|
rescue
|
|
|
|
data = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if ((data == nil) && (self.eof))
|
2005-04-12 06:39:33 +00:00
|
|
|
raise EOFError
|
|
|
|
end
|
|
|
|
|
2005-04-12 15:13:15 +00:00
|
|
|
return data
|
2005-04-12 06:39:33 +00:00
|
|
|
end
|
|
|
|
|
2005-04-12 05:37:11 +00:00
|
|
|
# Stub for seeking to a different location on the remote half of the
|
|
|
|
# channel
|
|
|
|
def seek(offset, whence = SEEK_SET)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
|
|
|
# Stub for getting the current position on the remote half of the
|
|
|
|
# channel
|
|
|
|
def tell
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2005-04-12 06:39:33 +00:00
|
|
|
protected
|
|
|
|
attr_accessor :_eof
|
2005-04-12 05:37:11 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end; end; end; end
|