Module: Ronin::Recon::Mixins::DNS
- Included in:
- DNSWorker
- Defined in:
- lib/ronin/recon/mixins/dns.rb
Overview
Mixin which adds methods for performing async DNS queries.
Constant Summary collapse
- IDN =
Handles International Domain Names (IDN).
Support::Network::DNS::IDN
- 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 record types to
Resolv::DNS::Resource::IN
classes. { a: Resolv::DNS::Resource::IN::A, aaaa: Resolv::DNS::Resource::IN::AAAA, any: Resolv::DNS::Resource::IN::ANY, cname: Resolv::DNS::Resource::IN::CNAME, hinfo: Resolv::DNS::Resource::IN::HINFO, loc: Resolv::DNS::Resource::IN::LOC, minfo: Resolv::DNS::Resource::IN::MINFO, mx: Resolv::DNS::Resource::IN::MX, ns: Resolv::DNS::Resource::IN::NS, ptr: Resolv::DNS::Resource::IN::PTR, soa: Resolv::DNS::Resource::IN::SOA, srv: Resolv::DNS::Resource::IN::SRV, txt: Resolv::DNS::Resource::IN::TXT, wks: Resolv::DNS::Resource::IN::WKS }
Instance Attribute Summary collapse
- #dns_resolver ⇒ Async::DNS::Resolver readonly
Instance Method Summary collapse
-
#dns_get_a_address(name) ⇒ String?
Queries the first IPv4 address belonging to the host name.
-
#dns_get_a_addresses(name) ⇒ Array<String>
Queries all IPv4 addresses belonging to the host name.
-
#dns_get_a_record(name) ⇒ Resolv::DNS::Resource::IN::A?
Queries the first
A
record belonging to the host name. -
#dns_get_a_records(name) ⇒ Array<Resolv::DNS::Resource::IN::A>
Queries all
A
records belonging to the host name. -
#dns_get_aaaa_address(name) ⇒ String?
Queries the first IPv6 address belonging to the host name.
-
#dns_get_aaaa_addresses(name) ⇒ Array<String>
Queries all IPv6 addresses belonging to the host name.
-
#dns_get_aaaa_record(name) ⇒ Resolv::DNS::Resource::IN::AAAA?
Queries the first
AAAA
DNS records belonging to the host name. -
#dns_get_aaaa_records(name) ⇒ Array<Resolv::DNS::Resource::IN::AAAA>
Queries all
AAAA
DNS records belonging to the host name. -
#dns_get_address(host) ⇒ String?
Looks up the address of a hostname.
-
#dns_get_addresses(host) ⇒ Array<String>
Looks up all addresses of a hostname.
-
#dns_get_any_records(name) ⇒ Array<Resolv::DNS::Resource>
Queries all records of the host name using the
ANY
DNS query. -
#dns_get_cname(name) ⇒ String?
Queries the canonical name for the host name.
-
#dns_get_cname_record(name) ⇒ Resolv::DNS::Resource::IN::CNAME?
Queries the
CNAME
record for the host name. -
#dns_get_hinfo_record(name) ⇒ Resolv::DNS::Resource::IN::HINFO?
Queries the
HINFO
record for the host name. -
#dns_get_loc_record(name) ⇒ Resolv::DNS::Resource::LOC?
Queries the
LOC
(Location) DNS record of the host name. -
#dns_get_mailservers(name) ⇒ Array<String>
Queries the mailservers for the host name.
-
#dns_get_minfo_record(name) ⇒ Resolv::DNS::Resource::MINFO?
Queries the
MINFO
(Machine-Info) DNS record of the host name. -
#dns_get_mx_records(name) ⇒ Array<Resolv::DNS::Resource::MX>
Queries all
MX
DNS records belonging to the host name. -
#dns_get_name(ip) ⇒ String?
(also: #dns_reverse_lookup)
Looks up the hostname of the address.
-
#dns_get_names(ip) ⇒ Array<String>
Looks up all hostnames associated with the address.
-
#dns_get_nameservers(name) ⇒ Array<String>
Queries the nameservers for the host name.
-
#dns_get_ns_records(name) ⇒ Array<Resolv::DNS::Resource::NS>
Queries all
NS
DNS records belonging to the host name. -
#dns_get_ptr_name(ip) ⇒ String?
Queries the
PTR
host name for the IP address. -
#dns_get_ptr_names(ip) ⇒ Array<String>
Queries all
PTR
names for the IP address. -
#dns_get_ptr_record(ip) ⇒ Resolv::DNS::Resource::PTR?
Queries the first
PTR
DNS record for the IP address. -
#dns_get_ptr_records(ip) ⇒ Array<Resolv::DNS::Resource::PTR>
Queries all
PTR
DNS records for the IP address. -
#dns_get_record(name, record_type) ⇒ Resolv::DNS::Resource?
Queries a single matching DNS record for the host name.
-
#dns_get_records(name, record_type) ⇒ Array<Resolv::DNS::Resource>
Queries all matching DNS records for the host name.
-
#dns_get_soa_record(name) ⇒ Resolv::DNS::Resource::SOA?
Queries the first
SOA
DNS record belonging to the host name. -
#dns_get_srv_records(name) ⇒ Array<Resolv::DNS::Resource::IN::SRV>
Queries all
SRV
DNS records belonging to the host name. -
#dns_get_txt_record(name) ⇒ Resolv::DNS::Resource::TXT?
Queiries the first
TXT
DNS record belonging to the host name. -
#dns_get_txt_records(name) ⇒ Array<Resolv::DNS::Resource::TXT>
Queries all
TXT
DNS records belonging to the host name. -
#dns_get_txt_string(name) ⇒ String?
Queries the first
TXT
string belonging to the host name. -
#dns_get_txt_strings(name) ⇒ Array<String>
Queries all of the
TXT
string values of the host name. -
#dns_get_wks_records(name) ⇒ Array<Resolv::DNS::Resource::IN::WKS>
Queries all
WKS
(Well-Known-Service) DNS records belonging to the host name. -
#initialize(nameservers: Support::Network::DNS.nameservers, **kwargs) ⇒ Object
Initializes the DNS resolver.
Instance Attribute Details
#dns_resolver ⇒ Async::DNS::Resolver (readonly)
41 42 43 |
# File 'lib/ronin/recon/mixins/dns.rb', line 41 def dns_resolver @dns_resolver end |
Instance Method Details
#dns_get_a_address(name) ⇒ String?
Queries the first IPv4 address belonging to the host name.
275 276 277 278 279 |
# File 'lib/ronin/recon/mixins/dns.rb', line 275 def dns_get_a_address(name) if (record = dns_get_a_record(name)) record.address.to_s end end |
#dns_get_a_addresses(name) ⇒ Array<String>
Queries all IPv4 addresses belonging to the host name.
305 306 307 308 309 |
# File 'lib/ronin/recon/mixins/dns.rb', line 305 def dns_get_a_addresses(name) dns_get_a_records(name).map do |record| record.address.to_s end end |
#dns_get_a_record(name) ⇒ Resolv::DNS::Resource::IN::A?
Queries the first A
record belonging to the host name.
262 263 264 |
# File 'lib/ronin/recon/mixins/dns.rb', line 262 def dns_get_a_record(name) dns_get_record(name,:a) end |
#dns_get_a_records(name) ⇒ Array<Resolv::DNS::Resource::IN::A>
Queries all A
records belonging to the host name.
292 293 294 |
# File 'lib/ronin/recon/mixins/dns.rb', line 292 def dns_get_a_records(name) dns_get_records(name,:a) end |
#dns_get_aaaa_address(name) ⇒ String?
Queries the first IPv6 address belonging to the host name.
337 338 339 340 341 |
# File 'lib/ronin/recon/mixins/dns.rb', line 337 def dns_get_aaaa_address(name) if (record = dns_get_aaaa_record(name)) record.address.to_s end end |
#dns_get_aaaa_addresses(name) ⇒ Array<String>
Queries all IPv6 addresses belonging to the host name.
367 368 369 370 371 |
# File 'lib/ronin/recon/mixins/dns.rb', line 367 def dns_get_aaaa_addresses(name) dns_get_aaaa_records(name).map do |record| record.address.to_s end end |
#dns_get_aaaa_record(name) ⇒ Resolv::DNS::Resource::IN::AAAA?
Queries the first AAAA
DNS records belonging to the host name.
323 324 325 |
# File 'lib/ronin/recon/mixins/dns.rb', line 323 def dns_get_aaaa_record(name) dns_get_record(name,:aaaa) end |
#dns_get_aaaa_records(name) ⇒ Array<Resolv::DNS::Resource::IN::AAAA>
Queries all AAAA
DNS records belonging to the host name.
354 355 356 |
# File 'lib/ronin/recon/mixins/dns.rb', line 354 def dns_get_aaaa_records(name) dns_get_records(name,:aaaa) end |
#dns_get_address(host) ⇒ String?
Looks up the address of a hostname.
88 89 90 |
# File 'lib/ronin/recon/mixins/dns.rb', line 88 def dns_get_address(host) dns_get_addresses(host).first end |
#dns_get_addresses(host) ⇒ Array<String>
Looks up all addresses of a hostname.
69 70 71 72 73 74 75 76 77 |
# File 'lib/ronin/recon/mixins/dns.rb', line 69 def dns_get_addresses(host) host = IDN.to_ascii(host) begin @dns_resolver.addresses_for(host).map(&:to_s) rescue Async::DNS::ResolutionFailure return [] end end |
#dns_get_any_records(name) ⇒ Array<Resolv::DNS::Resource>
Queries all records of the host name using the ANY
DNS query.
198 199 200 |
# File 'lib/ronin/recon/mixins/dns.rb', line 198 def dns_get_any_records(name) dns_get_records(name,:any) end |
#dns_get_cname(name) ⇒ String?
Queries the canonical name for the host name.
228 229 230 231 232 |
# File 'lib/ronin/recon/mixins/dns.rb', line 228 def dns_get_cname(name) if (record = dns_get_cname_record(name)) record.name.to_s end end |
#dns_get_cname_record(name) ⇒ Resolv::DNS::Resource::IN::CNAME?
Queries the CNAME
record for the host name.
214 215 216 |
# File 'lib/ronin/recon/mixins/dns.rb', line 214 def dns_get_cname_record(name) dns_get_record(name,:cname) end |
#dns_get_hinfo_record(name) ⇒ Resolv::DNS::Resource::IN::HINFO?
Queries the HINFO
record for the host name.
246 247 248 |
# File 'lib/ronin/recon/mixins/dns.rb', line 246 def dns_get_hinfo_record(name) dns_get_record(name,:hinfo) end |
#dns_get_loc_record(name) ⇒ Resolv::DNS::Resource::LOC?
Queries the LOC
(Location) DNS record of the host name.
416 417 418 |
# File 'lib/ronin/recon/mixins/dns.rb', line 416 def dns_get_loc_record(name) dns_get_record(name,:loc) end |
#dns_get_mailservers(name) ⇒ Array<String>
Queries the mailservers for the host name.
460 461 462 463 464 |
# File 'lib/ronin/recon/mixins/dns.rb', line 460 def dns_get_mailservers(name) dns_get_mx_records(name).map do |record| record.exchange.to_s end end |
#dns_get_minfo_record(name) ⇒ Resolv::DNS::Resource::MINFO?
Queries the MINFO
(Machine-Info) DNS record of the host name.
432 433 434 |
# File 'lib/ronin/recon/mixins/dns.rb', line 432 def dns_get_minfo_record(name) dns_get_record(name,:minfo) end |
#dns_get_mx_records(name) ⇒ Array<Resolv::DNS::Resource::MX>
Queries all MX
DNS records belonging to the host name.
447 448 449 |
# File 'lib/ronin/recon/mixins/dns.rb', line 447 def dns_get_mx_records(name) dns_get_records(name,:mx) end |
#dns_get_name(ip) ⇒ String? Also known as: dns_reverse_lookup
Looks up the hostname of the address.
114 115 116 |
# File 'lib/ronin/recon/mixins/dns.rb', line 114 def dns_get_name(ip) dns_get_names(ip).first end |
#dns_get_names(ip) ⇒ Array<String>
Looks up all hostnames associated with the address.
101 102 103 |
# File 'lib/ronin/recon/mixins/dns.rb', line 101 def dns_get_names(ip) dns_get_ptr_names(ip) end |
#dns_get_nameservers(name) ⇒ Array<String>
Queries the nameservers for the host name.
490 491 492 493 494 |
# File 'lib/ronin/recon/mixins/dns.rb', line 490 def dns_get_nameservers(name) dns_get_ns_records(name).map do |record| record.name.to_s end end |
#dns_get_ns_records(name) ⇒ Array<Resolv::DNS::Resource::NS>
Queries all NS
DNS records belonging to the host name.
477 478 479 |
# File 'lib/ronin/recon/mixins/dns.rb', line 477 def dns_get_ns_records(name) dns_get_records(name,:ns) end |
#dns_get_ptr_name(ip) ⇒ String?
Queries the PTR
host name for the IP address.
521 522 523 524 525 |
# File 'lib/ronin/recon/mixins/dns.rb', line 521 def dns_get_ptr_name(ip) if (record = dns_get_ptr_record(ip)) record.name.to_s end end |
#dns_get_ptr_names(ip) ⇒ Array<String>
Queries all PTR
names for the IP address.
553 554 555 556 557 |
# File 'lib/ronin/recon/mixins/dns.rb', line 553 def dns_get_ptr_names(ip) dns_get_ptr_records(ip).map do |record| record.name.to_s end end |
#dns_get_ptr_record(ip) ⇒ Resolv::DNS::Resource::PTR?
Queries the first PTR
DNS record for the IP address.
508 509 510 |
# File 'lib/ronin/recon/mixins/dns.rb', line 508 def dns_get_ptr_record(ip) dns_get_record(ip,:ptr) end |
#dns_get_ptr_records(ip) ⇒ Array<Resolv::DNS::Resource::PTR>
Queries all PTR
DNS records for the IP address.
538 539 540 541 542 |
# File 'lib/ronin/recon/mixins/dns.rb', line 538 def dns_get_ptr_records(ip) in_addr = IPAddr.new(ip).reverse dns_get_records(in_addr,:ptr) end |
#dns_get_record(name, record_type) ⇒ Resolv::DNS::Resource?
Queries a single matching DNS record for the host name.
183 184 185 |
# File 'lib/ronin/recon/mixins/dns.rb', line 183 def dns_get_record(name,record_type) dns_get_records(name,record_type).first end |
#dns_get_records(name, record_type) ⇒ Array<Resolv::DNS::Resource>
Queries all matching DNS records for the host name.
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ronin/recon/mixins/dns.rb', line 154 def dns_get_records(name,record_type) name = IDN.to_ascii(name) record_class = RECORD_TYPES.fetch(record_type) do raise(ArgumentError,"invalid record type: #{record_type.inspect}") end if ( = @dns_resolver.query(name,record_class)) .answer.map { |answer| answer[2] } else [] end end |
#dns_get_soa_record(name) ⇒ Resolv::DNS::Resource::SOA?
Queries the first SOA
DNS record belonging to the host name.
571 572 573 |
# File 'lib/ronin/recon/mixins/dns.rb', line 571 def dns_get_soa_record(name) dns_get_record(name,:soa) end |
#dns_get_srv_records(name) ⇒ Array<Resolv::DNS::Resource::IN::SRV>
Queries all SRV
DNS records belonging to the host name.
384 385 386 |
# File 'lib/ronin/recon/mixins/dns.rb', line 384 def dns_get_srv_records(name) dns_get_records(name,:srv) end |
#dns_get_txt_record(name) ⇒ Resolv::DNS::Resource::TXT?
Queiries the first TXT
DNS record belonging to the host name.
587 588 589 |
# File 'lib/ronin/recon/mixins/dns.rb', line 587 def dns_get_txt_record(name) dns_get_record(name,:txt) end |
#dns_get_txt_records(name) ⇒ Array<Resolv::DNS::Resource::TXT>
Queries all TXT
DNS records belonging to the host name.
618 619 620 |
# File 'lib/ronin/recon/mixins/dns.rb', line 618 def dns_get_txt_records(name) dns_get_records(name,:txt) end |
#dns_get_txt_string(name) ⇒ String?
Queries the first TXT
string belonging to the host name.
601 602 603 604 605 |
# File 'lib/ronin/recon/mixins/dns.rb', line 601 def dns_get_txt_string(name) if (record = dns_get_txt_record(name)) record.strings.join end end |
#dns_get_txt_strings(name) ⇒ Array<String>
Queries all of the TXT
string values of the host name.
631 632 633 634 635 |
# File 'lib/ronin/recon/mixins/dns.rb', line 631 def dns_get_txt_strings(name) dns_get_txt_records(name).map do |record| record.strings.join end end |
#dns_get_wks_records(name) ⇒ Array<Resolv::DNS::Resource::IN::WKS>
Queries all WKS
(Well-Known-Service) DNS records belonging to the
host name.
400 401 402 |
# File 'lib/ronin/recon/mixins/dns.rb', line 400 def dns_get_wks_records(name) dns_get_records(name,:wks) end |
#initialize(nameservers: Support::Network::DNS.nameservers, **kwargs) ⇒ Object
Initializes the DNS resolver.
52 53 54 55 56 57 58 |
# File 'lib/ronin/recon/mixins/dns.rb', line 52 def initialize(nameservers: Support::Network::DNS.nameservers, **kwargs) super(**kwargs) @dns_resolver = Async::DNS::Resolver.new( nameservers.map { |ip| [:udp, ip, 53] } ) end |