Class: Ronin::Listener::DNS::Server
- Inherits:
-
Async::DNS::Server
- Object
- Async::DNS::Server
- Ronin::Listener::DNS::Server
- Defined in:
- lib/ronin/listener/dns/server.rb
Overview
A simple DNS server for receiving exfiltrated DNS queries.
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
-
#callback ⇒ Proc
readonly
private
The callback which will be passed all received queries.
-
#domain ⇒ String
readonly
The domain to accept queries for.
-
#host ⇒ String
readonly
The host the server will listen on.
-
#port ⇒ Integer
readonly
The port the server will listen on.
Instance Method Summary collapse
-
#initialize(domain, host: '0.0.0.0', port: 53) {|query| ... } ⇒ Server
constructor
Initializes the DNS listener server.
-
#process(label, resource_class, transaction) ⇒ Object
private
Processes an incoming query.
Constructor Details
#initialize(domain, host: '0.0.0.0', port: 53) {|query| ... } ⇒ Server
Initializes the DNS listener server.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ronin/listener/dns/server.rb', line 76 def initialize(domain, host: '0.0.0.0', port: 53, &callback) unless callback raise(ArgumentError,"#{self.class}#initialize requires a callback block") end @domain = domain @suffix = ".#{domain}" @host = host @port = port super([[:udp, host, port]]) @callback = callback end |
Instance Attribute Details
#callback ⇒ Proc (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 callback which will be passed all received queries.
53 54 55 |
# File 'lib/ronin/listener/dns/server.rb', line 53 def callback @callback end |
#domain ⇒ String (readonly)
The domain to accept queries for.
36 37 38 |
# File 'lib/ronin/listener/dns/server.rb', line 36 def domain @domain end |
#host ⇒ String (readonly)
The host the server will listen on.
41 42 43 |
# File 'lib/ronin/listener/dns/server.rb', line 41 def host @host end |
#port ⇒ Integer (readonly)
The port the server will listen on.
46 47 48 |
# File 'lib/ronin/listener/dns/server.rb', line 46 def port @port end |
Instance Method Details
#process(label, 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 an incoming query.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ronin/listener/dns/server.rb', line 128 def process(label,resource_class,transaction) # filter out queries for all other domains if label.end_with?(@suffix) # map the `Resolv::DNS::Resource::IN` class to a Symbol query_type = RECORD_TYPES.fetch(resource_class) # extract the remote address source_addr = transaction.[:remote_address] @callback.call(Query.new(query_type,label,source_addr)) end # always respond with an error to prevent DNS caching transaction.fail!(:NXDomain) end |