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.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 22

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.done  = false
  end
end

Instance Attribute Details

#completion_paramObject

:nodoc:



79
80
81
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 79

def completion_param
  @completion_param
end

#completion_routineObject

:nodoc:



79
80
81
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 79

def completion_routine
  @completion_routine
end

#doneObject

:nodoc:



78
79
80
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 78

def done
  @done
end

#responseObject

:nodoc:



78
79
80
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 78

def response
  @response
end

#ridObject

:nodoc:



78
79
80
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 78

def rid
  @rid
end

Instance Method Details

#notify(response) ⇒ Object

Notifies the waiter that the supplied response packet has arrived.



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

def notify(response)
  self.response = response

  if (self.completion_routine)
    self.completion_routine.call(response, self.completion_param)
  else
    self.done = true
  end
end

#wait(interval) ⇒ Object

Waits for a given time interval for the response packet to arrive. If the interval is -1 we can wait forever.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rex/post/meterpreter/packet_response_waiter.rb', line 59

def wait(interval)
  if( interval and interval == -1 )
    while(not self.done)
      ::IO.select(nil, nil, nil, 0.1)
    end
  else
    begin
      Timeout.timeout(interval) {
        while(not self.done)
          ::IO.select(nil, nil, nil, 0.1)
        end
      }
    rescue Timeout::Error
      self.response = nil
    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)


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

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