lib/rex/post/meterpreter/packet_dispatcher.rb in librex-0.0.5 vs lib/rex/post/meterpreter/packet_dispatcher.rb in librex-0.0.6
- old
+ new
@@ -12,35 +12,39 @@
#
# Exception thrown when a request fails.
#
###
class RequestError < ArgumentError
- def initialize(method, result)
+ def initialize(method, einfo, ecode=nil)
@method = method
- @result = result
+ @result = einfo
+ @code = ecode || einfo
end
def to_s
"#{@method}: Operation failed: #{@result}"
end
# The method that failed.
attr_reader :method
- # The error result that occurred, typically a windows error code.
+ # The error result that occurred, typically a windows error message.
attr_reader :result
+
+ # The error result that occurred, typically a windows error code.
+ attr_reader :code
end
###
#
# Handles packet transmission, reception, and correlation,
# and processing
#
###
module PacketDispatcher
- PacketTimeout = 30
+ PacketTimeout = 600
##
#
# Transmission
#
@@ -77,16 +81,23 @@
#
# Sends a packet and waits for a timeout for the given time interval.
#
def send_request(packet, t = self.response_timeout)
+
+ if not t
+ send_packet(packet)
+ return nil
+ end
+
response = send_packet_wait_response(packet, t)
if (response == nil)
raise TimeoutError.new("Send timed out")
elsif (response.result != 0)
- e = RequestError.new(packet.method, response.result)
+ einfo = lookup_error(response.result)
+ e = RequestError.new(packet.method, einfo, response.result)
e.set_backtrace(caller)
raise e
end
@@ -137,11 +148,11 @@
@ping_sent = false
self.alive = true
# Spawn a thread for receiving packets
- self.receiver_thread = ::Thread.new do
+ self.receiver_thread = Rex::ThreadFactory.spawn("MeterpreterReceiver", false) do
while (self.alive)
begin
rv = Rex::ThreadSafe.select([ self.sock.fd ], nil, nil, 0.25)
ping_time = 60
# If there's nothing to read, and it's been awhile since we
@@ -189,10 +200,10 @@
end
end
end
# Spawn a new thread that monitors the socket
- self.dispatcher_thread = ::Thread.new do
+ self.dispatcher_thread = Rex::ThreadFactory.spawn("MeterpreterDispatcher", false) do
begin
# Whether we're finished or not is determined by the receiver
# thread above.
while(not @finish)
if(@pqueue.empty?)