Class: Rex::Post::Meterpreter::PacketParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/post/meterpreter/packet_parser.rb

Overview

This class is responsible for reading in and decrypting meterpreter packets that arrive on a socket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePacketParser

Initializes the packet parser context.


18
19
20
# File 'lib/rex/post/meterpreter/packet_parser.rb', line 18

def initialize
  reset
end

Instance Attribute Details

#cipherObject (protected)

:nodoc:


55
56
57
# File 'lib/rex/post/meterpreter/packet_parser.rb', line 55

def cipher
  @cipher
end

#packetObject (protected)

:nodoc:


55
56
57
# File 'lib/rex/post/meterpreter/packet_parser.rb', line 55

def packet
  @packet
end

Instance Method Details

#recv(sock) ⇒ Object

Reads data from the socket and parses as much of the packet as possible.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rex/post/meterpreter/packet_parser.rb', line 32

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
    end
  end

  if self.packet.raw_bytes_required > 0
    if raw == nil
      raise EOFError
    else
      return nil
    end
  end

  packet = self.packet
  reset
  packet
end

#resetObject

Resets the parser state so that a new packet can begin being parsed.


25
26
27
# File 'lib/rex/post/meterpreter/packet_parser.rb', line 25

def reset
  self.packet = Packet.new(0)
end