Class: Msf::OptAddressOrHostname
- Inherits:
-
OptAddressRoutable
- Object
- OptBase
- OptAddress
- OptAddressRoutable
- Msf::OptAddressOrHostname
- Defined in:
- lib/msf/core/opt_address_or_hostname.rb
Overview
Network address or hostname option.
Accepts an IPv4/IPv6 address, a local network interface name, or a syntactically valid hostname. Unlike OptAddress, DNS resolution is NOT performed during validation, so tunnel service hostnames (ngrok, pinggy, etc.) that are not resolvable from the local machine are accepted.
Use this for options like LHOST where the value identifies the callback endpoint embedded in a payload, and may be a tunnel hostname rather than a locally-resolvable address.
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
-
#initialize(in_name, attrs = [], resolve_names: false, **kwargs) ⇒ OptAddressOrHostname
constructor
A new instance of OptAddressOrHostname.
- #normalize(value) ⇒ Object
- #type ⇒ Object
- #valid?(value, check_empty: true, datastore: nil) ⇒ Boolean
Methods inherited from OptAddressRoutable
Methods inherited from OptBase
#advanced?, #display_value, #empty_required_value?, #evasion?, #invalid_value_length?, #required?, #type?, #validate_on_assignment?
Constructor Details
#initialize(in_name, attrs = [], resolve_names: false, **kwargs) ⇒ OptAddressOrHostname
Returns a new instance of OptAddressOrHostname.
27 28 29 30 |
# File 'lib/msf/core/opt_address_or_hostname.rb', line 27 def initialize(in_name, attrs = [], resolve_names: false, **kwargs) super(in_name, attrs, **kwargs) @resolve_names = resolve_names end |
Instance Method Details
#normalize(value) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/msf/core/opt_address_or_hostname.rb', line 61 def normalize(value) return unless value.kind_of?(String) return normalize_interface(value) if interfaces.include?(value) return normalize_ip_address(value) if Rex::Socket.is_ip_addr?(value) value end |
#type ⇒ Object
32 33 34 |
# File 'lib/msf/core/opt_address_or_hostname.rb', line 32 def type 'address' end |
#valid?(value, check_empty: true, datastore: nil) ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/msf/core/opt_address_or_hostname.rb', line 36 def valid?(value, check_empty: true, datastore: nil) return false if check_empty && empty_required_value?(value) return false unless value.kind_of?(String) || value.kind_of?(NilClass) if value && !value.empty? return true if Rex::Socket.is_ip_addr?(value) && Rex::Socket.addr_atoi(value) == 0 return super if Rex::Socket.is_ip_addr?(value) if Rex::Socket.is_name?(value) return true unless @resolve_names begin ::Rex::Socket.getaddress(value, true) return true rescue StandardError return false end end return false end true end |