Skip to content

Commit

Permalink
Mark dnsruby as a requirement and remove Net::DNS
Browse files Browse the repository at this point in the history
Remove ::Net::DNS because it can be replaced by Dnsruby instead since we
just need the constants. Use Dnsruby because it's a public gem whereas
::Net::DNS is currently a vendored hack used by Metasploit.

One DNS library to rule them all.
  • Loading branch information
zeroSteiner committed Nov 19, 2024
1 parent 60103db commit 36ee279
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/rex/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'thread'
require 'resolv'
require 'rex/exceptions'
require 'dnsruby'

module Rex

Expand Down Expand Up @@ -974,21 +975,21 @@ def self.rex_resolve_hostname(name, resolver: @@resolver)
) unless name.is_a?(String)
# Pull both record types
v4 = begin
resolver.send(name, ::Net::DNS::A).answer.select do |a|
resolver.send(name, ::Dnsruby::Types::A).answer.select do |a|
a.type == Dnsruby::Types::A
end.sort_by do |a|
self.addr_ntoi(a.address.address)
end
rescue
rescue StandardError
[]
end
v6 = begin
resolver.send(name, ::Net::DNS::AAAA).answer.select do |a|
resolver.send(name, Dnsruby::Types::AAAA).answer.select do |a|
a.type == Dnsruby::Types::AAAA
end.sort_by do |a|
self.addr_ntoi(a.address.address)
end
rescue
rescue StandardError
[]
end
# Emulate ::Socket's error if no responses found
Expand All @@ -1012,7 +1013,7 @@ def self.rex_getresources(name, typeclass, resolver: @@resolver)
if attribute.nil?
raise ArgumentError, "Invalid typeclass: #{typeclass}"
end
const = ::Net::DNS.const_get(typeclass)
const = Dnsruby::Types.const_get(typeclass)

resources = begin
resolver.send(name, const).answer.select do |a|
Expand Down
1 change: 1 addition & 0 deletions rex-socket.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec"

spec.add_runtime_dependency "rex-core"
spec.add_runtmie_dependency "dnsruby"
end

0 comments on commit 36ee279

Please sign in to comment.