1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 20:51:30 +00:00

snmp-interfaces patch for interaction with mac-geolocation through nmap.registry[host.ip][mac-geolocation]

This commit is contained in:
gorjan
2011-05-31 00:13:12 +00:00
parent 95a1cb52de
commit c53b07e451

View File

@@ -35,6 +35,8 @@ dependencies = {"snmp-brute"}
-- Revised 03/05/2010 - v0.2 - Reworked output slighty, moved iana_types to script scope. Suggested by David Fifield -- Revised 03/05/2010 - v0.2 - Reworked output slighty, moved iana_types to script scope. Suggested by David Fifield
-- Revised 04/11/2010 - v0.2 - moved snmp_walk to snmp library <patrik@cqure.net> -- Revised 04/11/2010 - v0.2 - moved snmp_walk to snmp library <patrik@cqure.net>
-- Revised 08/10/2010 - v0.3 - prerule; add interface addresses to Nmap's target list (Kris Katterjohn) -- Revised 08/10/2010 - v0.3 - prerule; add interface addresses to Nmap's target list (Kris Katterjohn)
-- Revised 05/27/2011 - v0.4 - action; add MAC addresses to nmap.registry[host.ip]["mac-geolocation"] (Gorjan Petrovski)
require "stdnse" require "stdnse"
require "shortport" require "shortport"
@@ -42,6 +44,7 @@ require "snmp"
require "datafiles" require "datafiles"
require "target" require "target"
prerule = function() prerule = function()
if not stdnse.get_script_args({"snmp-interfaces.host", "host"}) then if not stdnse.get_script_args({"snmp-interfaces.host", "host"}) then
stdnse.print_debug(3, stdnse.print_debug(3,
@@ -399,6 +402,14 @@ action = function(host, port)
local status local status
local srvhost, srvport local srvhost, srvport
-- table for mac-geolocation.nse
if not nmap.registry[host.ip] then
nmap.registry[host.ip] = {}
end
if not nmap.registry[host.ip]["mac-geolocation"] then
nmap.registry[host.ip]["mac-geolocation"] = {}
end
if SCRIPT_TYPE == "prerule" then if SCRIPT_TYPE == "prerule" then
srvhost = stdnse.get_script_args({"snmp-interfaces.host", "host"}) srvhost = stdnse.get_script_args({"snmp-interfaces.host", "host"})
if not srvhost then if not srvhost then
@@ -444,6 +455,14 @@ action = function(host, port)
local output = stdnse.format_output( true, build_results(interfaces) ) local output = stdnse.format_output( true, build_results(interfaces) )
-- insert the MAC addresses into the mac-geolocation table
for _,item in ipairs(interfaces) do
if item.phys_addr then
table.insert(nmap.registry[host.ip]["mac-geolocation"], item.phys_addr:match("^(%x+:%x+:%x+:%x+:%x+:%x+)"))
end
end
table.insert(nmap.registry[host.ip]["mac-geolocation"], "00:23:69:2a:b1:27")
if SCRIPT_TYPE == "prerule" and target.ALLOW_NEW_TARGETS then if SCRIPT_TYPE == "prerule" and target.ALLOW_NEW_TARGETS then
local sum = 0 local sum = 0