2005-10-01 21:27:40 +00:00
|
|
|
require 'rex'
|
|
|
|
require 'msf/base'
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This module provides an initialization interface for logging.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Logging
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Initialize logging.
|
2005-10-01 21:27:40 +00:00
|
|
|
#
|
|
|
|
def self.init
|
|
|
|
if (@initialized != true)
|
|
|
|
@initialized = true
|
|
|
|
|
|
|
|
f = Rex::Logging::Sinks::Flatfile.new(
|
|
|
|
Msf::Config.log_directory + File::SEPARATOR + "framework.log")
|
|
|
|
|
|
|
|
# Register each known log source
|
|
|
|
[
|
2005-11-19 15:09:41 +00:00
|
|
|
Rex::LogSource,
|
|
|
|
Msf::LogSource,
|
2005-10-02 03:21:26 +00:00
|
|
|
'base',
|
2005-10-01 21:27:40 +00:00
|
|
|
].each { |src|
|
|
|
|
register_log_source(src, f)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-10-02 03:21:26 +00:00
|
|
|
#
|
|
|
|
# Enables a log source.
|
|
|
|
#
|
2005-11-22 03:20:09 +00:00
|
|
|
def self.enable_log_source(src, level = 0)
|
2005-11-28 16:52:05 +00:00
|
|
|
if (log_source_registered?(src) == false)
|
|
|
|
f = Rex::Logging::Sinks::Flatfile.new(
|
|
|
|
Msf::Config.log_directory + File::SEPARATOR + "#{src}.log")
|
|
|
|
|
|
|
|
register_log_source(src, f, level)
|
|
|
|
end
|
2005-10-02 03:21:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Stops logging for a given log source.
|
|
|
|
#
|
|
|
|
def self.disable_log_source(src)
|
|
|
|
deregister_log_source(src)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Sets whether or not session logging is to be enabled.
|
|
|
|
#
|
|
|
|
def self.enable_session_logging(tf)
|
|
|
|
@session_logging = tf
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns whether or not session logging is enabled.
|
|
|
|
#
|
|
|
|
def self.session_logging_enabled?
|
|
|
|
@session_logging || false
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Starts logging for a given session.
|
|
|
|
#
|
|
|
|
def self.start_session_log(session)
|
2005-11-28 20:41:11 +00:00
|
|
|
if (log_source_registered?(session.log_source) == false)
|
|
|
|
f = Rex::Logging::Sinks::Flatfile.new(
|
2005-10-02 03:21:26 +00:00
|
|
|
Msf::Config.session_log_directory + File::SEPARATOR + "#{session.log_file_name}.log")
|
2005-11-28 20:41:11 +00:00
|
|
|
|
|
|
|
register_log_source(session.log_source, f)
|
|
|
|
|
|
|
|
rlog("\n[*] Logging started: #{Time.now}\n\n", session.log_source)
|
|
|
|
end
|
2005-10-02 03:21:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Stops logging for a given session.
|
|
|
|
#
|
|
|
|
def self.stop_session_log(session)
|
2005-10-02 03:57:46 +00:00
|
|
|
rlog("\n[*] Logging stopped: #{Time.now}\n\n", session.log_source)
|
|
|
|
|
2005-10-02 03:21:26 +00:00
|
|
|
deregister_log_source(session.log_source)
|
|
|
|
end
|
|
|
|
|
2005-10-01 21:27:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|