From fdd1048f1a5db7e97891a74e57bdbcad4e9244c4 Mon Sep 17 00:00:00 2001 From: soh_cah_toa Date: Fri, 3 May 2013 22:37:42 -0400 Subject: [PATCH] Implemented basic nameserver and configured it to run on BeEF startup. It's worth noting that RubyDNS currently displays a lot of messy output. This needs to be addressed before moving any further. --- extensions/dns/api.rb | 33 +++++++++++++++++++++++++++++++++ extensions/dns/dns.rb | 33 +++++++++++++++++++++++++++++++++ extensions/dns/extension.rb | 3 +++ 3 files changed, 69 insertions(+) create mode 100644 extensions/dns/api.rb create mode 100644 extensions/dns/dns.rb diff --git a/extensions/dns/api.rb b/extensions/dns/api.rb new file mode 100644 index 000000000..a5c838040 --- /dev/null +++ b/extensions/dns/api.rb @@ -0,0 +1,33 @@ +# +# Copyright (c) 2006-2013 Wade Alcorn - wade@bindshell.net +# Browser Exploitation Framework (BeEF) - http://beefproject.com +# See the file 'doc/COPYING' for copying permission +# +module BeEF +module Extension +module DNS +module API + + module NameserverHandler + + BeEF::API::Registrar.instance.register(BeEF::Extension::DNS::API::NameserverHandler, + BeEF::API::Server, + 'pre_http_start') + + def self.pre_http_start(http_hook_server) + config = BeEF::Core::Configuration.instance + + address = config.get('beef.extension.dns.address') + port = config.get('beef.extension.dns.port') + + Thread.new { BeEF::Extension::DNS::DNS.new(address, port) } + + print_info "DNS server: #{address}:#{port}" + end + + end + +end +end +end +end diff --git a/extensions/dns/dns.rb b/extensions/dns/dns.rb new file mode 100644 index 000000000..d07a19a02 --- /dev/null +++ b/extensions/dns/dns.rb @@ -0,0 +1,33 @@ +# +# Copyright (c) 2006-2013 Wade Alcorn - wade@bindshell.net +# Browser Exploitation Framework (BeEF) - http://beefproject.com +# See the file 'doc/COPYING' for copying permission +# +module BeEF +module Extension +module DNS + + class DNS + + UPSTREAM = RubyDNS::Resolver.new([[:udp, '8.8.8.8', 53], [:tcp, '8.8.8.8', 53]]) + + def initialize(address, port) + @address = address + @port = port + + run_server + end + + def run_server + RubyDNS::run_server(:listen => [[:udp, @address, @port]]) do + otherwise do |transaction| + transaction.passthrough!(UPSTREAM) + end + end + end + + end + +end +end +end diff --git a/extensions/dns/extension.rb b/extensions/dns/extension.rb index fc0e5d0e8..04a655c4a 100644 --- a/extensions/dns/extension.rb +++ b/extensions/dns/extension.rb @@ -17,3 +17,6 @@ module DNS end end end + +require 'extensions/dns/api' +require 'extensions/dns/dns'