Class: Msf::OptAddress

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

Overview

Network address option.

Direct Known Subclasses

OptAddressLocal

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 OptBase

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

Constructor Details

This class inherits a constructor from Msf::OptBase

Instance Method Details

#typeObject


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

def type
  return 'address'
end

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

Returns:

  • (Boolean)

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

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

  if (value != nil and value.empty? == false)
    begin
      getaddr_result = ::Rex::Socket.getaddress(value, true)
      # Covers a wierdcase where an incomplete ipv4 address will have it's
      # missing octets filled in  with 0's. (e.g 192.168 become 192.0.0.168)
      # which does not feel like a legit behaviour
      if value =~ /^\d{1,3}(\.\d{1,3}){1,3}$/
        return false unless value =~ Rex::Socket::MATCH_IPV4
      end
    rescue
      return false
    end
  end

  return super
end