Remove debug code

This commit is contained in:
Matthew Kienow 2018-12-14 13:33:16 -05:00
parent ad6b80bd08
commit eec7a3dafc
No known key found for this signature in database
GPG Key ID: 40787F8B1EAC6E41
7 changed files with 3 additions and 59 deletions

View File

@ -33,45 +33,24 @@ module SessionDataProxy
begin
self.data_service_operation do |data_service|
is_msf_session = false
$stderr.puts("*** SessionDataProxy.update_session(): opts=#{opts}") # TODO: remove
# session = opts[:session]
# $stderr.puts("*** SessionDataProxy.update_session(): session.class=#{session.class}") # TODO: remove
# if !session.nil? && session.kind_of?(Msf::Session)
if !opts.nil? && opts.kind_of?(Msf::Session)
msf_session = opts
is_msf_session = true
$stderr.puts("*** SessionDataProxy.update_session(): is_msf_session=#{is_msf_session}, opts=#{opts}, opts.class=#{opts.class}") # TODO: remove
# save session ID
# id = opts.delete(:id)
# tmp_opts = convert_msf_session_to_hash(session)
tmp_opts = SessionDataProxy.convert_msf_session_to_hash(msf_session)
# only updating session data
# opts = tmp_opts[:session_data]
opts = tmp_opts[:session_data]
# add back session ID
# opts[:id] = id
opts[:id] = msf_session.db_record.id
$stderr.puts("*** SessionDataProxy.update_session(): after convert_msf_session_to_hash, opts=#{opts}") # TODO: remove
end
mdm_session = data_service.update_session(opts)
$stderr.puts("*** SessionDataProxy.update_session(): after update: is_msf_session=#{is_msf_session}, mdm_session=#{mdm_session}, #{mdm_session.attributes}") # TODO: remove
# reassign returned Mdm::Session to the Msf::Session's db_record
msf_session.db_record = mdm_session if is_msf_session
$stderr.puts("*** SessionDataProxy.update_session(): msf_session.db_record=#{msf_session.db_record}") if is_msf_session # TODO: remove
# TODO: remove block
if is_msf_session && !msf_session.db_record.nil?
$stderr.puts("SessionDataProxy.update_session(): msf_session.db_record=#{msf_session.db_record}, msf_session.db_record.id=#{msf_session.db_record.id}") # TODO: remove
else
$stderr.puts("SessionDataProxy.update_session(): msf_session.db_record is nil") # TODO: remove
end
mdm_session
end
rescue => e
$stderr.puts("SessionDataProxy.update_session(): e.backtrace=#{e.backtrace}") # TODO: remove
self.log_error(e, "Problem updating session")
end
end

View File

@ -12,23 +12,15 @@ module RemoteSessionDataService
end
def report_session(opts)
$stderr.puts("RemoteSessionDataService.report_session(): opts=#{opts}") # TODO: remove
session = opts[:session]
if (session.kind_of? Msf::Session)
opts = SessionDataProxy.convert_msf_session_to_hash(session)
elsif (opts[:host])
$stderr.puts("*** RemoteSessionDataService.report_session(): executing path where session is not a kind_of Msf::Session...") # TODO: remove
opts[:host] = opts[:host].address
end
opts[:time_stamp] = Time.now.utc
$stderr.puts("RemoteSessionDataService.report_session(): opts=#{opts}") # TODO: remove
sess_db = json_to_mdm_object(self.post_data(SESSION_API_PATH, opts), SESSION_MDM_CLASS, []).first
if !sess_db.nil?
$stderr.puts("RemoteSessionDataService.report_session(): sess_db=#{sess_db}, sess_db.id=#{sess_db.id}") # TODO: remove
else
$stderr.puts("RemoteSessionDataService.report_session(): sess_db is nil") # TODO: remove
end
session.db_record = sess_db
end
@ -39,12 +31,7 @@ module RemoteSessionDataService
path = "#{SESSION_API_PATH}/#{id}"
end
$stderr.puts("RemoteSessionDataService.update_session(): path=#{path}, opts=#{opts}") # TODO: remove
sess_db = json_to_mdm_object(self.put_data(path, opts), SESSION_MDM_CLASS, []).first
$stderr.puts("RemoteSessionDataService.update_session(): returning... sess_db=#{sess_db}") # TODO: remove
sess_db
json_to_mdm_object(self.put_data(path, opts), SESSION_MDM_CLASS, []).first
end
end

View File

