Class: Rex::Post::Meterpreter::Extensions::Stdapi::Net::Resolve

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb

Overview

This class provides DNS resolution from the perspective of the remote host.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Resolve

Initializes a Resolve instance that is used to resolve network addresses on the remote machine.



30
31
32
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb', line 30

def initialize(client)
  self.client = client
end

Instance Attribute Details

#clientObject (protected)

:nodoc:



92
93
94
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb', line 92

def client
  @client
end

Instance Method Details

#raw_to_host_ip_pair(host, raw) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb', line 73

def raw_to_host_ip_pair(host, raw)
  if raw.nil? or host.nil?
    return nil
  end

  ip = nil
  if raw.length == 4 || raw.length == 16
    ip = Rex::Socket.addr_ntoa(raw)
  elsif raw.length != 0
    wlog("hostname resolution failed, the returned address is corrupt (hostname: #{host}, length: #{raw.length})")
  end

  result = { :hostname => host, :ip => ip }

  return result
end

#resolve_host(hostname, family = AF_INET) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb', line 34

def resolve_host(hostname, family=AF_INET)
  request = Packet.create_request(COMMAND_ID_STDAPI_NET_RESOLVE_HOST)
  request.add_tlv(TLV_TYPE_HOST_NAME, hostname)
  request.add_tlv(TLV_TYPE_ADDR_TYPE, family)

  response = client.send_request(request)

  raw = response.get_tlv_value(TLV_TYPE_IP)

  return raw_to_host_ip_pair(hostname, raw)
end

#resolve_hosts(hostnames, family = AF_INET) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb', line 46

def resolve_hosts(hostnames, family=AF_INET)
  request = Packet.create_request(COMMAND_ID_STDAPI_NET_RESOLVE_HOSTS)
  request.add_tlv(TLV_TYPE_ADDR_TYPE, family)

  hostnames.each do |hostname|
    request.add_tlv(TLV_TYPE_HOST_NAME, hostname)
  end

  response = client.send_request(request)

  hosts = []
  raws = []

  response.each(TLV_TYPE_IP) do |raw|
    raws << raw
  end

  0.upto(hostnames.length - 1) do |i|
    raw = raws[i]
    host = hostnames[i]

    hosts << raw_to_host_ip_pair(host, raw&.value)
  end

  return hosts
end