Class: Msf::OptAddressLocal

Inherits:
OptAddress show all
Defined in:
lib/msf/core/opt_address_local.rb

Overview

Local network address option.

Instance Attribute Summary

Attributes inherited from OptBase

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

Instance Method Summary collapse

Methods inherited from OptAddress

#type

Methods inherited from OptBase

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

Constructor Details

This class inherits a constructor from Msf::OptBase

Instance Method Details

#interfacesObject



12
13
14
# File 'lib/msf/core/opt_address_local.rb', line 12

def interfaces
  NetworkInterface.interfaces || []
end

#normalize(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/msf/core/opt_address_local.rb', line 16

def normalize(value)
  return unless value.kind_of?(String)
  return value unless interfaces.include?(value)

  addrs = NetworkInterface.addresses(value).values.flatten

  # Strip interface name from address (see getifaddrs(3))
  addrs = addrs.map { |x| x['addr'].split('%').first }.select do |addr|
    begin
      IPAddr.new(addr)
    rescue IPAddr::InvalidAddressError
      false
    end
  end

  addrs.any? ? addrs.first : ''
end

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

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
# File 'lib/msf/core/opt_address_local.rb', line 34

def valid?(value, check_empty: true)
  return false if check_empty && empty_required_value?(value)
  return false unless value.kind_of?(String) || value.kind_of?(NilClass)

  return true if interfaces.include?(value)

  super
end