Class: Msf::OptAddress

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

Overview

Network address option.

Instance Attribute Summary

Attributes inherited from OptBase

#advanced, #default, #desc, #enums, #evasion, #name, #owner, #required

Instance Method Summary collapse

Methods inherited from OptBase

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

Constructor Details

This class inherits a constructor from Msf::OptBase

Instance Method Details

#typeObject


328
329
330
# File 'lib/msf/core/option_container.rb', line 328

def type
  return 'address'
end

#valid?(value) ⇒ Boolean


332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/msf/core/option_container.rb', line 332

def valid?(value)
  return false if 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