Class: Msf::OptMeterpreterDebugLogging

Inherits:
OptBase
  • Object
show all
Defined in:
lib/msf/core/opt_meterpreter_debug_logging.rb

Overview

Meterpreter Debug Logging option

Instance Attribute Summary

Attributes inherited from OptBase

#advanced, #aliases, #conditions, #default, #desc, #enums, #evasion, #fallbacks, #max_length, #name, #owner, #regex, #required

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OptBase

#advanced?, #display_value, #empty_required_value?, #evasion?, #invalid_value_length?, #normalize, #required?, #type?

Constructor Details

#initialize(in_name, attrs = [], **kwargs) ⇒ OptMeterpreterDebugLogging

Returns a new instance of OptMeterpreterDebugLogging.



10
11
12
# File 'lib/msf/core/opt_meterpreter_debug_logging.rb', line 10

def initialize(in_name, attrs = [], **kwargs)
  super
end

Class Method Details

.parse_logging_options(value) ⇒ Object

Parses the given Meterpreter Debug Logging string



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/msf/core/opt_meterpreter_debug_logging.rb', line 38

def self.parse_logging_options(value)
  result = {}
  errors = []

  return result if value.nil?

  value = value.strip
  # Match 'rpath:./file', 'rpath:/file', and drive letters e.g. 'rpath:C:/file'
  rpath_regex = %r{^rpath:((\.?/\p{ASCII}+)|(\p{ASCII}:/\p{ASCII}+))}i

  # Check if we log to rpath
  if value.match?(rpath_regex)
    # https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd
    max_length = 260
    rpath_value = value.split('rpath:').last
    if rpath_value.length <= max_length
      result[:rpath] = rpath_value
    else
      errors << "Rpath is too long. Max length: #{max_length}"
    end
  else
    errors << 'Value is not a valid rpath string'
  end

  if errors.any?
    raise ::ArgumentError, "Failed to validate MeterpreterDebugLogging option: #{value} with error/errors: #{errors.join('. ')}"
  end

  result
end

Instance Method Details

#typeObject



14
15
16
# File 'lib/msf/core/opt_meterpreter_debug_logging.rb', line 14

def type
  'meterpreterdebuglogging'
end

#valid?(value, check_empty: true) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
# File 'lib/msf/core/opt_meterpreter_debug_logging.rb', line 22

def valid?(value, check_empty: true)
  return false if !super(value, check_empty: check_empty)

  begin
    _parse_result = self.class.parse_logging_options(value)
    true
  rescue ::ArgumentError
    false
  end
end

#validate_on_assignment?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/msf/core/opt_meterpreter_debug_logging.rb', line 18

def validate_on_assignment?
  true
end