Module: Ronin::CLI::DNS Private

Included in:
Commands::Dns, Commands::Host
Defined in:
lib/ronin/cli/dns.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Mixin for adding DNS support to commands.

Since:

  • 2.0.0

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 DNS record types and lowercase versions.

Since:

  • 2.0.0

{
  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
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameserversArray<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 configured nameservers to query.

Returns:

  • (Array<String>)

Since:

  • 2.0.0



66
67
68
# File 'lib/ronin/cli/dns.rb', line 66

def nameservers
  @nameservers
end

Class Method Details

.included(command) ⇒ 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.

Adds the -N,--nameserver HOST|IP option to the command which is including Ronin::CLI::DNS.

Parameters:

Since:

  • 2.0.0



52
53
54
55
56
57
58
59
60
61
# File 'lib/ronin/cli/dns.rb', line 52

def self.included(command)
  command.option :nameserver, short: '-N',
                              value: {
                                type: String,
                                usage: 'HOST|IP'
                              },
                              desc: 'Send DNS queries to the nameserver' do |ip|
                                @nameservers << ip
                              end
end

Instance Method Details

#initialize(**kwargs) ⇒ 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.

Initializes the command.

Since:

  • 2.0.0



71
72
73
74
75
# File 'lib/ronin/cli/dns.rb', line 71

def initialize(**kwargs)
  super(**kwargs)

  @nameservers = []
end

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.

Prints a DNS record.

Parameters:

  • record (Resolv::DNS::Resource)

    The DNS resource record to print.

Since:

  • 2.0.0



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ronin/cli/dns.rb', line 111

def print_record(record)
  case record
  when Resolv::DNS::Resource::IN::A,
    Resolv::DNS::Resource::IN::AAAA
    puts record.address
  when Resolv::DNS::Resource::IN::NS,
    Resolv::DNS::Resource::IN::CNAME,
    Resolv::DNS::Resource::IN::PTR
    puts record.name
  when Resolv::DNS::Resource::IN::MX
    puts record.exchange
  when Resolv::DNS::Resource::IN::TXT
    puts record.strings.join
  when Resolv::DNS::Resource::IN::HINFO
    puts "#{record.cpu} #{record.os}"
  when Resolv::DNS::Resource::IN::LOC
    puts "#{record.latitude} #{record.longitude}"
  when Resolv::DNS::Resource::IN::MINFO
    puts "#{record.emailbx}@#{record.rmailbx}"
  when Resolv::DNS::Resource::IN::SOA
    puts "#{record.mname} #{record.rname} #{record.serial} #{record.refresh} #{record.retry} #{record.expire} #{record.ttl}"
  when Resolv::DNS::Resource::IN::SRV
    puts "#{record.port} #{record.priority} #{record.weight} #{record.target}"
  when Resolv::DNS::Resource::IN::WKS
    puts "#{record.address} #{record.protocol}"
  end
end

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.

Prints multiple DNS records.

Parameters:

  • records (Array<Resolv::DNS::Resource>)

    The DNS resource records to print.

Since:

  • 2.0.0



99
100
101
102
103
# File 'lib/ronin/cli/dns.rb', line 99

def print_records(records)
  records.each do |record|
    print_record(record)
  end
end

#resolverRonin::Network::DNS::Resolver

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 resolver to use.

Returns:

  • (Ronin::Network::DNS::Resolver)

    The DNS resolver.

Since:

  • 2.0.0



83
84
85
86
87
88
89
90
91
# File 'lib/ronin/cli/dns.rb', line 83

def resolver
  @resolver ||= unless @nameservers.empty?
                  Support::Network::DNS.resolver(
                    nameservers: @nameservers
                  )
                else
                  Support::Network::DNS.resolver
                end
end