Class: Ronin::DNS::Proxy::Server
- Inherits:
-
Async::DNS::Server
- Object
- Async::DNS::Server
- Ronin::DNS::Proxy::Server
- Defined in:
- lib/ronin/dns/proxy/server.rb
Overview
A rule based DNS proxy server.
Constant Summary collapse
- RECORD_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mapping of Resolv resource classes to Symbols.
{ Resolv::DNS::Resource::IN::A => :A, Resolv::DNS::Resource::IN::AAAA => :AAAA, Resolv::DNS::Resource::IN::ANY => :ANY, Resolv::DNS::Resource::IN::CNAME => :CNAME, Resolv::DNS::Resource::IN::HINFO => :HINFO, Resolv::DNS::Resource::IN::LOC => :LOC, Resolv::DNS::Resource::IN::MINFO => :MINFO, Resolv::DNS::Resource::IN::MX => :MX, Resolv::DNS::Resource::IN::NS => :NS, Resolv::DNS::Resource::IN::PTR => :PTR, Resolv::DNS::Resource::IN::SOA => :SOA, Resolv::DNS::Resource::IN::SRV => :SRV, Resolv::DNS::Resource::IN::TXT => :TXT, Resolv::DNS::Resource::IN::WKS => :WKS }
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
The host the server will listen on.
-
#port ⇒ Integer
readonly
The port the server will listen on.
-
#resolver ⇒ Async::DNS::Resolver
readonly
private
The upstream DNS resolver.
-
#rules ⇒ Array<Rule>
readonly
private
The defined rules for the proxy server.
Instance Method Summary collapse
-
#initialize(host, port, nameservers: Ronin::Support::Network::DNS.nameservers, rules: nil) {|server| ... } ⇒ Server
constructor
Initializes the DNS server.
-
#process(name, resource_class, transaction) ⇒ Object
private
Processes a received query.
-
#rule(record_type, name, result = nil) {|type, name, transaction| ... } ⇒ Object
Adds a rule to the server.
Constructor Details
#initialize(host, port, nameservers: Ronin::Support::Network::DNS.nameservers, rules: nil) {|server| ... } ⇒ Server
Initializes the DNS server.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ronin/dns/proxy/server.rb', line 89 def initialize(host,port, nameservers: Ronin::Support::Network::DNS.nameservers, rules: nil) @host = host @port = port super([[:udp, host, port]]) @resolver = Async::DNS::Resolver.new( nameservers.map { |ip| [:udp, ip, 53] } ) @rules = [] if rules rules.each do |(record_type,name,result)| rule(record_type,name,result) end end yield self if block_given? end |
Instance Attribute Details
#host ⇒ String (readonly)
The host the server will listen on.
37 38 39 |
# File 'lib/ronin/dns/proxy/server.rb', line 37 def host @host end |
#port ⇒ Integer (readonly)
The port the server will listen on.
42 43 44 |
# File 'lib/ronin/dns/proxy/server.rb', line 42 def port @port end |
#resolver ⇒ Async::DNS::Resolver (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The upstream DNS resolver.
49 50 51 |
# File 'lib/ronin/dns/proxy/server.rb', line 49 def resolver @resolver end |
#rules ⇒ Array<Rule> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The defined rules for the proxy server.
56 57 58 |
# File 'lib/ronin/dns/proxy/server.rb', line 56 def rules @rules end |
Instance Method Details
#process(name, resource_class, transaction) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Processes a received query.
209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/ronin/dns/proxy/server.rb', line 209 def process(name,resource_class,transaction) query_type = RECORD_TYPES.fetch(resource_class) matched_rule = @rules.find do |rule| rule.matches?(query_type,name) end if matched_rule matched_rule.call(query_type,name,transaction) else transaction.passthrough!(@resolver) end end |
#rule(record_type, name, result = nil) {|type, name, transaction| ... } ⇒ Object
Adds a rule to the server.
167 168 169 170 171 172 173 |
# File 'lib/ronin/dns/proxy/server.rb', line 167 def rule(record_type,name,result=nil,&block) unless (result || block) raise(ArgumentError,"must specify a result value or a block") end @rules << Rule.new(record_type,name,result,&block) end |