1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-01-20 20:37:27 +01:00

Land #504, Python support for seek and tell in file channels

Merge branch 'land-504' into upstream-master
This commit is contained in:
bwatters-r7 2021-09-28 14:15:23 -05:00
commit 23ed10cf53
No known key found for this signature in database
GPG Key ID: ECC0F0A52E65F268

View File

@ -596,6 +596,16 @@ class MeterpreterChannel(object):
response += tlv_pack(TLV_TYPE_LENGTH, self.write(channel_data))
return ERROR_SUCCESS, response
def core_seek(self, request, response):
offset = packet_get_tlv(request, TLV_TYPE_SEEK_OFFSET)['value']
whence = packet_get_tlv(request, TLV_TYPE_SEEK_WHENCE)['value']
self.seek(offset, whence)
return ERROR_SUCCESS, response
def core_tell(self, request, response):
response += tlv_pack(TLV_TYPE_SEEK_POS, self.tell())
return ERROR_SUCCESS, response
def close(self):
raise NotImplementedError()
@ -614,6 +624,12 @@ class MeterpreterChannel(object):
def write(self, data):
raise NotImplementedError()
def seek(self, offset, whence=os.SEEK_SET):
raise NotImplementedError()
def tell(self):
raise NotImplementedError()
#@export
class MeterpreterFile(MeterpreterChannel):
def __init__(self, file_obj):
@ -632,6 +648,12 @@ class MeterpreterFile(MeterpreterChannel):
def write(self, data):
self.file_obj.write(data)
return len(data)
def seek(self, offset, whence=os.SEEK_SET):
self.file_obj.seek(offset, whence)
def tell(self):
return self.file_obj.tell()
export(MeterpreterFile)
#@export
@ -1565,7 +1587,7 @@ class PythonMeterpreter(object):
return ERROR_FAILURE, response
channel = self.channels[channel_id]
status, response = channel.core_eof(request, response)
return ERROR_SUCCESS, response
return status, response
def _core_channel_interact(self, request, response):
channel_id = packet_get_tlv(request, TLV_TYPE_CHANNEL_ID)['value']
@ -1605,6 +1627,20 @@ class PythonMeterpreter(object):
self.handle_dead_resource_channel(channel_id)
return status, response
def _core_channel_seek(self, request, response):
channel_id = packet_get_tlv(request, TLV_TYPE_CHANNEL_ID)['value']
if channel_id not in self.channels:
return ERROR_FAILURE, response
channel = self.channels[channel_id]
return channel.core_seek(request, response)
def _core_channel_tell(self, request, response):
channel_id = packet_get_tlv(request, TLV_TYPE_CHANNEL_ID)['value']
if channel_id not in self.channels:
return ERROR_FAILURE, response
channel = self.channels[channel_id]
return channel.core_tell(request, response)
def create_response(self, request):
response = struct.pack('>I', PACKET_TYPE_RESPONSE)
commd_id_tlv = packet_get_tlv(request, TLV_TYPE_COMMAND_ID)