diff --git a/scripts/broadcast-dhcp-discover.nse b/scripts/broadcast-dhcp-discover.nse index 826a571e4..a273525bc 100644 --- a/scripts/broadcast-dhcp-discover.nse +++ b/scripts/broadcast-dhcp-discover.nse @@ -37,11 +37,24 @@ author = "Patrik Karlsson" license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"broadcast", "safe"} -prerule = function() return not( nmap.address_family() == "inet6") end require 'dhcp' require 'ipOps' require 'packet' +require 'nmap' + +prerule = function() + if not nmap.is_privileged() then + stdnse.print_verbose("%s not running for lack of privileges.", SCRIPT_NAME) + return false + end + + if nmap.address_family() ~= 'inet' then + stdnse.print_debug("%s is IPv4 compatible only.", SCRIPT_NAME) + return false + end + return true +end -- Creates a random MAC address -- @@ -116,10 +129,6 @@ end action = function() - if not nmap.is_privileged() then - return ("\n ERROR: %s needs to be run as a privileged user (root)."):format(SCRIPT_NAME) - end - local host, port = "255.255.255.255", 67 local timeout = stdnse.get_script_args("broadcast-dhcp-discover.timeout") timeout = tonumber(timeout) or 10 diff --git a/scripts/broadcast-listener.nse b/scripts/broadcast-listener.nse index bf3c20758..27286dcf6 100644 --- a/scripts/broadcast-listener.nse +++ b/scripts/broadcast-listener.nse @@ -74,10 +74,19 @@ author = "Patrik Karlsson" license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"broadcast", "safe"} -prerule = function() return true end require('packet') require('tab') +require('nmap') + + +prerule = function() + if not nmap.is_privileged() then + stdnse.print_verbose("%s not running for lack of privileges.", SCRIPT_NAME) + return false + end + return true +end --- -- loads the decoders from file diff --git a/scripts/broadcast-pppoe-discover.nse b/scripts/broadcast-pppoe-discover.nse index 2c4164871..eb105a1d3 100644 --- a/scripts/broadcast-pppoe-discover.nse +++ b/scripts/broadcast-pppoe-discover.nse @@ -28,8 +28,15 @@ license = "Same as Nmap--See http://nmap.org/book/man-legal.html" categories = {"broadcast", "safe"} require 'pppoe' +require 'nmap' -prerule = function() return true end +prerule = function() + if not nmap.is_privileged() then + stdnse.print_verbose("%s not running for lack of privileges.", SCRIPT_NAME) + return false + end + return true +end local function fail(err) if ( err ) then