Skip to content

Commit

Permalink
updated dns extension to use async-dns instead of old rubydns
Browse files Browse the repository at this point in the history
  • Loading branch information
h4sh5 committed Jan 9, 2020
1 parent 39ef3fe commit f5de5eb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end

# DNS extension
group :ext_dns do
gem 'rubydns', '~> 0.7.3'
gem 'async-dns'
end

# QRcode extension
Expand Down
34 changes: 21 additions & 13 deletions extensions/dns/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Dns
# using a rule-based system. A list of user-defined rules is used to match against incoming
# DNS requests. These rules generate a response that is either a resource record or a
# failure code.
class Server < RubyDNS::Server
class Server < Async::DNS::Server

include Singleton

Expand Down Expand Up @@ -127,26 +127,31 @@ def run(options = {})
Thread.new do
EventMachine.next_tick do
upstream = options[:upstream] || nil

listen = options[:listen] || nil
# listen is called enpoints in Async::DNS
@endpoints = listen

if upstream
resolver = RubyDNS::Resolver.new(upstream)
resolver = Async::DNS::Resolver.new(upstream)
@otherwise = Proc.new { |t| t.passthrough!(resolver) }
end

begin
super(:listen => listen)
rescue RuntimeError => e
if e.message =~ /no datagram socket/ || e.message =~ /no acceptor/ # the port is in use
print_error "[DNS] Another process is already listening on port #{options[:listen]}"
print_error "Exiting..."
exit 127
else
raise
# super(:listen => listen)
Thread.new { super() }
rescue RuntimeError => e
if e.message =~ /no datagram socket/ || e.message =~ /no acceptor/ # the port is in use
print_error "[DNS] Another process is already listening on port #{options[:listen]}"
print_error "Exiting..."
exit 127
else
raise
end
end
end

end

end
end
end
end
Expand All @@ -159,7 +164,10 @@ def run(options = {})
# @param transaction [RubyDNS::Transaction] internal RubyDNS class detailing DNS question/answer
def process(name, resource, transaction)
@lock.synchronize do
print_debug "Received DNS request (name: #{name} type: #{format_resource(resource)})"

resource = resource.to_s

print_debug "Received DNS request (name: #{name} type: #{format_resource(resource)})"

# no need to parse AAAA resources when data is extruded from client. Also we check if the FQDN starts with the 0xb3 string.
# this 0xb3 is convenient to clearly separate DNS requests used to extrude data from normal DNS requests than should be resolved by the DNS server.
Expand Down
3 changes: 2 additions & 1 deletion extensions/dns/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Browser Exploitation Framework (BeEF) - http://beefproject.com
# See the file 'doc/COPYING' for copying permission
#
require 'rubydns'
require 'async/dns'


module BeEF
module Extension
Expand Down

0 comments on commit f5de5eb

Please sign in to comment.