Class: Rex::Post::Meterpreter::PacketResponseWaiter

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

Overview

This class handles waiting for a response to a given request and the subsequent response association.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rid, completion_routine = nil, completion_param = nil) ⇒ PacketResponseWaiter

Initializes a response waiter instance for the supplied request identifier.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 46

def initialize(rid, completion_routine = nil, completion_param = nil)
  self.rid      = rid.dup
  self.response = nil

  if (completion_routine)
    self.completion_routine = completion_routine
    self.completion_param   = completion_param
  else
    self.mutex = Mutex.new
    self.cond  = ConditionVariable.new
  end
end

Instance Attribute Details

#completion_paramObject?

Arbitrary argument to #completion_routine

Returns:

  • (Object, nil)


21
22
23
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 21

def completion_param
  @completion_param
end

#completion_routineProc?

A callback to be called when this waiter is notified of a packet’s arrival. If not nil, this will be called with the response packet as first parameter and #completion_param as the second.

Returns:

  • (Proc, nil)


28
29
30
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 28

def completion_routine
  @completion_routine
end

#condConditionVariable

Returns:

  • (ConditionVariable)


31
32
33
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 31

def cond
  @cond
end

#mutexMutex

Returns:

  • (Mutex)


34
35
36
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 34

def mutex
  @mutex
end

#responsePacket

Returns:



37
38
39
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 37

def response
  @response
end

#ridInteger

Returns request ID to wait for.

Returns:

  • (Integer)

    request ID to wait for



40
41
42
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 40

def rid
  @rid
end

Instance Method Details

#notify(response) ⇒ void

This method returns an undefined value.

Notifies the waiter that the supplied response packet has arrived.

Parameters:



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 72

def notify(response)
  if (self.completion_routine)
    self.response = response
    self.completion_routine.call(response, self.completion_param)
  else
    self.mutex.synchronize do
      self.response = response
      self.cond.signal
    end
  end
end

#wait(interval) ⇒ Packet?

Wait for a given time interval for the response packet to arrive.

Parameters:

  • interval (Integer, nil)

    number of seconds to wait, or nil to wait forever

Returns:

  • (Packet, nil)

    the response, or nil if the interval elapsed before receiving one



91
92
93
94
95
96
97
98
99
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 91

def wait(interval)
  interval = nil if interval and interval == -1
  self.mutex.synchronize do
    if self.response.nil?
      self.cond.wait(self.mutex, interval)
    end
  end
  return self.response
end

#waiting_for?(packet) ⇒ Boolean

Checks to see if this waiter instance is waiting for the supplied packet based on its request identifier.

Returns:

  • (Boolean)


63
64
65
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 63

def waiting_for?(packet)
  return (packet.rid == rid)
end