1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-27 18:09:01 +00:00

Fixed some problems which caused snmp-interfaces to always fail after obtaining info from the IF-MIB tree walk (invalid use of the percent escape char in the replacement param to gsub and other minor errors).

Fixed a problem which caused snmp-interfaces to always fail in the pre-scanning phase (attempt to index the undefined host table).
This commit is contained in:
jah
2012-07-19 17:21:55 +00:00
parent 972eae8bbb
commit 1c783a920e
2 changed files with 22 additions and 18 deletions

View File

@@ -1,5 +1,9 @@
# Nmap Changelog ($Id$); -*-text-*-
o [NSE] Fixed some bugs in snmp-interfaces which prevented the script from
outputting discovered interface info and caused it to abort in the
pre-scanning phase. [jah]
o [NSE] lltd-discovery scripts now parses for hostnames and outputs network
card manufacturer. [Hani Benhabiles]

View File

@@ -208,13 +208,13 @@ function process_interfaces( tbl )
-- Add the %. escape character to prevent matching the index on e.g. "1.3.6.1.2.1.2.2.1.10."
local if_index = "1.3.6.1.2.1.2.2.1.1%."
local if_descr = "1.3.6.1.2.1.2.2.1.2%."
local if_type = "1.3.6.1.2.1.2.2.1.3%."
local if_speed = "1.3.6.1.2.1.2.2.1.5%."
local if_phys_addr = "1.3.6.1.2.1.2.2.1.6%."
local if_status = "1.3.6.1.2.1.2.2.1.8%."
local if_in_octets = "1.3.6.1.2.1.2.2.1.10%."
local if_out_octets = "1.3.6.1.2.1.2.2.1.16%."
local if_descr = "1.3.6.1.2.1.2.2.1.2."
local if_type = "1.3.6.1.2.1.2.2.1.3."
local if_speed = "1.3.6.1.2.1.2.2.1.5."
local if_phys_addr = "1.3.6.1.2.1.2.2.1.6."
local if_status = "1.3.6.1.2.1.2.2.1.8."
local if_in_octets = "1.3.6.1.2.1.2.2.1.10."
local if_out_octets = "1.3.6.1.2.1.2.2.1.16."
local new_tbl = {}
-- Some operating systems (such as MS Windows) don't list interfaces with consecutive indexes
@@ -361,7 +361,7 @@ function build_results( tbl )
if interface.descr then
item.name = interface.descr
else
item.name = string.format("Interface %d", item.index)
item.name = string.format("Interface %d", index)
end
if interface.ip_addr and interface.netmask then
@@ -406,14 +406,6 @@ action = function(host, port)
local status
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
srvhost = stdnse.get_script_args({"snmp-interfaces.host", "host"})
if not srvhost then
@@ -432,6 +424,14 @@ action = function(host, port)
srvport = port.number
end
-- table for mac-geolocation.nse
if not nmap.registry[srvhost] then
nmap.registry[srvhost] = {}
nmap.registry[srvhost]["mac-geolocation"] = {}
elseif not nmap.registry[srvhost]["mac-geolocation"] then
nmap.registry[srvhost]["mac-geolocation"] = {}
end
socket:set_timeout(5000)
try(socket:connect(srvhost, srvport, "udp"))
@@ -462,10 +462,10 @@ action = function(host, port)
-- 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+)"))
table.insert(nmap.registry[srvhost]["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")
-- wtf is this? table.insert(nmap.registry[srvhost]["mac-geolocation"], "00:23:69:2a:b1:27")
if SCRIPT_TYPE == "prerule" and target.ALLOW_NEW_TARGETS then
local sum = 0