mirror of
https://github.com/nmap/nmap.git
synced 2025-12-29 10:59:02 +00:00
o [NSE] Added gps library and the gpsd-info script that collects GPS data
from the gpsd daemon. [Patrik Karlsson]
This commit is contained in:
99
scripts/gpsd-info.nse
Normal file
99
scripts/gpsd-info.nse
Normal file
@@ -0,0 +1,99 @@
|
||||
description = [[
|
||||
Retrieves GPS time, coordinates and speed from the GPSD network daemon.
|
||||
]]
|
||||
|
||||
---
|
||||
-- @usage
|
||||
-- nmap -p 2947 <ip> --script gpsd-info
|
||||
--
|
||||
-- @output
|
||||
-- PORT STATE SERVICE REASON
|
||||
-- 2947/tcp open gpsd-ng syn-ack
|
||||
-- | gpsd-info:
|
||||
-- | Time of fix: Sat Apr 14 15:54:23 2012
|
||||
-- | Coordinates: 59.321685,17.886493
|
||||
-- |_ Speed: - knots
|
||||
--
|
||||
|
||||
|
||||
author = "Patrik Karlsson"
|
||||
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
||||
categories = {"discovery", "safe"}
|
||||
|
||||
local shortport = require 'shortport'
|
||||
local gps = require 'gps'
|
||||
local json = require 'json'
|
||||
local match = require 'match'
|
||||
|
||||
portrule = shortport.port_or_service(2947, "gpsd-ng", "tcp")
|
||||
|
||||
local arg_timeout = tonumber(stdnse.get_script_args(SCRIPT_NAME .. ".timeout")) or 10
|
||||
|
||||
local function updateData(gpsinfo, entry)
|
||||
for k, v in pairs(gpsinfo) do
|
||||
if ( entry[k] and 0 < #tostring(entry[k]) ) then
|
||||
gpsinfo[k] = entry[k]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function hasAllData(gpsinfo)
|
||||
for k, v in pairs(gpsinfo) do
|
||||
if ( k ~= "speed" and v == '-' ) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function fail(err) return ("\n ERROR: %s"):format(err or "") end
|
||||
|
||||
action = function(host, port)
|
||||
|
||||
local gpsinfo = {
|
||||
longitude = "-",
|
||||
latitude = "-",
|
||||
speed = "-",
|
||||
time = "-",
|
||||
date = "-",
|
||||
}
|
||||
|
||||
local socket = nmap.new_socket()
|
||||
socket:set_timeout(1000)
|
||||
|
||||
local status = socket:connect(host, port)
|
||||
|
||||
if ( not(status) ) then
|
||||
return fail("Failed to connect to server")
|
||||
end
|
||||
|
||||
-- get the banner
|
||||
local status, line = socket:receive_lines(1)
|
||||
socket:send('?WATCH={"enable":true,"nmea":true}\r\n')
|
||||
|
||||
local start_time = os.time()
|
||||
|
||||
repeat
|
||||
local entry
|
||||
status, line = socket:receive_buf("\r\n")
|
||||
if ( status ) then
|
||||
status, entry = gps.NMEA.parse(line)
|
||||
if ( status ) then
|
||||
updateData(gpsinfo, entry)
|
||||
end
|
||||
end
|
||||
until( os.time() - start_time > arg_timeout or hasAllData(gpsinfo) )
|
||||
|
||||
socket:send('?WATCH={"enable":false}\r\n')
|
||||
|
||||
if ( not(hasAllData(gpsinfo)) ) then
|
||||
return
|
||||
end
|
||||
|
||||
local output = {
|
||||
("Time of fix: %s UTC"):format(os.date("%c", gps.Util.convertTime(gpsinfo.date, gpsinfo.time))),
|
||||
("Coordinates: %.4f,%.4f"):format(tonumber(gpsinfo.latitude), tonumber(gpsinfo.longitude)),
|
||||
("Speed: %s knots"):format(gpsinfo.speed)
|
||||
}
|
||||
return stdnse.format_output(true, output)
|
||||
end
|
||||
@@ -94,6 +94,7 @@ Entry { filename = "ftp-vuln-cve2010-4221.nse", categories = { "intrusive", "vul
|
||||
Entry { filename = "ganglia-info.nse", categories = { "default", "discovery", "safe", } }
|
||||
Entry { filename = "giop-info.nse", categories = { "default", "discovery", "safe", } }
|
||||
Entry { filename = "gopher-ls.nse", categories = { "default", "discovery", "safe", } }
|
||||
Entry { filename = "gpsd-info.nse", categories = { "discovery", "safe", } }
|
||||
Entry { filename = "hadoop-datanode-info.nse", categories = { "default", "discovery", "safe", } }
|
||||
Entry { filename = "hadoop-jobtracker-info.nse", categories = { "default", "discovery", "safe", } }
|
||||
Entry { filename = "hadoop-namenode-info.nse", categories = { "default", "discovery", "safe", } }
|
||||
|
||||
Reference in New Issue
Block a user