@@ -284,20 +284,6 @@ def keepalive
284
284
# Reception
285
285
#
286
286
##
287
-
288
- #
289
- # Simple class to track packets and if they are in-progress or complete.
290
- #
291
- class QueuedPacket
292
- attr_reader :packet
293
- attr_reader :in_progress
294
-
295
- def initialize ( packet , in_progress )
296
- @packet = packet
297
- @in_progress = in_progress
298
- end
299
- end
300
-
301
287
#
302
288
# Monitors the PacketDispatcher's sock for data in its own
303
289
# thread context and parsers all inbound packets.
@@ -320,8 +306,8 @@ def monitor_socket
320
306
begin
321
307
rv = Rex ::ThreadSafe . select ( [ self . sock . fd ] , nil , nil , PING_TIME )
322
308
if rv
323
- packet , in_progress = receive_packet
324
- @pqueue << QueuedPacket . new ( packet , in_progress )
309
+ packet = receive_packet
310
+ @pqueue << packet if packet
325
311
elsif self . send_keepalives && @pqueue . empty?
326
312
keepalive
327
313
end
@@ -356,11 +342,11 @@ def monitor_socket
356
342
tmp_channel = [ ]
357
343
tmp_close = [ ]
358
344
backlog . each do |pkt |
359
- if ( pkt . packet . response? )
345
+ if ( pkt . response? )
360
346
tmp_command << pkt
361
347
next
362
348
end
363
- if ( pkt . packet . method == "core_channel_close" )
349
+ if ( pkt . method == "core_channel_close" )
364
350
tmp_close << pkt
365
351
next
366
352
end
@@ -379,23 +365,21 @@ def monitor_socket
379
365
backlog . each do |pkt |
380
366
381
367
begin
382
- if ! dispatch_inbound_packet ( pkt . packet , pkt . in_progress )
368
+ if ! dispatch_inbound_packet ( pkt )
383
369
# Keep Packets in the receive queue until a handler is registered
384
370
# for them. Packets will live in the receive queue for up to
385
371
# PACKET_TIMEOUT seconds, after which they will be dropped.
386
372
#
387
373
# A common reason why there would not immediately be a handler for
388
374
# a received Packet is in channels, where a connection may
389
375
# open and receive data before anything has asked to read.
390
- #
391
- # Also, don't bother saving incomplete packets if we have no handler.
392
- if ( !pkt . in_progress and ::Time . now . to_i - pkt . packet . created_at . to_i < PACKET_TIMEOUT )
376
+ if ( ::Time . now . to_i - pkt . created_at . to_i < PACKET_TIMEOUT )
393
377
incomplete << pkt
394
378
end
395
379
end
396
380
397
381
rescue ::Exception => e
398
- dlog ( "Dispatching exception with packet #{ pkt . packet } : #{ e } #{ e . backtrace } " , 'meterpreter' , LEV_1 )
382
+ dlog ( "Dispatching exception with packet #{ pkt } : #{ e } #{ e . backtrace } " , 'meterpreter' , LEV_1 )
399
383
end
400
384
end
401
385
@@ -475,16 +459,12 @@ def add_response_waiter(request, completion_routine = nil, completion_param = ni
475
459
# Notifies a whomever is waiting for a the supplied response,
476
460
# if anyone.
477
461
#
478
- # For not-yet-complete responses, we might not be able to determine
479
- # the response ID, in that case just let all waiters know that some
480
- # responses are trickling in.
481
- #
482
- def notify_response_waiter ( response , in_progress = false )
462
+ def notify_response_waiter ( response )
483
463
handled = false
484
464
self . waiters . each ( ) { |waiter |
485
- if ( in_progress || waiter . waiting_for? ( response ) )
486
- waiter . notify ( response , in_progress )
487
- remove_response_waiter ( waiter ) unless in_progress
465
+ if ( waiter . waiting_for? ( response ) )
466
+ waiter . notify ( response )
467
+ remove_response_waiter ( waiter )
488
468
handled = true
489
469
break
490
470
end
@@ -518,7 +498,7 @@ def initialize_inbound_handlers
518
498
# Otherwise, the packet is passed onto any registered dispatch
519
499
# handlers until one returns success.
520
500
#
521
- def dispatch_inbound_packet ( packet , in_progress = false )
501
+ def dispatch_inbound_packet ( packet )
522
502
handled = false
523
503
524
504
# Update our last reply time
@@ -527,7 +507,7 @@ def dispatch_inbound_packet(packet, in_progress=false)
527
507
# If the packet is a response, try to notify any potential
528
508
# waiters
529
509
if packet . response?
530
- if ( notify_response_waiter ( packet , in_progress ) )
510
+ if ( notify_response_waiter ( packet ) )
531
511
return true
532
512
end
533
513
end
0 commit comments