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

57 lines
925 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 wire and parse as much of the packet as possible.
#
def recv(sock)
if self.packet.raw_bytes_required
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
return nil
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