Skip to content

Commit

Permalink
Adds protection against incomplete GeoPlugin results, such as 92.123.…
Browse files Browse the repository at this point in the history
…145.37. Fixes nmap#1331
  • Loading branch information
nnposter committed Oct 9, 2018
1 parent 466bf8f commit 74f1b37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#Nmap Changelog ($Id$); -*-text-*-

o [NSE][GH#1331] Script traceroute-geolocation no longer crashes when
www.GeoPlugin.net returns null coordinates [Michal Kubenka, nnposter]

o Limit verbose -v and debugging -d levels to a maximum of 10. Nmap does not
use higher levels internally. [Daniel Miller]

Expand Down
16 changes: 12 additions & 4 deletions scripts/traceroute-geolocation.nse
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,21 @@ local function geoLookup(ip, no_cache)
local response = http.get("www.geoplugin.net", 80, "/json.gp?ip="..ip, {any_af=true})
local stat, loc = json.parse(response.body)

if not stat then return nil end
local regionName = (loc.geoplugin_regionName == json.NULL) and "Unknown" or loc.geoplugin_regionName
local get_value = function (d)
local t = type(d)
return (t == "string" or t == "number") and d or nil
end

if not (stat
and get_value(loc.geoplugin_latitude)
and get_value(loc.geoplugin_longitude)) then
return nil
end
output = {
lat = loc.geoplugin_latitude,
lon = loc.geoplugin_longitude,
reg = regionName,
ctry = loc.geoplugin_countryName
reg = get_value(loc.geoplugin_regionName) or "Unknown",
ctry = get_value(loc.geoplugin_countryName) or "Unknown"
}
if not no_cache then
stdnse.registry_add_table({SCRIPT_NAME}, ip, output)
Expand Down

0 comments on commit 74f1b37

Please sign in to comment.