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.



60
61
62
# File 'lib/msf/base/logging.rb', line 60

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.



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

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.



68
69
70
# File 'lib/msf/base/logging.rb', line 68

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

.init(log_sink_name = nil) ⇒ void

This method returns an undefined value.

Initialize logging.

Parameters:

  • log_sink_name (string) (defaults to: nil)

    Log sink name.



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

def self.init(log_sink_name = nil)
  if (! @@initialized)
    @@initialized = true

    log_sink ||= Rex::Logging::LogSinkFactory.new(
      log_sink_name,
      Msf::Config.log_directory + File::SEPARATOR + "framework.log"
    )

    # Register each known log source
    [
      Rex::LogSource,
      Rex::Socket::LogSource,
      Msf::LogSource,
      'base',
    ].each { |src|
      register_log_source(src, log_sink)
    }
  end
end

.session_logging_enabled?Boolean

Returns whether or not session logging is enabled.

Returns:

  • (Boolean)

    true if enabled. false if disabled.



75
76
77
# File 'lib/msf/base/logging.rb', line 75

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.



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

def self.start_session_log(session)
  if (log_source_registered?(session.log_source) == false)
    f = Rex::Logging::Sinks::TimestampColorlessFlatfile.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 successful. false if not.



98
99
100
101
102
# File 'lib/msf/base/logging.rb', line 98

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

  deregister_log_source(session.log_source)
end