Class: Msf::Logging

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/base/logging.rb

Overview

This module provides an initialization interface for logging.

Constant Summary collapse

@@initialized =

Is logging initialized

false
@@session_logging =

Is session logging enabled

false

Class Method Summary collapse

Class Method Details

.disable_log_source(src) ⇒ Boolean

Stops logging for a given log source.

Parameters:

  • src (String)

    the log source to disable.

Returns:

  • (Boolean)

    true if successful. false if not.


58
59
60
# File 'lib/msf/base/logging.rb', line 58

def self.disable_log_source(src)
  deregister_log_source(src)
end

.enable_log_source(src, level = 0) ⇒ void

This method returns an undefined value.

Enables a log source of name src. Creates the .log file in the configured directory if logging is not already enabled for this source.

Parameters:

  • src (String)

    log source name.

  • level (Integer) (defaults to: 0)

    logging level.


45
46
47
48
49
50
51
52
# File 'lib/msf/base/logging.rb', line 45

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

.enable_session_logging(tf) ⇒ void

This method returns an undefined value.

Sets whether or not session logging is to be enabled.

Parameters:

  • tf (Boolean)

    true if enabling. false if disabling.


66
67
68
# File 'lib/msf/base/logging.rb', line 66

def self.enable_session_logging(tf)
  @@session_logging = tf
end

.initvoid

This method returns an undefined value.

Initialize logging.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/msf/base/logging.rb', line 20

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

.session_logging_enabled?Boolean

Returns whether or not session logging is enabled.

Returns:

  • (Boolean)

    true if enabled. false if disabled.


73
74
75
# File 'lib/msf/base/logging.rb', line 73

def self.session_logging_enabled?
  @@session_logging || false
end

.start_session_log(session) ⇒ void

This method returns an undefined value.

Starts logging for a given session.

Parameters:

  • session (Msf::Session)

    the session to start logging on.


81
82
83
84
85
86
87
88
89
90
# File 'lib/msf/base/logging.rb', line 81

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

.stop_session_log(session) ⇒ Boolean

Stops logging for a given session.

Parameters:

Returns:

  • (Boolean)

    true if sucessful. false if not.


96
97
98
99
100
# File 'lib/msf/base/logging.rb', line 96

def self.stop_session_log(session)
  rlog("\n[*] Logging stopped: #{Time.now}\n\n", session.log_source)

  deregister_log_source(session.log_source)
end