Class: Ronin::CLI::Commands::DnsProxy Private
- Inherits:
-
Ronin::CLI::Command
- Object
- Core::CLI::Command
- Ronin::CLI::Command
- Ronin::CLI::Commands::DnsProxy
- Includes:
- Core::CLI::Logging
- Defined in:
- lib/ronin/cli/commands/dns_proxy.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Starts a DNS proxy.
Usage
ronin dns-proxy [options] [HOST] PORT
Options
-n, --nameserver IP The upstream nameserver IP to use
-r RECORD_TYPE:NAME:RESULT|RECORD_TYPE:/REGEXP/:RESULT,
--rule Adds a rule to the DNS proxy
-h, --help Print help information
Arguments
[HOST] The host name to listen on.
PORT The port number to listen on.
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.
Record types.
{ 'A' => :A, 'AAAA' => :AAAA, 'ANY' => :ANY, 'CNAME' => :CNAME, 'HINFO' => :HINFO, 'LOC' => :LOC, 'MINFO' => :MINFO, 'MX' => :MX, 'NS' => :NS, 'PTR' => :PTR, 'SOA' => :SOA, 'SRV' => :SRV, 'TXT' => :TXT, 'WKS' => :WKS }
- ERROR_CODES =
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.
Error names.
{ 'NoError' => :NoError, 'FormErr' => :FormErr, 'ServFail' => :ServFail, 'NXDomain' => :NXDomain, 'NotImp' => :NotImp, 'Refused' => :Refused, 'NotAuth' => :NotAuth }
Instance Attribute Summary collapse
-
#nameservers ⇒ Array<String>
readonly
private
The upstream nameserver IP addresses to forward DNS queries to.
-
#rules ⇒ Array<(Symbol, String, String), (Symbol, Regexp, String)>
readonly
private
The rules for the DNS proxy server.
Instance Method Summary collapse
-
#initialize(**kwargs) ⇒ DnsProxy
constructor
private
Initializes the
ronin dns-proxy
command. -
#parse_record_name(name) ⇒ String, Regex
private
Parses the name field of a record.
-
#parse_record_type(record_type) ⇒ :A, ...
private
Parses a record type name.
-
#parse_rule(rule) ⇒ (Symbol, String, String), (Symbol, Regexp, String)
private
Parses a rule string.
-
#parse_rule_result(result) ⇒ String, ...
private
Parses a result value.
-
#proxy_kwargs ⇒ Hash{Symbol => Object}
private
The keyword arguments for
Ronin::DNS::Proxy.run
. -
#run(host = '127.0.0.1', port) ⇒ Object
private
Runs the
ronin dns-proxy
command.
Constructor Details
#initialize(**kwargs) ⇒ DnsProxy
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.
Initializes the ronin dns-proxy
command.
97 98 99 100 101 102 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 97 def initialize(**kwargs) super(**kwargs) @nameservers = [] @rules = [] end |
Instance Attribute Details
#nameservers ⇒ Array<String> (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 nameserver IP addresses to forward DNS queries to.
84 85 86 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 84 def nameservers @nameservers end |
#rules ⇒ Array<(Symbol, String, String), (Symbol, Regexp, String)> (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 rules for the DNS proxy server.
89 90 91 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 89 def rules @rules end |
Instance Method Details
#parse_record_name(name) ⇒ String, Regex
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.
Parses the name field of a record.
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 178 def parse_record_name(name) if name.start_with?('/') && name.end_with?('/') begin Regexp.new(name[1..-2]) rescue RegexpError => error raise(OptionParser::InvalidArgument,"invalid Regexp: #{error.}") end else name end end |
#parse_record_type(record_type) ⇒ :A, ...
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.
Parses a record type name.
159 160 161 162 163 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 159 def parse_record_type(record_type) RECORD_TYPES.fetch(record_type) do raise(OptionParser::InvalidArgument,"invalid record type: #{record_type.inspect}") end end |
#parse_rule(rule) ⇒ (Symbol, String, String), (Symbol, Regexp, String)
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.
Parses a rule string.
226 227 228 229 230 231 232 233 234 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 226 def parse_rule(rule) record_type, name, result = rule.split(':',3) [ parse_record_type(record_type), parse_record_name(name), parse_rule_result(result) ] end |
#parse_rule_result(result) ⇒ String, ...
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.
Parses a result value.
210 211 212 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 210 def parse_rule_result(result) ERROR_CODES.fetch(result,result) end |
#proxy_kwargs ⇒ Hash{Symbol => 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.
The keyword arguments for Ronin::DNS::Proxy.run
.
119 120 121 122 123 124 125 126 127 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 119 def proxy_kwargs kwargs = {rules: @rules} unless @nameservers.empty? kwargs[:nameservers] = @nameservers end return kwargs end |
#run(host = '127.0.0.1', port) ⇒ 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.
Runs the ronin dns-proxy
command.
107 108 109 110 111 112 |
# File 'lib/ronin/cli/commands/dns_proxy.rb', line 107 def run(host='127.0.0.1',port) port = port.to_i log_info "Listening on #{host}:#{port} ..." DNS::Proxy.run(host,port,**proxy_kwargs) end |