Class: Msf::OptAddressLocal
- Inherits:
-
OptAddress
- Object
- OptBase
- OptAddress
- Msf::OptAddressLocal
- 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, #fallbacks, #max_length, #name, #owner, #regex, #required
Instance Method Summary collapse
Methods inherited from OptAddress
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
#interfaces ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/msf/core/opt_address_local.rb', line 12 def interfaces begin NetworkInterface.interfaces || [] rescue NetworkInterface::Error => e elog(e) [] end end |
#normalize(value) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/msf/core/opt_address_local.rb', line 21 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::Error false end end # Sort for deterministic normalization; preference ipv4 addresses followed by their value sorted_addrs = addrs.sort_by { |addr| ip_addr = IPAddr.new(addr); [ip_addr.ipv4? ? 0 : 1, ip_addr.to_i] } sorted_addrs.any? ? sorted_addrs.first : '' end |
#valid?(value, check_empty: true) ⇒ Boolean
42 43 44 45 46 47 48 49 |
# File 'lib/msf/core/opt_address_local.rb', line 42 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 |