Skip to content

Commit f015b92

Browse files
committed
Merge branch 'goliath' into add_https
2 parents 908a695 + fe069e4 commit f015b92

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module SessionDataService
22
def report_session(opts)
3-
raise 'SessionDataService#report_vuln is not implemented'
3+
raise 'SessionDataService#report_session is not implemented'
44
end
55
end

lib/msf/core/db_manager/session.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ def report_session_dto(session_dto)
160160
}
161161
end
162162

163+
# Clean out any stale sessions that have been orphaned by a dead framework instance.
164+
# @param last_seen_interval [Integer] interval, in seconds, open sessions are marked as alive
165+
def remove_stale_sessions(last_seen_interval)
166+
return unless active
167+
168+
::ActiveRecord::Base.connection_pool.with_connection {
169+
::Mdm::Session.where(closed_at: nil).each do |db_session|
170+
next unless db_session.last_seen.nil? or ((Time.now.utc - db_session.last_seen) > (2 * last_seen_interval))
171+
db_session.closed_at = db_session.last_seen || Time.now.utc
172+
db_session.close_reason = "Orphaned"
173+
db_session.save
174+
end
175+
}
176+
end
177+
163178
#########
164179
protected
165180
#########

lib/msf/core/session_manager.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SessionManager < Hash
2020

2121
include Framework::Offspring
2222

23-
LAST_SEEN_INTERVAL = 60 * 2.5
23+
LAST_SEEN_INTERVAL = 60 * 2.5
2424
SCHEDULER_THREAD_COUNT = 5
2525

2626
def initialize(framework)
@@ -98,12 +98,10 @@ def initialize(framework)
9898
end
9999
end
100100

101-
102101
#
103102
# Skip the database cleanup code below if there is no database
104103
#
105-
next if not (framework.db and framework.db.active and framework.db.is_local?)
106-
104+
next unless framework.db && framework.db.active && framework.db.is_local?
107105

108106
#
109107
# Mark all open session as alive every LAST_SEEN_INTERVAL
@@ -114,6 +112,7 @@ def initialize(framework)
114112
# processing time for large session lists from skewing our update interval.
115113

116114
last_seen_timer = Time.now.utc
115+
117116
if framework.db.active
118117
::ActiveRecord::Base.connection_pool.with_connection do
119118
values.each do |s|
@@ -129,20 +128,12 @@ def initialize(framework)
129128
end
130129
end
131130

132-
133131
#
134132
# Clean out any stale sessions that have been orphaned by a dead
135133
# framework instance.
136134
#
137-
::ActiveRecord::Base.connection_pool.with_connection do |conn|
138-
::Mdm::Session.where(closed_at: nil).each do |db_session|
139-
if db_session.last_seen.nil? or ((Time.now.utc - db_session.last_seen) > (2*LAST_SEEN_INTERVAL))
140-
db_session.closed_at = db_session.last_seen || Time.now.utc
141-
db_session.close_reason = "Orphaned"
142-
db_session.save
143-
end
144-
end
145-
end
135+
framework.db.remove_stale_sessions(LAST_SEEN_INTERVAL)
136+
146137
end
147138

148139
#

0 commit comments

Comments
 (0)