Skip to content

Commit 8ca66e0

Browse files
author
HD Moore
committed
Track and display the last checkin time for Meterpreter sessions
1 parent 93ac8b4 commit 8ca66e0

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/msf/base/serializer/readable_text.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ def self.dump_sessions(framework, opts={})
536536
]
537537

538538
columns << 'Via' if verbose
539+
columns << 'CheckIn' if verbose
539540
columns << 'PayloadId' if verbose
540541

541542
tbl = Rex::Ui::Text::Table.new(
@@ -554,11 +555,16 @@ def self.dump_sessions(framework, opts={})
554555

555556
row = [ session.sid.to_s, session.type.to_s, sinfo, session.tunnel_to_s + " (#{session.session_host})" ]
556557
if session.respond_to? :platform
557-
row[1] += " " + session.platform
558+
row[1] << (" " + session.platform)
558559
end
559560

560561
if verbose
561562
row << session.via_exploit.to_s
563+
if session.respond_to?(:last_checkin) && session.last_checkin
564+
row << "#{(Time.now.to_i - session.last_checkin.to_i)}s"
565+
else
566+
row << ''
567+
end
562568
row << session.payload_uuid.to_s
563569
end
564570

lib/rex/post/meterpreter/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ def unicode_filter_decode(str)
464464
# A list of the commands
465465
#
466466
attr_reader :commands
467+
#
468+
# The timestamp of the last received response
469+
#
470+
attr_accessor :last_checkin
467471

468472
protected
469473
attr_accessor :parser, :ext_aliases # :nodoc:

lib/rex/post/meterpreter/packet_dispatcher.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ def initialize_passive_dispatcher
7979

8080
def shutdown_passive_dispatcher
8181
return if not self.passive_service
82-
self.passive_service.remove_resource(self.conn_id + "/")
82+
83+
# Ensure that there is only one leading and trailing slash on the URI
84+
resource_uri = "/" + self.conn_id.to_s.gsub(/(^\/|\/$)/, '') + "/"
85+
86+
self.passive_service.remove_resource(resource_uri)
8387

8488
# If there are no more resources registered on the service, stop it entirely
8589
if self.passive_service.resources.empty?
@@ -102,6 +106,8 @@ def on_passive_request(cli, req)
102106
resp['Content-Type'] = 'application/octet-stream'
103107
resp['Connection'] = 'close'
104108

109+
self.last_checkin = Time.now
110+
105111
# If the first 4 bytes are "RECV", return the oldest packet from the outbound queue
106112
if req.body[0,4] == "RECV"
107113
rpkt = send_queue.shift
@@ -494,6 +500,9 @@ def dispatch_inbound_packet(packet, client = nil)
494500
client = self
495501
end
496502

503+
# Update our last reply time
504+
client.last_checkin = Time.now
505+
497506
# If the packet is a response, try to notify any potential
498507
# waiters
499508
if ((resp = packet.response?))

0 commit comments

Comments
 (0)