@ -516,7 +516,6 @@ class Meterpreter < Rex::Post::Meterpreter::Client
})
if self.db_record
$stderr.puts("Msf::Sessions::Meterpreter.load_session_info(): self.sid=#{self.sid}, self.db_record.id=#{self.db_record.id}; calling framework.db.update_session(self)...") # TODO: remove
framework.db.update_session(self)
end

View File

@ -187,17 +187,8 @@ module Msf::DBManager::Session
return if not active
::ActiveRecord::Base.connection_pool.with_connection {
$stderr.puts("#{DateTime.now} Msf::DBManager::Session.update_session(): opts=#{opts}") # TODO: remove
id = opts.delete(:id)
$stderr.puts("#{DateTime.now} Msf::DBManager::Session.update_session(): id=#{id}, opts=#{opts}") # TODO: remove
$stderr.puts("#{DateTime.now} Msf::DBManager::Session.update_session(): id=#{id}, before update: #{Mdm::Session.find(id).attributes}") # TODO: remove
session_db_record = ::Mdm::Session.update(id, opts)
$stderr.puts("#{DateTime.now} Msf::DBManager::Session.update_session(): session_db_record=#{session_db_record}") # TODO: remove
$stderr.puts("#{DateTime.now} Msf::DBManager::Session.update_session(): session_db_record.id=#{session_db_record.id}") unless session_db_record.nil? # TODO: remove
$stderr.puts("#{DateTime.now} Msf::DBManager::Session.update_session(): id=#{id}, after update: #{Mdm::Session.find(id).attributes}") # TODO: remove
session_db_record
::Mdm::Session.update(id, opts)
}
end

View File

@ -283,14 +283,10 @@ module Session
# Also must tolerate being called multiple times.
#
def cleanup
$stderr.puts("#{DateTime.now} Msf::Session.cleanup(): db_record=#{db_record}, db_record.class=#{db_record.class}, framework.db.active=#{framework.db.active}") # TODO: remove
$stderr.puts("#{DateTime.now} Msf::Session.cleanup(): db_record.id=#{db_record.id}, Time.now.utc=#{Time.now.utc}, before update: #{db_record.attributes}") unless db_record.nil? # TODO: remove
if db_record and framework.db.active
::ActiveRecord::Base.connection_pool.with_connection {
tmp_db_record = framework.db.update_session(id: db_record.id, closed_at: Time.now.utc, close_reason: db_record.close_reason)
$stderr.puts("#{DateTime.now} Msf::Session.cleanup(): tmp_db_record.id=#{tmp_db_record.id}, self.sid=#{self.sid}, after save: #{tmp_db_record.attributes}") unless tmp_db_record.nil? # TODO: remove
framework.db.update_session(id: db_record.id, closed_at: Time.now.utc, close_reason: db_record.close_reason)
db_record = nil
$stderr.puts("#{DateTime.now} Msf::Session.cleanup(): returning after db_record.save call... db_record.class=#{db_record.class}") # TODO: remove
}
end
end

View File

@ -119,9 +119,7 @@ class SessionManager < Hash
# as recently seen. This notifies other framework instances that this
# session is being maintained.
if s.db_record
$stderr.puts("#{DateTime.now} SessionManager.initialize() [monitor_thread]: before update: Time.now.utc=#{Time.now.utc}, s.sid=#{s.sid}, s.db_record.id=#{s.db_record.id}, #{s.db_record.attributes}") # TODO: remove
s.db_record = framework.db.update_session(id: s.db_record.id, last_seen: Time.now.utc)
$stderr.puts("#{DateTime.now} SessionManager.initialize() [monitor_thread]: after update: s.sid=#{s.sid}, s.db_record.id=#{s.db_record.id}, #{s.db_record.attributes}") # TODO: remove
end
end
end

View File

@ -56,15 +56,9 @@ module SessionServlet
warden.authenticate!
begin
opts = parse_json_request(request, false)
$stderr.puts("#{DateTime.now} SessionServlet.update_session(): opts=#{opts}") # TODO: remove
tmp_params = sanitize_params(params)
opts[:id] = tmp_params[:id] if tmp_params[:id]
$stderr.puts("#{DateTime.now} SessionServlet.update_session(): (after mod) opts=#{opts}") # TODO: remove
data = get_db.update_session(opts)
$stderr.puts("#{DateTime.now} SessionServlet.update_session(): data=#{data}") # TODO: remove
$stderr.puts("#{DateTime.now} SessionServlet.update_session(): data.class=#{data.class}") unless data.nil? # TODO: remove
set_json_data_response(response: data)
rescue => e
print_error_and_create_response(error: e, message: 'There was an error updating the session:', code: 500)