mirror of
https://github.com/nmap/nmap.git
synced 2025-12-16 04:39:03 +00:00
o [NSE] Added snmpWalk function to SNMP library and updated scripts to use it
[Patrik]
This commit is contained in:
@@ -21,60 +21,16 @@ license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
||||
categories = {"default", "discovery", "safe"}
|
||||
dependencies = {"snmp-brute"}
|
||||
|
||||
-- Version 0.2
|
||||
-- Version 0.3
|
||||
-- Created 01/15/2010 - v0.1 - created by Patrik Karlsson <patrik@cqure.net>
|
||||
-- Revised 01/19/2010 - v0.2 - fixed loop that would occure if a mib did not exist
|
||||
-- Revised 04/11/2010 - v0.3 - moved snmp_walk to snmp library <patrik@cqure.net>
|
||||
|
||||
require "shortport"
|
||||
require "snmp"
|
||||
|
||||
portrule = shortport.portnumber(161, "udp", {"open", "open|filtered"})
|
||||
|
||||
--- Walks the MIB Tree
|
||||
--
|
||||
-- @param socket socket already connected to the server
|
||||
-- @param base_oid string containing the base object ID to walk
|
||||
-- @return table containing <code>oid</code> and <code>value</code>
|
||||
function snmp_walk( socket, base_oid )
|
||||
|
||||
local catch = function() socket:close() end
|
||||
local try = nmap.new_try(catch)
|
||||
|
||||
local snmp_table = {}
|
||||
local oid = base_oid
|
||||
|
||||
while ( true ) do
|
||||
|
||||
local value, response, snmpdata, options, item = nil, nil, nil, {}, {}
|
||||
options.reqId = 28428 -- unnecessary?
|
||||
payload = snmp.encode( snmp.buildPacket( snmp.buildGetNextRequest(options, oid) ) )
|
||||
|
||||
try(socket:send(payload))
|
||||
response = try( socket:receive_bytes(1) )
|
||||
|
||||
snmpdata = snmp.fetchResponseValues( response )
|
||||
|
||||
value = snmpdata[1][1]
|
||||
oid = snmpdata[1][2]
|
||||
|
||||
if not oid:match( base_oid ) or base_oid == oid then
|
||||
break
|
||||
end
|
||||
|
||||
item.oid = oid
|
||||
item.value = value
|
||||
|
||||
table.insert( snmp_table, item )
|
||||
|
||||
end
|
||||
|
||||
socket:close()
|
||||
snmp_table.baseoid = base_oid
|
||||
|
||||
return snmp_table
|
||||
|
||||
end
|
||||
|
||||
--- Processes the table and creates the script output
|
||||
--
|
||||
-- @param tbl table containing <code>oid</code> and <code>value</code>
|
||||
@@ -100,11 +56,18 @@ action = function(host, port)
|
||||
local try = nmap.new_try(catch)
|
||||
local snmpoid = "1.3.6.1.4.1.77.1.2.25"
|
||||
local users = {}
|
||||
local status
|
||||
|
||||
socket:set_timeout(5000)
|
||||
try(socket:connect(host.ip, port.number, "udp"))
|
||||
|
||||
users = snmp_walk( socket, snmpoid )
|
||||
status, users = snmp.snmpWalk( socket, snmpoid )
|
||||
socket:close()
|
||||
|
||||
if( not(status) ) then
|
||||
return
|
||||
end
|
||||
|
||||
users = process_answer( users )
|
||||
|
||||
if ( users == nil ) or ( #users == 0 ) then
|
||||
|
||||
Reference in New Issue
Block a user