diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:42:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:42:04 +0000 |
commit | 0d47952611198ef6b1163f366dc03922d20b1475 (patch) | |
tree | 3d840a3b8c0daef0754707bfb9f5e873b6b1ac13 /scripts/targets-traceroute.nse | |
parent | Initial commit. (diff) | |
download | nmap-0d47952611198ef6b1163f366dc03922d20b1475.tar.xz nmap-0d47952611198ef6b1163f366dc03922d20b1475.zip |
Adding upstream version 7.94+git20230807.3be01efb1+dfsg.upstream/7.94+git20230807.3be01efb1+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | scripts/targets-traceroute.nse | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/scripts/targets-traceroute.nse b/scripts/targets-traceroute.nse new file mode 100644 index 0000000..f4989b0 --- /dev/null +++ b/scripts/targets-traceroute.nse @@ -0,0 +1,64 @@ +local stdnse = require "stdnse" +local string = require "string" +local target = require "target" + +description = [[ +Inserts traceroute hops into the Nmap scanning queue. It only functions if +Nmap's <code>--traceroute</code> option is used and the <code>newtargets</code> +script argument is given. +]] + +--- +-- @args newtargets If specified, adds traceroute hops onto Nmap +-- scanning queue. +-- +-- @usage +-- nmap --script targets-traceroute --script-args newtargets --traceroute target +-- +-- @output +-- Host script results: +-- |_traceroute-scan-hops: successfully added 5 new targets. + + +-- 09/02/2010 +author = "Henri Doreau" + +license = "Same as Nmap--See https://nmap.org/book/man-legal.html" + +categories = {"safe", "discovery"} + + +hostrule = function(host) + -- print debug messages because the script relies on + -- script arguments and traceroute results. + if not target.ALLOW_NEW_TARGETS then + stdnse.debug3("Skipping %s script, 'newtargets' script argument is missing.", SCRIPT_NAME) + return false + end + if not host.traceroute then + stdnse.debug3("Skipping %s script because traceroute results are missing.", SCRIPT_NAME) + return false + end + return true +end + +action = function(host) + local ntargets = 0 + for _, hop in ipairs(host.traceroute) do + -- avoid timedout hops, marked as empty entries + -- do not add the current scanned host.ip + if hop.ip and host.ip ~= hop.ip then + local status, ret = target.add(hop.ip) + if status then + ntargets = ntargets + ret + stdnse.debug3("TRACEROUTE Scan Hops: Added new target "..host.ip.." from traceroute results") + else + stdnse.debug3("TRACEROUTE Scan Hops: " .. ret) + end + end + end + + if ntargets > 0 then + return string.format("successfully added %d new targets.\n", ntargets) + end +end |