Module: Rex::Post::Meterpreter::PacketDispatcher
- Included in:
- Client
- Defined in:
- lib/rex/post/meterpreter/packet_dispatcher.rb
Overview
Handles packet transmission, reception, and correlation, and processing
Constant Summary collapse
- PACKET_TIMEOUT =
Default time, in seconds, to wait for a response after sending a packet
600
- PING_TIME =
Number of seconds to wait without getting any packets before we try to send a liveness check. A minute should be generous even on the highest latency networks
60
Instance Attribute Summary collapse
-
#comm_mutex ⇒ Object
This mutex is used to lock out new commands during an active migration.
-
#dispatcher_thread ⇒ Object
protected
:nodoc:.
-
#passive_service ⇒ Rex::ServiceManager?
Passive Dispatching.
-
#receiver_thread ⇒ Object
protected
:nodoc:.
- #recv_queue ⇒ Array
- #send_queue ⇒ Array
-
#session_guid ⇒ Object
The guid that identifies an active Meterpreter session.
-
#tlv_enc_key ⇒ Object
This contains the key material used for TLV encryption.
-
#tlv_log_file ⇒ Object
protected
:nodoc:.
-
#tlv_log_file_path ⇒ Object
protected
:nodoc:.
-
#tlv_log_output ⇒ Object
protected
:nodoc:.
-
#tlv_logging_error_occured ⇒ Object
protected
:nodoc:.
-
#waiters ⇒ Object
protected
:nodoc:.
Instance Method Summary collapse
-
#add_response_waiter(request, completion_routine = nil, completion_param = nil) ⇒ Object
Adds a waiter association with the supplied request packet.
-
#decrypt_inbound_packet(packet) ⇒ Object
Decrypt the given packet with the appropriate key depending on if this session is a pivot session or not.
-
#deregister_inbound_handler(handler) ⇒ Object
Deregisters a previously registered inbound packet handler.
-
#dispatch_inbound_packet(packet) ⇒ Object
Dispatches and processes an inbound packet.
-
#initialize_inbound_handlers ⇒ Object
Initializes the inbound handlers.
- #initialize_passive_dispatcher ⇒ Object
- #initialize_tlv_logging(opt) ⇒ Object
-
#keepalive ⇒ void
Send a ping to the server.
- #log_packet(packet, packet_type) ⇒ Object protected
- #log_packet_to_console(packet, packet_type) ⇒ Object protected
- #log_packet_to_file(packet, packet_type) ⇒ Object protected
-
#monitor_socket ⇒ Object
Monitors the PacketDispatcher’s sock for data in its own thread context and parsers all inbound packets.
-
#monitor_stop ⇒ Object
Stop the monitor.
-
#notify_response_waiter(response) ⇒ Object
Notifies a whomever is waiting for a the supplied response, if anyone.
- #on_passive_request(cli, req) ⇒ Object
-
#pivot_keepalive_start ⇒ Object
Reception.
-
#receive_packet ⇒ Object
Parses data from the dispatcher’s sock and returns a Packet context once a full packet has been received.
-
#register_inbound_handler(handler) ⇒ Object
Registers an inbound packet handler that implements the InboundPacketHandler interface.
-
#remove_response_waiter(waiter) ⇒ Object
Removes a waiter from the list of waiters.
-
#send_packet(packet, opts = {}) ⇒ Object
Sends a packet without waiting for a response.
-
#send_packet_wait_response(packet, timeout) ⇒ Object
Transmits a packet and waits for a response.
-
#send_request(packet, timeout = self.response_timeout) ⇒ Object
Sends a packet and waits for a timeout for the given time interval.
- #shutdown_passive_dispatcher ⇒ Object
- #shutdown_tlv_logging ⇒ Object protected
Instance Attribute Details
#comm_mutex ⇒ Object
This mutex is used to lock out new commands during an active migration. Unused if this is a passive dispatcher
60 61 62 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 60 def comm_mutex @comm_mutex end |
#dispatcher_thread ⇒ Object (protected)
:nodoc:
653 654 655 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 653 def dispatcher_thread @dispatcher_thread end |
#passive_service ⇒ Rex::ServiceManager?
Passive Dispatching
72 73 74 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 72 def passive_service @passive_service end |
#receiver_thread ⇒ Object (protected)
:nodoc:
652 653 654 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 652 def receiver_thread @receiver_thread end |
#recv_queue ⇒ Array
78 79 80 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 78 def recv_queue @recv_queue end |
#send_queue ⇒ Array
75 76 77 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 75 def send_queue @send_queue end |
#session_guid ⇒ Object
The guid that identifies an active Meterpreter session
63 64 65 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 63 def session_guid @session_guid end |
#tlv_enc_key ⇒ Object
This contains the key material used for TLV encryption
66 67 68 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 66 def tlv_enc_key @tlv_enc_key end |
#tlv_log_file ⇒ Object (protected)
:nodoc:
657 658 659 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 657 def tlv_log_file @tlv_log_file end |
#tlv_log_file_path ⇒ Object (protected)
:nodoc:
658 659 660 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 658 def tlv_log_file_path @tlv_log_file_path end |
#tlv_log_output ⇒ Object (protected)
:nodoc:
656 657 658 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 656 def tlv_log_output @tlv_log_output end |
#tlv_logging_error_occured ⇒ Object (protected)
:nodoc:
659 660 661 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 659 def tlv_logging_error_occured @tlv_logging_error_occured end |
#waiters ⇒ Object (protected)
:nodoc:
654 655 656 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 654 def waiters @waiters end |
Instance Method Details
#add_response_waiter(request, completion_routine = nil, completion_param = nil) ⇒ Object
Adds a waiter association with the supplied request packet.
504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 504 def add_response_waiter(request, completion_routine = nil, completion_param = nil) if self.pivot_session return self.pivot_session.add_response_waiter(request, completion_routine, completion_param) end waiter = PacketResponseWaiter.new(request.rid, completion_routine, completion_param) self.waiters << waiter return waiter end |
#decrypt_inbound_packet(packet) ⇒ Object
Decrypt the given packet with the appropriate key depending on if this session is a pivot session or not.
565 566 567 568 569 570 571 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 565 def decrypt_inbound_packet(packet) pivot_session = self.find_pivot_session(packet.session_guid) tlv_enc_key = self.tlv_enc_key tlv_enc_key = pivot_session.pivoted_session.tlv_enc_key if pivot_session packet.from_r(tlv_enc_key) packet end |
#deregister_inbound_handler(handler) ⇒ Object
Deregisters a previously registered inbound packet handler.
632 633 634 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 632 def deregister_inbound_handler(handler) @inbound_handlers.delete(handler) end |
#dispatch_inbound_packet(packet) ⇒ Object
Dispatches and processes an inbound packet. If the packet is a response that has an associated waiter, the waiter is notified. Otherwise, the packet is passed onto any registered dispatch handlers until one returns success.
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 579 def dispatch_inbound_packet(packet) handled = false log_packet(packet, :recv) # Update our last reply time self.last_checkin = ::Time.now pivot_session = self.find_pivot_session(packet.session_guid) pivot_session.pivoted_session.last_checkin = self.last_checkin if pivot_session # If the packet is a response, try to notify any potential # waiters if packet.response? && notify_response_waiter(packet) return true end # Enumerate all of the inbound packet handlers until one handles # the packet @inbound_handlers.each { |handler| handled = nil begin if packet.response? handled = handler.response_handler(self, packet) else handled = handler.request_handler(self, packet) end rescue ::Exception => e dlog("Exception caught in dispatch_inbound_packet: handler=#{handler} #{e.class} #{e} #{e.backtrace}", 'meterpreter', LEV_1) return true end if (handled) break end } return handled end |
#initialize_inbound_handlers ⇒ Object
Initializes the inbound handlers.
557 558 559 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 557 def initialize_inbound_handlers @inbound_handlers = [] end |
#initialize_passive_dispatcher ⇒ Object
80 81 82 83 84 85 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 80 def initialize_passive_dispatcher self.send_queue = [] self.recv_queue = [] self.waiters = [] self.alive = true end |
#initialize_tlv_logging(opt) ⇒ Object
636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 636 def initialize_tlv_logging(opt) self.tlv_logging_error_occured = false self.tlv_log_file = nil self.tlv_log_file_path = nil self.tlv_log_output = :none if opt.casecmp?('console') || opt.casecmp?('true') self.tlv_log_output = :console elsif opt.start_with?('file:') self.tlv_log_output = :file self.tlv_log_file_path = opt.split('file:').last end end |
#keepalive ⇒ void
This method returns an undefined value.
Send a ping to the server.
Our ‘ping’ is a check for eof on channel id 0. This method has no side effects and always returns an answer (regardless of the existence of chan 0), which is all that’s needed for a liveness check. The answer itself is unimportant and is ignored.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 259 def keepalive if @ping_sent if ::Time.now.to_i - last_checkin.to_i > PING_TIME*2 dlog("No response to ping, session #{self.sid} is dead", LEV_3) self.alive = false end else pkt = Packet.create_request(COMMAND_ID_CORE_CHANNEL_EOF) pkt.add_tlv(TLV_TYPE_CHANNEL_ID, 0) add_response_waiter(pkt, Proc.new { @ping_sent = false }) send_packet(pkt) @ping_sent = true end end |
#log_packet(packet, packet_type) ⇒ Object (protected)
668 669 670 671 672 673 674 675 676 677 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 668 def log_packet(packet, packet_type) # if we previously failed to log, return return if self.tlv_logging_error_occured || self.tlv_log_output == :none if self.tlv_log_output == :console log_packet_to_console(packet, packet_type) elsif self.tlv_log_output == :file log_packet_to_file(packet, packet_type) end end |
#log_packet_to_console(packet, packet_type) ⇒ Object (protected)
679 680 681 682 683 684 685 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 679 def log_packet_to_console(packet, packet_type) if packet_type == :send print "\n%redSEND%clr: #{packet.inspect}\n" elsif packet_type == :recv print "\n%bluRECV%clr: #{packet.inspect}\n" end end |
#log_packet_to_file(packet, packet_type) ⇒ Object (protected)
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 687 def log_packet_to_file(packet, packet_type) pathname = ::Pathname.new(self.tlv_log_file_path.split('file:').last) begin if self.tlv_log_file.nil? || self.tlv_log_file.path != pathname.to_s self.tlv_log_file.close unless self.tlv_log_file.nil? self.tlv_log_file = ::File.open(pathname, 'a+') end if packet_type == :recv self.tlv_log_file.puts("\nRECV: #{packet.inspect}\n") elsif packet_type == :send self.tlv_log_file.puts("\nSEND: #{packet.inspect}\n") end rescue ::StandardError => e self.tlv_logging_error_occured = true print_error "Failed writing to TLV Log File: #{pathname} with error: #{e.}. Turning off logging for this session: #{self.inspect}..." elog(e) shutdown_tlv_logging return end end |
#monitor_socket ⇒ Object
Monitors the PacketDispatcher’s sock for data in its own thread context and parsers all inbound packets.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 301 def monitor_socket # Skip if we are using a passive dispatcher return if self.passive_service # redirect to pivot keepalive if we're a pivot session return pivot_keepalive_start if self.pivot_session self.comm_mutex = ::Mutex.new self.waiters = [] # This queue is where the new incoming packets end up @new_packet_queue = ::Queue.new # This is where we put packets that aren't new, but haven't # yet been handled. @incomplete_queue = ::Queue.new @ping_sent = false # Spawn a thread for receiving packets self.receiver_thread = Rex::ThreadFactory.spawn("MeterpreterReceiver", false) do while (self.alive) begin rv = Rex::ThreadSafe.select([ self.sock.fd ], nil, nil, PING_TIME) if rv packet = receive_packet # Always enqueue the new packets onto the new packet queue @new_packet_queue << decrypt_inbound_packet(packet) if packet elsif self.send_keepalives && @new_packet_queue.empty? keepalive end rescue ::Exception => e dlog("Exception caught in monitor_socket: #{e.class}: #{e}", 'meterpreter', LEV_1) dlog("Call stack: #{e.backtrace.join("\n")}", 'meterpreter', LEV_2) self.alive = false break end end end # Spawn a new thread that monitors the socket self.dispatcher_thread = Rex::ThreadFactory.spawn("MeterpreterDispatcher", false) do begin while (self.alive) # This is where we'll store incomplete packets on # THIS iteration incomplete = [] # The backlog is the full list of packets that aims # to be handled this iteration backlog = [] # If we have any left over packets from the previous # iteration, we need to prioritise them over the new # packets. If we don't do this, then we end up in # situations where data on channels can be processed # out of order. We don't do a blocking wait here via # the .pop method because we don't want to block, we # just want to dump the queue. while @incomplete_queue.length > 0 backlog << @incomplete_queue.pop end # If the backlog is empty, we don't have old/stale # packets hanging around, so perform a blocking wait # for the next packet backlog << @new_packet_queue.pop if backlog.length == 0 # At this point we either received a packet off the wire # or we had a backlog to process. In either case, we # perform a non-blocking queue dump to fill the backlog # with every packet we have. while @new_packet_queue.length > 0 backlog << @new_packet_queue.pop end # # Prioritize message processing here # 1. Close should always be processed at the end # 2. Command responses always before channel data # tmp_command = [] tmp_channel = [] tmp_close = [] backlog.each do |pkt| if(pkt.response?) tmp_command << pkt next end if(pkt.method == COMMAND_ID_CORE_CHANNEL_CLOSE) tmp_close << pkt next end tmp_channel << pkt end backlog = [] backlog.push(*tmp_command) backlog.push(*tmp_channel) backlog.push(*tmp_close) # # Process the message queue # backlog.each do |pkt| begin unless dispatch_inbound_packet(pkt) # Keep Packets in the receive queue until a handler is registered # for them. Packets will live in the receive queue for up to # PACKET_TIMEOUT seconds, after which they will be dropped. # # A common reason why there would not immediately be a handler for # a received Packet is in channels, where a connection may # open and receive data before anything has asked to read. if (::Time.now.to_i - pkt.created_at.to_i < PACKET_TIMEOUT) incomplete << pkt end end rescue ::Exception => e dlog("Dispatching exception with packet #{pkt}: #{e} #{e.backtrace}", 'meterpreter', LEV_1) end end # If the backlog and incomplete arrays are the same, it means # dispatch_inbound_packet wasn't able to handle any of the # packets. When that's the case, we can get into a situation # where @new_packet_queue is not empty and, since nothing else bounds this # loop, we spin CPU trying to handle packets that can't be # handled. Sleep here to treat that situation as though the # queue is empty. if (backlog.length > 0 && backlog.length == incomplete.length) ::IO.select(nil, nil, nil, 0.10) end # If we have any packets that weren't handled, they go back # on the incomplete queue so that they're prioritised over # new packets that are coming in off the wire. dlog("Requeuing #{incomplete.length} packet(s)", 'meterpreter', LEV_1) if incomplete.length > 0 while incomplete.length > 0 @incomplete_queue << incomplete.shift end # If the old queue of packets gets too big... if(@incomplete_queue.length > 100) removed = [] # Drop a bunch of them. (1..25).each { removed << @incomplete_queue.pop } dlog("Backlog has grown to over 100 in monitor_socket, dropping older packets: #{removed.map{|x| x.inspect}.join(" - ")}", 'meterpreter', LEV_1) end end rescue ::Exception => e dlog("Exception caught in monitor_socket dispatcher: #{e.class} #{e} #{e.backtrace}", 'meterpreter', LEV_1) ensure self.receiver_thread.kill if self.receiver_thread end end end |
#monitor_stop ⇒ Object
Stop the monitor
481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 481 def monitor_stop if self.receiver_thread self.receiver_thread.kill self.receiver_thread.join self.receiver_thread = nil end if self.dispatcher_thread self.dispatcher_thread.kill self.dispatcher_thread.join self.dispatcher_thread = nil end end |
#notify_response_waiter(response) ⇒ Object
Notifies a whomever is waiting for a the supplied response, if anyone.
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 520 def notify_response_waiter(response) if self.pivot_session return self.pivot_session.notify_response_waiter(response) end handled = false self.waiters.each() { |waiter| if (waiter.waiting_for?(response)) waiter.notify(response) remove_response_waiter(waiter) handled = true break end } return handled end |
#on_passive_request(cli, req) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 94 def on_passive_request(cli, req) begin self.last_checkin = ::Time.now resp = send_queue.shift cli.send_response(resp) rescue => e send_queue.unshift(resp) if resp elog("Exception sending a reply to the reader request #{cli.inspect}", error: e) end end |
#pivot_keepalive_start ⇒ Object
Reception
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 280 def pivot_keepalive_start return unless self.send_keepalives self.receiver_thread = Rex::ThreadFactory.spawn("PivotKeepalive", false) do while self.alive begin Rex::sleep(PING_TIME) keepalive rescue ::Exception => e dlog("Exception caught in pivot keepalive: #{e.class}: #{e}", 'meterpreter', LEV_1) dlog("Call stack: #{e.backtrace.join("\n")}", 'meterpreter', LEV_2) self.alive = false break end end end end |
#receive_packet ⇒ Object
Parses data from the dispatcher’s sock and returns a Packet context once a full packet has been received.
467 468 469 470 471 472 473 474 475 476 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 467 def receive_packet packet = parser.recv(self.sock) if packet packet.parse_header! if self.session_guid == NULL_GUID self.session_guid = packet.session_guid.dup end end packet end |
#register_inbound_handler(handler) ⇒ Object
Registers an inbound packet handler that implements the InboundPacketHandler interface.
625 626 627 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 625 def register_inbound_handler(handler) @inbound_handlers << handler end |
#remove_response_waiter(waiter) ⇒ Object
Removes a waiter from the list of waiters.
540 541 542 543 544 545 546 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 540 def remove_response_waiter(waiter) if self.pivot_session self.pivot_session.remove_response_waiter(waiter) else self.waiters.delete(waiter) end end |
#send_packet(packet, opts = {}) ⇒ Object
Sends a packet without waiting for a response.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 114 def send_packet(packet, opts={}) if self.pivot_session opts[:session_guid] = self.session_guid opts[:tlv_enc_key] = self.tlv_enc_key return self.pivot_session.send_packet(packet, opts) end if opts[:completion_routine] add_response_waiter(packet, opts[:completion_routine], opts[:completion_param]) end session_guid = self.session_guid tlv_enc_key = self.tlv_enc_key # if a session guid is provided, use all the details provided if opts[:session_guid] session_guid = opts[:session_guid] tlv_enc_key = opts[:tlv_enc_key] end log_packet(packet, :send) bytes = 0 raw = packet.to_r(session_guid, tlv_enc_key) err = nil # Short-circuit send when using a passive dispatcher if self.passive_service send_queue.push(raw) return raw.size # Lie! end if raw self.comm_mutex.synchronize do begin bytes = self.sock.write(raw) rescue ::Exception => e err = e end end if bytes.to_i == 0 # Mark the session itself as dead self.alive = false # Reraise the error to the top-level caller raise err if err end end return bytes end |
#send_packet_wait_response(packet, timeout) ⇒ Object
Transmits a packet and waits for a response.
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 200 def send_packet_wait_response(packet, timeout) if packet.type == PACKET_TYPE_REQUEST && commands.present? # XXX: Remove this condition once the payloads gem has had another major version bump from 2.x to 3.x and # rapid7/metasploit-payloads#451 has been landed to correct the `enumextcmd` behavior on Windows. Until then, skip # proactive validation of Windows core commands. This is not the only instance of this workaround. windows_core = base_platform == 'windows' && (packet.method - (packet.method % COMMAND_ID_RANGE)) == Rex::Post::Meterpreter::ClientCore.extension_id unless windows_core || commands.include?(packet.method) if (ext_name = Rex::Post::Meterpreter::ExtensionMapper.get_extension_name(packet.method)) unless ext.aliases.include?(ext_name) raise RequestError.new(packet.method, "The command requires the #{ext_name} extension to be loaded") end end raise RequestError.new(packet.method, "The command is not supported by this Meterpreter type (#{session_type})") end end # First, add the waiter association for the supplied packet waiter = add_response_waiter(packet) bytes_written = send_packet(packet) # Transmit the packet if (bytes_written.to_i <= 0) # Remove the waiter if we failed to send the packet. remove_response_waiter(waiter) return nil end if not timeout return nil end # Wait for the supplied time interval response = waiter.wait(timeout) # Remove the waiter from the list of waiters in case it wasn't # removed. This happens if the waiter timed out above. remove_response_waiter(waiter) # wire in the UUID for this, as it should be part of every response # packet if response && !self.payload_uuid uuid = response.get_tlv_value(TLV_TYPE_UUID) self.payload_uuid = Msf::Payload::UUID.new({:raw => uuid}) if uuid end # Return the response packet, if any return response end |
#send_request(packet, timeout = self.response_timeout) ⇒ Object
Sends a packet and waits for a timeout for the given time interval.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 175 def send_request(packet, timeout = self.response_timeout) response = send_packet_wait_response(packet, timeout) if timeout.nil? return nil elsif response.nil? raise Rex::TimeoutError.new("Send timed out") elsif (response.result != 0) einfo = lookup_error(response.result) e = RequestError.new(packet.method, einfo, response.result) e.set_backtrace(caller) raise e end return response end |
#shutdown_passive_dispatcher ⇒ Object
87 88 89 90 91 92 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 87 def shutdown_passive_dispatcher self.alive = false self.send_queue = [] self.recv_queue = [] self.waiters = [] end |
#shutdown_tlv_logging ⇒ Object (protected)
661 662 663 664 665 666 |
# File 'lib/rex/post/meterpreter/packet_dispatcher.rb', line 661 def shutdown_tlv_logging self.tlv_log_output = :none self.tlv_log_file.close unless self.tlv_log_file.nil? self.tlv_log_file = nil self.tlv_log_file_path = nil end |