2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
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
|
|
|
|
|
2013-12-25 01:43:14 +00:00
|
|
|
#Is logging initialized
|
|
|
|
#@private
|
2013-08-30 21:28:33 +00:00
|
|
|
@@initialized = false
|
2013-12-25 01:43:14 +00:00
|
|
|
#Is session logging enabled
|
|
|
|
#@private
|
2013-08-30 21:28:33 +00:00
|
|
|
@@session_logging = false
|
|
|
|
|
|
|
|
# Initialize logging.
|
2013-12-26 18:14:41 +00:00
|
|
|
#
|
2013-12-25 01:43:14 +00:00
|
|
|
# @return [void]
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.init
|
|
|
|
if (! @@initialized)
|
|
|
|
@@initialized = true
|
|
|
|
|
|
|
|
f = Rex::Logging::Sinks::Flatfile.new(
|
|
|
|
Msf::Config.log_directory + File::SEPARATOR + "framework.log")
|
|
|
|
|
|
|
|
# Register each known log source
|
|
|
|
[
|
|
|
|
Rex::LogSource,
|
|
|
|
Msf::LogSource,
|
|
|
|
'base',
|
|
|
|
].each { |src|
|
|
|
|
register_log_source(src, f)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-12-25 01:43:14 +00:00
|
|
|
# Enables a log source of name src. Creates the .log file in the
|
|
|
|
# configured directory if logging is not already enabled for this
|
|
|
|
# source.
|
2013-12-26 18:14:41 +00:00
|
|
|
#
|
|
|
|
# @param src [String] log source name.
|
|
|
|
# @param level [Integer] logging level.
|
2013-12-25 01:43:14 +00:00
|
|
|
# @return [void]
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.enable_log_source(src, level = 0)
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
# Stops logging for a given log source.
|
2013-12-26 18:14:41 +00:00
|
|
|
#
|
|
|
|
# @param src [String] the log source to disable.
|
2013-12-25 01:43:14 +00:00
|
|
|
# @return [Boolean] true if successful. false if not.
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.disable_log_source(src)
|
|
|
|
deregister_log_source(src)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Sets whether or not session logging is to be enabled.
|
2013-12-26 18:14:41 +00:00
|
|
|
#
|
|
|
|
# @param tf [Boolean] true if enabling. false if disabling.
|
2013-12-25 01:43:14 +00:00
|
|
|
# @return [void]
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.enable_session_logging(tf)
|
|
|
|
@@session_logging = tf
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns whether or not session logging is enabled.
|
2013-12-26 18:14:41 +00:00
|
|
|
#
|
2013-12-25 01:43:14 +00:00
|
|
|
# @return [Boolean] true if enabled. false if disabled.
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.session_logging_enabled?
|
|
|
|
@@session_logging || false
|
|
|
|
end
|
|
|
|
|
|
|
|
# Starts logging for a given session.
|
2013-12-26 18:14:41 +00:00
|
|
|
#
|
|
|
|
# @param session [Msf::Session] the session to start logging on.
|
2013-12-25 01:43:14 +00:00
|
|
|
# @return [void]
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.start_session_log(session)
|
|
|
|
if (log_source_registered?(session.log_source) == false)
|
|
|
|
f = Rex::Logging::Sinks::Flatfile.new(
|
|
|
|
Msf::Config.session_log_directory + File::SEPARATOR + "#{session.log_file_name}.log")
|
|
|
|
|
|
|
|
register_log_source(session.log_source, f)
|
|
|
|
|
|
|
|
rlog("\n[*] Logging started: #{Time.now}\n\n", session.log_source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Stops logging for a given session.
|
2013-12-26 18:14:41 +00:00
|
|
|
#
|
|
|
|
# @param session [Msf::Session] the session to stop logging.
|
2013-12-25 01:43:14 +00:00
|
|
|
# @return [Boolean] true if sucessful. false if not.
|
2013-08-30 21:28:33 +00:00
|
|
|
def self.stop_session_log(session)
|
|
|
|
rlog("\n[*] Logging stopped: #{Time.now}\n\n", session.log_source)
|
|
|
|
|
|
|
|
deregister_log_source(session.log_source)
|
|
|
|
end
|
2005-10-02 03:21:26 +00:00
|
|
|
|
2005-10-01 21:27:40 +00:00
|
|
|
end
|
|
|
|
|
2009-11-13 17:31:57 +00:00
|
|
|
end
|