Class: Msf::OptPath

Inherits:
OptBase show all
Defined in:
lib/msf/core/opt_path.rb

Overview

File system path option.

Direct Known Subclasses

OptInjectablePE

Instance Attribute Summary

Attributes inherited from OptBase

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

Instance Method Summary collapse

Methods inherited from OptBase

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

Constructor Details

This class inherits a constructor from Msf::OptBase

Instance Method Details

#check_memory_location(id) ⇒ Object

The AuthBrute mixin can take a memory address as well – currently, no other OptFile can make use of these objects. TODO: Implement memory:xxx to be more generally useful so the validator on OptFile isn’t lying for non-AuthBrute.



42
43
44
45
46
47
48
# File 'lib/msf/core/opt_path.rb', line 42

def check_memory_location(id)
  return false unless self.class.const_defined?(:ObjectSpace)
  obj = ObjectSpace._id2ref(id.to_i) rescue nil
  return false unless obj.respond_to? :acts_as_file?
  return false unless obj.acts_as_file? # redundant?
  return !!obj
end

#normalize(value) ⇒ Object



15
16
17
# File 'lib/msf/core/opt_path.rb', line 15

def normalize(value)
  value.nil? || value.to_s.empty? ? value : File.expand_path(value)
end

#typeObject



11
12
13
# File 'lib/msf/core/opt_path.rb', line 11

def type
  return 'path'
end

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

Generally, ‘value’ should be a file that exists.

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/msf/core/opt_path.rb', line 24

def valid?(value, check_empty: true)
  return false if check_empty && empty_required_value?(value)
  if value and !value.empty?
    if value =~ /^memory:\s*([0-9]+)/i
      return false unless check_memory_location($1)
    else
      unless File.exist?(File.expand_path(value))
        return false
      end
    end
  end
  return super
end

#validate_on_assignment?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/msf/core/opt_path.rb', line 19

def validate_on_assignment?
  false
end