From 0d47952611198ef6b1163f366dc03922d20b1475 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:42:04 +0200 Subject: Adding upstream version 7.94+git20230807.3be01efb1+dfsg. Signed-off-by: Daniel Baumann --- scripts/ip-geolocation-map-kml.nse | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 scripts/ip-geolocation-map-kml.nse (limited to 'scripts/ip-geolocation-map-kml.nse') diff --git a/scripts/ip-geolocation-map-kml.nse b/scripts/ip-geolocation-map-kml.nse new file mode 100644 index 0000000..bd18a38 --- /dev/null +++ b/scripts/ip-geolocation-map-kml.nse @@ -0,0 +1,90 @@ +local geoip = require "geoip" +local io = require "io" +local oops = require "oops" +local stdnse = require "stdnse" +local table = require "table" + +description = [[ +This script queries the Nmap registry for the GPS coordinates of targets stored +by previous geolocation scripts and produces a KML file of points representing +the targets. +]] + +--- +-- @usage +-- nmap -sn -Pn --script ip-geolocation-geoplugin,ip-geolocation-map-kml --script-args ip-geolocation-map-kml.map_path=map.kml +-- +-- @output +-- | ip-geolocation-map-kml: +-- |_ The map has been saved at 'map.kml'. +-- +-- @args ip-geolocation-map-kml.map_path (REQUIRED) +-- +-- @see ip-geolocation-geoplugin.nse +-- @see ip-geolocation-ipinfodb.nse +-- @see ip-geolocation-map-bing.nse +-- @see ip-geolocation-map-google.nse +-- @see ip-geolocation-maxmind.nse + +author = "Mak Kolybabi " +license = "Same as Nmap--See https://nmap.org/book/man-legal.html" +categories = {"safe"} + +local render = function(path) + local kml = {'\n\n '} + + for ip, coords in pairs(geoip.get_all_by_ip()) do + table.insert(kml, ([[ + + %s + + %s,%s + + ]]):format(ip, coords["longitude"], coords["latitude"]) + ) + end + + table.insert(kml, ' \n\n') + + kml = table.concat(kml, "\n") + + local f = io.open(path, "w") + if not f then + return false, ("Failed to open file '%s'."):format(path) + end + + if not f:write(kml) then + return false, ("Failed to write file '%s'."):format(path) + end + + f:close() + + return true, ("The map has been saved at '%s'."):format(path) +end + +local parse_args = function() + local map_path = stdnse.get_script_args(SCRIPT_NAME .. '.map_path') + if not map_path then + return false, "Need to specify a path for the map." + end + + return true, map_path +end + +postrule = function() + -- Only run if a previous script has registered geolocation data. + return not geoip.empty() +end + +action = function() + -- Parse and sanity check the command line arguments. + local status, path = oops.raise( + "Script argument problem", + parse_args()) + if not status then + return path + end + + -- Render the map. + return oops.output(render(path)) +end -- cgit v1.2.3