Land #10862, fix issue with session reporting when DB is disabled

GSoC/Meterpreter_Web_Console
James Barnett 2018-10-26 10:58:06 -05:00
commit bd7c867485
No known key found for this signature in database
GPG Key ID: 647983861A4EC5EA
3 changed files with 28 additions and 9 deletions

View File

@ -150,12 +150,28 @@ class DataProxy
return @current_data_service
end
# Performs a set of data service operations declared within the block.
# This passes the @current_data_service as a parameter to the block.
# If there is no current data service registered or the data service
# is not active, the block is not executed and the method simply returns.
def data_service_operation(&block)
return unless block_given?
begin
data_service = self.get_data_service
rescue
return
end
block.call(data_service) if !data_service.nil? && self.active
end
def log_error(exception, ui_message)
elog "#{ui_message}: #{exception.message}"
exception.backtrace.each { |line| elog "#{line}" }
# TODO: We should try to surface the original exception, instead of just a generic one.
# This should not display the full backtrace, only the message.
raise Exception, "#{ui_message}: #{exception.message}. See log for more details."
raise "#{ui_message}: #{exception.message}. See log for more details."
end
# Adds a valid workspace value to the opts hash before sending on to the data layer.

View File

@ -1,9 +1,10 @@
module SessionDataProxy
def sessions(opts={})
begin
data_service = self.get_data_service
add_opts_workspace(opts)
data_service.sessions(opts)
self.data_service_operation do |data_service|
add_opts_workspace(opts)
data_service.sessions(opts)
end
rescue => e
self.log_error(e, "Problem retrieving sessions")
end
@ -11,9 +12,10 @@ module SessionDataProxy
def report_session(opts)
begin
data_service = self.get_data_service
add_opts_workspace(opts)
data_service.report_session(opts)
self.data_service_operation do |data_service|
add_opts_workspace(opts)
data_service.report_session(opts)
end
rescue => e
self.log_error(e, "Problem reporting session")
end

View File

@ -2,8 +2,9 @@ module SessionEventDataProxy
def report_session_event(opts)
begin
data_service = self.get_data_service()
data_service.report_session_event(opts)
self.data_service_operation do |data_service|
data_service.report_session_event(opts)
end
rescue => e
self.log_error(e, "Problem reporting session event")
end