From c4b0b63e9028e7fd36b9472defc50d004932055d Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 25 Mar 2024 11:44:33 +1000 Subject: [PATCH] move dns banner output into to banners.rb - still had a bug --- core/main/console/banners.rb | 16 +++++++++++++++- extensions/dns/api.rb | 22 +++++++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/core/main/console/banners.rb b/core/main/console/banners.rb index cbbae5663..d4d703928 100644 --- a/core/main/console/banners.rb +++ b/core/main/console/banners.rb @@ -135,7 +135,6 @@ module BeEF end end - # # Print WebSocket servers # def print_http_proxy @@ -143,6 +142,21 @@ module BeEF print_info "HTTP Proxy: http://#{config.get('beef.extension.proxy.address')}:#{config.get('beef.extension.proxy.port')}" end + def print_dns + address = nil + port = nil + protocol = nil + + # TODO: fix the following reference - extensions/dns/api.rb + # servers, interfaces, address, port, protocol, upstream_servers = get_dns_config # get the DNS configuration + + # Print the DNS server information + unless address.nil? || port.nil? || protocol.nil? + print_info "DNS Server: #{address}:#{port} (#{protocol})" + print_more upstream_servers unless upstream_servers.empty? + end + end + end end end diff --git a/extensions/dns/api.rb b/extensions/dns/api.rb index 9722a416e..f34de49c8 100644 --- a/extensions/dns/api.rb +++ b/extensions/dns/api.rb @@ -24,8 +24,23 @@ module BeEF # # @param http_hook_server [BeEF::Core::Server] HTTP server instance def self.pre_http_start(_http_hook_server) - dns_config = BeEF::Core::Configuration.instance.get('beef.extension.dns') + servers, interfaces, address, port, protocol, upstream_servers = get_dns_config # get the DNS configuration + + # Start the DNS server dns = BeEF::Extension::Dns::Server.instance + dns.run(upstream: servers, listen: interfaces) + end + + def self.print_dns_info + servers, interfaces, address, port, protocol, upstream_servers = get_dns_config # get the DNS configuration + + # Print the DNS server information + print_info "DNS Server: #{address}:#{port} (#{protocol})" + print_more upstream_servers unless upstream_servers.empty? + end + + def self.get_dns_config + dns_config = BeEF::Core::Configuration.instance.get('beef.extension.dns') protocol = begin dns_config['protocol'].to_sym @@ -52,10 +67,7 @@ module BeEF end end - dns.run(upstream: servers, listen: interfaces) - - print_info "DNS Server: #{address}:#{port} (#{protocol})" - print_more upstream_servers unless upstream_servers.empty? + return servers, interfaces, address, port, protocol, upstream_servers end # Mounts the handler for processing DNS RESTful API requests.