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 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 Method Details

#raw_to_host_ip_pair(host, raw, type) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb', line 80

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

  if raw.empty?
    ip = nil
  else
    if type == AF_INET
      ip = Rex::Socket.addr_ntoa(raw[0..3])
    else
      ip = Rex::Socket.addr_ntoa(raw[0..16])
    end
  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
45
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb', line 34

def resolve_host(hostname, family=AF_INET)
  request = Packet.create_request('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)

  type = response.get_tlv_value(TLV_TYPE_ADDR_TYPE)
  raw = response.get_tlv_value(TLV_TYPE_IP)

  return raw_to_host_ip_pair(hostname, raw, type)
end

#resolve_hosts(hostnames, family = AF_INET) ⇒ Object



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
72
73
74
75
76
77
78
# File 'lib/rex/post/meterpreter/extensions/stdapi/net/resolve.rb', line 47

def resolve_hosts(hostnames, family=AF_INET)
  request = Packet.create_request('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 = []
  types = []

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

  response.each(TLV_TYPE_ADDR_TYPE) do |type|
    types << type
  end

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

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

  return hosts
end