metasploit-framework/lib/rex/post/meterpreter/packet_parser.rb

62 lines
1012 B
Ruby
Raw Normal View History

# -*- coding: binary -*-
module Rex
module Post
module Meterpreter
###
#
# This class is responsible for reading in and decrypting meterpreter
# packets that arrive on a socket
#
###
class PacketParser
2013-08-30 21:28:33 +00:00
#
# Initializes the packet parser context.
2013-08-30 21:28:33 +00:00
#
def initialize
2013-08-30 21:28:33 +00:00
reset
end
#
# Resets the parser state so that a new packet can begin being parsed.
#
def reset
self.packet = Packet.new(0)
2013-08-30 21:28:33 +00:00
end
#
# Reads data from the socket and parses as much of the packet as possible.
2013-08-30 21:28:33 +00:00
#
def recv(sock)
raw = nil
if self.packet.raw_bytes_required > 0
while (raw = sock.read(self.packet.raw_bytes_required))
self.packet.add_raw(raw)
break if self.packet.raw_bytes_required == 0
2013-08-30 21:28:33 +00:00
end
end
if self.packet.raw_bytes_required > 0
if raw == nil
raise EOFError
else
return nil
end
2013-08-30 21:28:33 +00:00
end
packet = self.packet
reset
packet
2013-08-30 21:28:33 +00:00
end
protected
attr_accessor :cipher, :packet # :nodoc:
end
end; end; end