Skip to content

Commit 49f5256

Browse files
committed
Make session_events retrievable from the API
1 parent eb92766 commit 49f5256

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

lib/metasploit/framework/data_service/proxy/session_event_data_proxy.rb

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,51 @@
11
module SessionEventDataProxy
22

3+
def session_events
4+
begin
5+
data_service = self.get_data_service()
6+
puts "In SessionEventDataProxy.session_events"
7+
rescue Exception => e
8+
puts"Call to #{data_service.class}#session_events threw exception: #{e.message}"
9+
end
10+
end
11+
312
def report_session_event(opts)
413
begin
514
data_service = self.get_data_service()
6-
# The full Session object contains in-memory instances of data we do not need to store.
7-
opts[:session] = opts[:session].sid
15+
16+
# TODO: This is pretty hacky, but I don't want to change the code in Msf::DBManager::SessionEvent at this time.
17+
# If we decide it's ok to make changes in that code then we need to make it simply store the object and
18+
# do the pre-processing here.
19+
if !data_service.is_a?(Msf::DBManager)
20+
# The Msf::DBManager::SessionEvent.report_session_event does a lot of work for creating the SessionEvent
21+
# Should we move that here?
22+
#opts[:session] = opts[:session].sid
23+
if opts[:session].respond_to? :db_record
24+
session = opts[:session].db_record
25+
if session.nil?
26+
# The session doesn't have a db_record which means
27+
# a) the database wasn't connected at session registration time
28+
# or
29+
# b) something awful happened and the report_session call failed
30+
#
31+
# Either way, we can't do anything with this session as is, so
32+
# log a warning and punt.
33+
wlog("Warning: trying to report a session_event for a session with no db_record (#{opts[:session].sid})")
34+
return
35+
end
36+
event_data = { :created_at => Time.now }
37+
else
38+
session = opts[:session]
39+
event_data = { :created_at => opts[:created_at] }
40+
end
41+
42+
event_data[:session_id] = session.id
43+
[:remote_path, :local_path, :output, :command, :etype].each do |attr|
44+
event_data[attr] = opts[attr] if opts[attr]
45+
end
46+
opts = event_data
47+
end
48+
849
data_service.report_session_event(opts)
950
rescue Exception => e
1051
puts "Call to #{data_service.class}#report_session_event threw exception: #{e.message}"

lib/msf/core/db_manager/session_event.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
module Msf::DBManager::SessionEvent
2+
3+
def session_events(opts)
4+
wspace = opts[:workspace] || opts[:wspace] || workspace
5+
if wspace.kind_of? String
6+
wspace = find_workspace(wspace)
7+
end
8+
9+
::ActiveRecord::Base.connection_pool.with_connection {
10+
conditions = {}
11+
12+
Mdm::SessionEvent.all
13+
}
14+
end
215
#
316
# Record a session event in the database
417
#

0 commit comments

Comments
 (0)