|
1 | 1 | module SessionEventDataProxy
|
2 | 2 |
|
| 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 | + |
3 | 12 | def report_session_event(opts)
|
4 | 13 | begin
|
5 | 14 | 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 | + |
8 | 49 | data_service.report_session_event(opts)
|
9 | 50 | rescue Exception => e
|
10 | 51 | puts "Call to #{data_service.class}#report_session_event threw exception: #{e.message}"
|
|
0 commit comments