1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-24 16:39:03 +00:00

Convert snmp-win32-* to XML output

This commit is contained in:
dmiller
2014-09-03 19:50:03 +00:00
parent 5365095c7b
commit 1bd3e1e85c
4 changed files with 118 additions and 40 deletions

View File

@@ -14,13 +14,43 @@ Attempts to enumerate installed software through SNMP.
-- nmap -sU -p 161 --script=snmp-win32-software <target>
-- @output
-- | snmp-win32-software:
-- | Apache Tomcat 5.5 (remove only); 2007-09-15 15:13:18
-- | Microsoft Internationalized Domain Names Mitigation APIs; 2007-09-15 15:13:18
-- | Security Update for Windows Media Player (KB911564); 2007-09-15 15:13:18
-- | Security Update for Windows Server 2003 (KB924667-v2); 2007-09-15 15:13:18
-- | Security Update for Windows Media Player 6.4 (KB925398); 2007-09-15 15:13:18
-- | Security Update for Windows Server 2003 (KB925902); 2007-09-15 15:13:18
-- |_ Windows Internet Explorer 7; 2007-09-15 15:13:18
-- | Apache Tomcat 5.5 (remove only); 2007-09-15T15:13:18
-- | Microsoft Internationalized Domain Names Mitigation APIs; 2007-09-15T15:13:18
-- | Security Update for Windows Media Player (KB911564); 2007-09-15T15:13:18
-- | Security Update for Windows Server 2003 (KB924667-v2); 2007-09-15T15:13:18
-- | Security Update for Windows Media Player 6.4 (KB925398); 2007-09-15T15:13:18
-- | Security Update for Windows Server 2003 (KB925902); 2007-09-15T15:13:18
-- |_ Windows Internet Explorer 7; 2007-09-15T15:13:18
--
-- @xmloutput
-- <table>
-- <elem key="name">Apache Tomcat 5.5 (remove only)</elem>
-- <elem key="install_date">2007-09-15T15:13:18</elem>
-- </table>
-- <table>
-- <elem key="name">Microsoft Internationalized Domain Names Mitigation APIs</elem>
-- <elem key="install_date">2007-09-15T15:13:18</elem>
-- </table>
-- <table>
-- <elem key="name">Security Update for Windows Media Player (KB911564)</elem>
-- <elem key="install_date">2007-09-15T15:13:18</elem>
-- </table>
-- <table>
-- <elem key="name">Security Update for Windows Server 2003 (KB924667-v2)</elem>
-- <elem key="install_date">2007-09-15T15:13:18</elem>
-- </table>
-- <table>
-- <elem key="name">Security Update for Windows Media Player 6.4 (KB925398)</elem>
-- <elem key="install_date">2007-09-15T15:13:18</elem>
-- </table>
-- <table>
-- <elem key="name">Security Update for Windows Server 2003 (KB925902)</elem>
-- <elem key="install_date">2007-09-15T15:13:18</elem>
-- </table>
-- <table>
-- <elem key="name">Windows Internet Explorer 7</elem>
-- <elem key="install_date">2007-09-15T15:13:18</elem>
-- </table>
author = "Patrik Karlsson"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
@@ -40,7 +70,7 @@ portrule = shortport.portnumber(161, "udp", {"open", "open|filtered"})
-- @param tbl table containing <code>oid</code> and <code>value</code>
-- @param oid string containing the object id for which the value should be extracted
-- @return value of relevant type or nil if oid was not found
function get_value_from_table( tbl, oid )
local function get_value_from_table( tbl, oid )
for _, v in ipairs( tbl ) do
if v.oid == oid then
@@ -51,33 +81,58 @@ function get_value_from_table( tbl, oid )
return nil
end
local date_xlate = {
year = 2,
month = 3,
day = 4,
hour = 5,
min = 6,
sec = 7
}
-- translate date parts to positional indices for stdnse.format_timestamp
local date_metatab = {
__index = function (t, k)
return t[date_xlate[k]]
end
}
local sw_metatab = {
__tostring = function (t)
return ("%s; %s"):format(t.name , t.install_date)
end
}
--- Processes the table and creates the script output
--
-- @param tbl table containing <code>oid</code> and <code>value</code>
-- @return table suitable for <code>stdnse.format_output</code>
function process_answer( tbl )
local function process_answer( tbl )
local sw_name = "1.3.6.1.2.1.25.6.3.1.2"
local sw_name = "^1.3.6.1.2.1.25.6.3.1.2"
local sw_date = "1.3.6.1.2.1.25.6.3.1.5"
local new_tbl = {}
for _, v in ipairs( tbl ) do
if ( v.oid:match("^" .. sw_name) ) then
local objid = v.oid:gsub( "^" .. sw_name, sw_date)
if ( v.oid:match(sw_name) ) then
local objid = v.oid:gsub(sw_name, sw_date)
local install_date = get_value_from_table( tbl, objid )
local sw_item
local install_date_tab = { bin.unpack( ">SCCCCC", install_date ) }
setmetatable(install_date_tab, date_metatab)
local _, year, month, day, hour, min, sec = bin.unpack( ">SCCCCC", install_date )
install_date = ("%02d-%02d-%02d %02d:%02d:%02d"):format( year, month, day, hour, min, sec )
local sw_item = {
["name"] = v.value,
["install_date"] = stdnse.format_timestamp(install_date_tab)
}
sw_item = ("%s; %s"):format(v.value ,install_date)
setmetatable(sw_item, sw_metatab)
table.insert( new_tbl, sw_item )
end
end
table.sort( new_tbl )
table.sort( new_tbl, function(a, b) return a.name < b.name end )
return new_tbl
end
@@ -106,6 +161,6 @@ action = function(host, port)
nmap.set_port_state(host, port, "open")
return stdnse.format_output( true, sw )
return sw
end