refactored the pool interface to make the code more generic
git-svn-id: file:///home/svn/incoming/trunk@2375 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
068dc13284
commit
ca42291606
|
@ -48,9 +48,23 @@ class Pool < Rex::Post::Meterpreter::Channel
|
|||
#
|
||||
##
|
||||
|
||||
# Synonym for tell
|
||||
def pos
|
||||
return tell
|
||||
# Checks eof
|
||||
def eof
|
||||
request = Packet.create_request('core_channel_eof')
|
||||
|
||||
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
|
||||
|
||||
begin
|
||||
response = self.client.send_request(request)
|
||||
rescue
|
||||
return true
|
||||
end
|
||||
|
||||
if (response.has_tlv?(TLV_TYPE_BOOL))
|
||||
return response.get_tlv_value(TLV_TYPE_BOOL)
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
# Wraps the read operation to raise end-of-file as necessary
|
||||
|
@ -60,24 +74,70 @@ class Pool < Rex::Post::Meterpreter::Channel
|
|||
rescue
|
||||
data = nil
|
||||
end
|
||||
|
||||
if ((data == nil) && (self.eof))
|
||||
|
||||
if (((data == nil) || (data.length == 0)) &&
|
||||
(self.eof))
|
||||
raise EOFError
|
||||
end
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
# Stub for seeking to a different location on the remote half of the
|
||||
# channel
|
||||
# Seeks to a different location in the pool
|
||||
def seek(offset, whence = SEEK_SET)
|
||||
raise NotImplementedError
|
||||
sane = 0
|
||||
|
||||
# Just in case...
|
||||
case whence
|
||||
when ::IO::SEEK_SET
|
||||
sane = 0
|
||||
when ::IO::SEEK_CUR
|
||||
sane = 1
|
||||
when ::IO::SEEK_END
|
||||
sane = 2
|
||||
else
|
||||
raise RuntimeError, "Invalid seek whence #{whence}.", caller
|
||||
end
|
||||
|
||||
request = Packet.create_request('core_channel_seek')
|
||||
|
||||
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
|
||||
request.add_tlv(TLV_TYPE_SEEK_OFFSET, offset)
|
||||
request.add_tlv(TLV_TYPE_SEEK_WHENCE, sane)
|
||||
|
||||
begin
|
||||
response = self.client.send_request(request)
|
||||
rescue
|
||||
return -1
|
||||
end
|
||||
|
||||
return tell
|
||||
end
|
||||
|
||||
# Stub for getting the current position on the remote half of the
|
||||
# channel
|
||||
# Synonym for tell
|
||||
def pos
|
||||
return tell
|
||||
end
|
||||
|
||||
# Gets the current position in the pool
|
||||
def tell
|
||||
raise NotImplementedError
|
||||
request = Packet.create_request('core_channel_tell')
|
||||
pos = -1
|
||||
|
||||
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
|
||||
|
||||
begin
|
||||
response = self.client.send_request(request)
|
||||
rescue
|
||||
return pos
|
||||
end
|
||||
|
||||
# Set the return value to the position that we're at
|
||||
if (response.has_tlv?(TLV_TYPE_SEEK_POS))
|
||||
pos = response.get_tlv_value(TLV_TYPE_SEEK_POS)
|
||||
end
|
||||
|
||||
return pos
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -19,10 +19,6 @@ module Pools
|
|||
###
|
||||
class File < Rex::Post::Meterpreter::Channels::Pool
|
||||
|
||||
TLV_TYPE_SEEK_OFFSET = TLV_META_TYPE_UINT | (TLV_TEMP + 0)
|
||||
TLV_TYPE_SEEK_WHENCE = TLV_META_TYPE_UINT | (TLV_TEMP + 1)
|
||||
TLV_TYPE_SEEK_POS = TLV_META_TYPE_UINT | (TLV_TEMP + 2)
|
||||
|
||||
##
|
||||
#
|
||||
# Constructor
|
||||
|
@ -34,83 +30,6 @@ TLV_TYPE_SEEK_POS = TLV_META_TYPE_UINT | (TLV_TEMP + 2)
|
|||
super(client, cid, type, flags)
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# I/O operations
|
||||
#
|
||||
##
|
||||
|
||||
# Checks to see if the end-of-file has been reached
|
||||
def eof
|
||||
request = Packet.create_request('stdapi_fs_file_eof')
|
||||
|
||||
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
|
||||
|
||||
begin
|
||||
response = self.client.send_request(request)
|
||||
rescue
|
||||
return true
|
||||
end
|
||||
|
||||
if (response.has_tlv?(TLV_TYPE_BOOL))
|
||||
return response.get_tlv_value(TLV_TYPE_BOOL)
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
# Seeks to a different location in the file
|
||||
def seek(offset, whence = SEEK_SET)
|
||||
sane = 0
|
||||
|
||||
# Just in case...
|
||||
case whence
|
||||
when ::IO::SEEK_SET
|
||||
sane = 0
|
||||
when ::IO::SEEK_CUR
|
||||
sane = 1
|
||||
when ::IO::SEEK_END
|
||||
sane = 2
|
||||
else
|
||||
raise RuntimeError, "Invalid seek whence #{whence}.", caller
|
||||
end
|
||||
|
||||
request = Packet.create_request('stdapi_fs_file_seek')
|
||||
|
||||
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
|
||||
request.add_tlv(TLV_TYPE_SEEK_OFFSET, offset)
|
||||
request.add_tlv(TLV_TYPE_SEEK_WHENCE, sane)
|
||||
|
||||
begin
|
||||
response = self.client.send_request(request)
|
||||
rescue
|
||||
return -1
|
||||
end
|
||||
|
||||
return tell
|
||||
end
|
||||
|
||||
# Gets the current position of the file pointer
|
||||
def tell
|
||||
request = Packet.create_request('stdapi_fs_file_tell')
|
||||
pos = -1
|
||||
|
||||
request.add_tlv(TLV_TYPE_CHANNEL_ID, self.cid)
|
||||
|
||||
begin
|
||||
response = self.client.send_request(request)
|
||||
rescue
|
||||
return pos
|
||||
end
|
||||
|
||||
# Set the return value to the position that we're at
|
||||
if (response.has_tlv?(TLV_TYPE_SEEK_POS))
|
||||
pos = response.get_tlv_value(TLV_TYPE_SEEK_POS)
|
||||
end
|
||||
|
||||
return pos
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end; end; end; end; end
|
||||
|
|
|
@ -54,6 +54,10 @@ TLV_TYPE_CHANNEL_DATA = TLV_META_TYPE_RAW | 52
|
|||
TLV_TYPE_CHANNEL_DATA_GROUP = TLV_META_TYPE_GROUP | 53
|
||||
TLV_TYPE_CHANNEL_CLASS = TLV_META_TYPE_UINT | 54
|
||||
|
||||
TLV_TYPE_SEEK_WHENCE = TLV_META_TYPE_UINT | 70
|
||||
TLV_TYPE_SEEK_OFFSET = TLV_META_TYPE_UINT | 71
|
||||
TLV_TYPE_SEEK_POS = TLV_META_TYPE_UINT | 72
|
||||
|
||||
TLV_TYPE_EXCEPTION_CODE = TLV_META_TYPE_UINT | 300
|
||||
TLV_TYPE_EXCEPTION_STRING = TLV_META_TYPE_STRING | 301
|
||||
|
||||
|
@ -161,7 +165,7 @@ class Tlv
|
|||
self.value = false
|
||||
end
|
||||
else
|
||||
self.value = raw[8..raw.length-1]
|
||||
self.value = raw[8..-1]
|
||||
end
|
||||
|
||||
return length;
|
||||
|
|
Loading…
Reference in New Issue