Module: Ronin::Payloads::Mixins::ResolveHost

Included in:
Shellcode::BindShellPayload, Shellcode::ReverseShellPayload
Defined in:
lib/ronin/payloads/mixins/resolve_host.rb

Overview

Adds methods for resolving the host parameter and converting it to IP address(es).

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#host_addressString?

Resolves the host parameter and returns the first address.

Returns:

  • (String, nil)

Since:

  • 1.0.0



61
62
63
# File 'lib/ronin/payloads/mixins/resolve_host.rb', line 61

def host_address
  host_addresses.first
end

#host_addressesArray<String>

Resolves the host and returns it's IP addresses.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ronin/payloads/mixins/resolve_host.rb', line 43

def host_addresses
  host = params[:host]

  # check if the `host` value is already an IP address
  if host =~ IPAddr::RE_IPV4ADDRLIKE ||
     host =~ IPAddr::RE_IPV6ADDRLIKE_COMPRESSED ||
     host =~ IPAddr::RE_IPV6ADDRLIKE_FULL
    [host]
  else
    Support::Network::DNS.get_addresses(host)
  end
end

#host_ip_addressString?

Resolves the host parameter and returns the first IPv4 or IPv6 address.

Returns:

  • (String, nil)

Since:

  • 1.0.0



89
90
91
# File 'lib/ronin/payloads/mixins/resolve_host.rb', line 89

def host_ip_address
  host_ip_addresses.first
end

#host_ip_addressesArray<String>

Resolves the host and returns it's IPv4 and IPv6 addresses.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ronin/payloads/mixins/resolve_host.rb', line 70

def host_ip_addresses
  host = params[:host]

  # check if the `host` value is already an IP address
  if host =~ IPAddr::RE_IPV4ADDRLIKE ||
     host =~ IPAddr::RE_IPV6ADDRLIKE_COMPRESSED ||
     host =~ IPAddr::RE_IPV6ADDRLIKE_FULL
    [host]
  else
    Support::Network::DNS.get_ip_addresses(host)
  end
end

#host_ipv4_addressString?

Resolves the host parameter and returns the first IPv4 address.

Returns:

  • (String, nil)

Since:

  • 1.0.0



116
117
118
# File 'lib/ronin/payloads/mixins/resolve_host.rb', line 116

def host_ipv4_address
  host_ipv4_addresses.first
end

#host_ipv4_addressesArray<String>

Resolves the host parameter and returns the IPv4 addresses.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/ronin/payloads/mixins/resolve_host.rb', line 98

def host_ipv4_addresses
  host = params[:host]

  if host =~ IPAddr::RE_IPV4ADDRLIKE
    [host]
  elsif host =~ IPAddr::RE_IPV6ADDRLIKE_COMPRESSED ||
        host =~ IPAddr::RE_IPV6ADDRLIKE_FULL
    raise(ValidationError,"host must be a hostname or an IPv4 address, was an IPv6 address: #{host.inspect}")
  else
    Support::Network::DNS.get_ipv4_addresses(host)
  end
end

#host_ipv6_addressString?

Resolves the host parameter and returns the first IPv6 address.

Returns:

  • (String, nil)

Since:

  • 1.0.0



143
144
145
# File 'lib/ronin/payloads/mixins/resolve_host.rb', line 143

def host_ipv6_address
  host_ipv6_addresses.first
end

#host_ipv6_addressesArray<String>

Resolves the host parameter and returns the IPv6 addresses.

Returns:

  • (Array<String>)

Since:

  • 1.0.0



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/ronin/payloads/mixins/resolve_host.rb', line 125

def host_ipv6_addresses
  host = params[:host]

  if host =~ IPAddr::RE_IPV4ADDRLIKE
    ["::ffff:#{host}"]
  elsif host =~ IPAddr::RE_IPV6ADDRLIKE_COMPRESSED ||
        host =~ IPAddr::RE_IPV6ADDRLIKE_FULL
    [host]
  else
    Support::Network::DNS.get_ipv6_addresses(host)
  end
end