Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/base/logging.rb
Views: 11780
# -*- coding: binary -*-1require 'rex'2module Msf34# This module provides an initialization interface for logging.5class Logging67#Is logging initialized8#@private9@@initialized = false10#Is session logging enabled11#@private12@@session_logging = false1314# Initialize logging.15#16# @param log_sink_name [string] Log sink name.17# @return [void]18def self.init(log_sink_name = nil)19if (! @@initialized)20@@initialized = true2122log_sink ||= Rex::Logging::LogSinkFactory.new(23log_sink_name,24Msf::Config.log_directory + File::SEPARATOR + "framework.log"25)2627# Register each known log source28[29Rex::LogSource,30Rex::Socket::LogSource,31Msf::LogSource,32'base',33].each { |src|34register_log_source(src, log_sink)35}36end37end3839# Enables a log source of name src. Creates the .log file in the40# configured directory if logging is not already enabled for this41# source.42#43# @param src [String] log source name.44# @param level [Integer] logging level.45# @return [void]46def self.enable_log_source(src, level = 0)47if (log_source_registered?(src) == false)48f = Rex::Logging::Sinks::Flatfile.new(49Msf::Config.log_directory + File::SEPARATOR + "#{src}.log")5051register_log_source(src, f, level)52end53end5455# Stops logging for a given log source.56#57# @param src [String] the log source to disable.58# @return [Boolean] true if successful. false if not.59def self.disable_log_source(src)60deregister_log_source(src)61end6263# Sets whether or not session logging is to be enabled.64#65# @param tf [Boolean] true if enabling. false if disabling.66# @return [void]67def self.enable_session_logging(tf)68@@session_logging = tf69end7071# Returns whether or not session logging is enabled.72#73# @return [Boolean] true if enabled. false if disabled.74def self.session_logging_enabled?75@@session_logging || false76end7778# Starts logging for a given session.79#80# @param session [Msf::Session] the session to start logging on.81# @return [void]82def self.start_session_log(session)83if (log_source_registered?(session.log_source) == false)84f = Rex::Logging::Sinks::TimestampColorlessFlatfile.new(85Msf::Config.session_log_directory + File::SEPARATOR + "#{session.log_file_name}.log")8687register_log_source(session.log_source, f)8889rlog("\n[*] Logging started: #{Time.now}\n\n", session.log_source)90end91end9293# Stops logging for a given session.94#95# @param session [Msf::Session] the session to stop logging.96# @return [Boolean] true if successful. false if not.97def self.stop_session_log(session)98rlog("\n[*] Logging stopped: #{Time.now}\n\n", session.log_source)99100deregister_log_source(session.log_source)101end102103end104105end106107108