CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/dns/upstream_resolver.rb
Views: 11704
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module DNS
6
##
7
# This represents a single upstream DNS resolver target of one of the predefined types.
8
##
9
class UpstreamResolver
10
module Type
11
BLACK_HOLE = :"black-hole"
12
DNS_SERVER = :"dns-server"
13
STATIC = :static
14
SYSTEM = :system
15
end
16
17
attr_reader :type, :destination, :socket_options
18
19
# @param [Symbol] type The resolver type.
20
# @param [String] destination An optional destination, as used by some resolver types.
21
# @param [Hash] socket_options Options to use for sockets when connecting to the destination, as used by some
22
# resolver types.
23
def initialize(type, destination: nil, socket_options: {})
24
@type = type
25
@destination = destination
26
@socket_options = socket_options
27
end
28
29
# Initialize a new black-hole resolver.
30
def self.create_black_hole
31
self.new(Type::BLACK_HOLE)
32
end
33
34
# Initialize a new dns-server resolver.
35
#
36
# @param [String] destination The IP address of the upstream DNS server.
37
# @param [Hash] socket_options Options to use when connecting to the upstream DNS server.
38
def self.create_dns_server(destination, socket_options: {})
39
self.new(
40
Type::DNS_SERVER,
41
destination: destination,
42
socket_options: socket_options
43
)
44
end
45
46
# Initialize a new static resolver.
47
def self.create_static
48
self.new(Type::STATIC)
49
end
50
51
# Initialize a new system resolver.
52
def self.create_system
53
self.new(Type::SYSTEM)
54
end
55
56
def to_s
57
if type == Type::DNS_SERVER
58
destination.to_s
59
else
60
type.to_s
61
end
62
end
63
64
def eql?(other)
65
return false unless other.is_a?(self.class)
66
return false unless other.type == type
67
return false unless other.destination == destination
68
return false unless other.socket_options == socket_options
69
true
70
end
71
72
alias == eql?
73
end
74
end
75
end
76
end
77
78