From abdd89eaccf093870cf045f3dacfc0bdd62470c3 Mon Sep 17 00:00:00 2001 From: Stephen Date: Fri, 22 Mar 2024 10:32:31 +1000 Subject: [PATCH] stop multiple dns servers from starting and add a stop function --- extensions/dns/dns.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/extensions/dns/dns.rb b/extensions/dns/dns.rb index c25574028..7a9cabbeb 100644 --- a/extensions/dns/dns.rb +++ b/extensions/dns/dns.rb @@ -118,6 +118,7 @@ module BeEF @lock.synchronize do Thread.new do EventMachine.next_tick do + next if @server_started # Check if the server was already started upstream = options[:upstream] || nil listen = options[:listen] || nil @@ -132,6 +133,7 @@ module BeEF begin # super(:listen => listen) Thread.new { super() } + @server_started = true # Set the server started flag 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]}" @@ -146,6 +148,14 @@ module BeEF end end + def stop + return unless @server_started # Check if the server was started + + # Logic to stop the Async::DNS server + puts EventMachine.stop if EventMachine.reactor_running? + @server_started = false # Reset the server started flag + end + # Entry point for processing incoming DNS requests. Attempts to find a matching rule and # sends back its associated response. #