mirror of
https://github.com/nmap/nmap.git
synced 2026-01-06 06:29:03 +00:00
NSE snmp manually rebase #122 provided patch
This commit is contained in:
@@ -46,24 +46,6 @@ dependencies = {"snmp-brute"}
|
||||
|
||||
portrule = shortport.portnumber(161, "udp", {"open", "open|filtered"})
|
||||
|
||||
local try
|
||||
|
||||
local function sendrequest(socket, oid, setparam)
|
||||
local payload
|
||||
local options = {}
|
||||
options.reqId = 28428 -- unnecessary?
|
||||
payload = snmp.encode(snmp.buildPacket(snmp.buildSetRequest(options, oid,setparam)))
|
||||
|
||||
try(socket:send(payload))
|
||||
|
||||
-- read in any response we might get
|
||||
local status, response = socket:receive()
|
||||
if ( not(status) ) then return status, response end
|
||||
|
||||
local result = snmp.fetchFirst(response)
|
||||
return true
|
||||
end
|
||||
|
||||
---
|
||||
-- Sends SNMP packets to host and reads responses
|
||||
action = function(host, port)
|
||||
@@ -74,20 +56,10 @@ action = function(host, port)
|
||||
return "ERROR: tftproot needs to end with slash"
|
||||
end
|
||||
|
||||
-- create the socket used for our connection
|
||||
local socket = nmap.new_socket()
|
||||
local snmpHelper = snmp.Helper:new(host, port)
|
||||
snmpHelper:connect()
|
||||
|
||||
-- set a reasonable timeout value
|
||||
socket:set_timeout(5000)
|
||||
|
||||
-- do some exception handling / cleanup
|
||||
local catch = function() socket:close() end
|
||||
try = nmap.new_try(catch)
|
||||
|
||||
-- connect to the potential SNMP system
|
||||
try(socket:connect(host, port))
|
||||
|
||||
local status, tftpserver, _, _, _ = socket:get_info()
|
||||
local status, tftpserver, _, _, _ = snmpHelper.socket:get_info()
|
||||
if( not(status) ) then
|
||||
return "ERROR: Failed to determine local ip"
|
||||
end
|
||||
@@ -95,7 +67,7 @@ action = function(host, port)
|
||||
-- build a SNMP v1 packet
|
||||
-- set value: .1.3.6.1.4.1.9.9.96.1.1.1.1.2.9999 (ConfigCopyProtocol is set to TFTP [1] )
|
||||
|
||||
local request = sendrequest(socket, ".1.3.6.1.4.1.9.9.96.1.1.1.1.2.9999",1)
|
||||
local request = snmpHelper:set({reqiId=28428},".1.3.6.1.4.1.9.9.96.1.1.1.1.2.9999",1)
|
||||
|
||||
-- Fail silently if the first request doesn't get a proper response
|
||||
if ( not(request) ) then return end
|
||||
@@ -107,13 +79,13 @@ action = function(host, port)
|
||||
-- build a SNMP v1 packet
|
||||
-- set value: .1.3.6.1.4.1.9.9.96.1.1.1.1.3 (SourceFileType is set to running-config [4] )
|
||||
|
||||
request = sendrequest(socket, ".1.3.6.1.4.1.9.9.96.1.1.1.1.3.9999",4)
|
||||
request = snmpHelper:set({reqId=28428}, ".1.3.6.1.4.1.9.9.96.1.1.1.1.3.9999",4)
|
||||
|
||||
-------------------------------------------------
|
||||
-- build a SNMP v1 packet
|
||||
-- set value: .1.3.6.1.4.1.9.9.96.1.1.1.1.4 (DestinationFileType is set to networkfile [1] )
|
||||
|
||||
request = sendrequest(socket, ".1.3.6.1.4.1.9.9.96.1.1.1.1.4.9999",1)
|
||||
request = snmpHelper:set({reqId=28428}, ".1.3.6.1.4.1.9.9.96.1.1.1.1.4.9999",1)
|
||||
|
||||
-------------------------------------------------
|
||||
-- build a SNMP v1 packet
|
||||
@@ -125,7 +97,7 @@ action = function(host, port)
|
||||
table.insert(tbl, octet)
|
||||
end
|
||||
|
||||
request = sendrequest(socket, nil, { { snmp.str2oid(".1.3.6.1.4.1.9.9.96.1.1.1.1.5.9999"), tbl } } )
|
||||
request = snmpHelper:set({reqId=28428}, nil, { { snmp.str2oid(".1.3.6.1.4.1.9.9.96.1.1.1.1.5.9999"), tbl } } )
|
||||
-- request = sendrequest(".1.3.6.1.4.1.9.9.96.1.1.1.1.5.9999",tftpserver)
|
||||
|
||||
|
||||
@@ -134,26 +106,26 @@ action = function(host, port)
|
||||
-- set value: .1.3.6.1.4.1.9.9.96.1.1.1.1.15 (ServerAddressType is set 1 for ipv4 )
|
||||
-- more options - 1:ipv4, 2:ipv6, 3:ipv4z, 4:ipv6z, 16:dns
|
||||
|
||||
request = sendrequest(socket, ".1.3.6.1.4.1.9.9.96.1.1.1.1.15.9999",1)
|
||||
request = snmpHelper:set({reqId=28428}, ".1.3.6.1.4.1.9.9.96.1.1.1.1.15.9999",1)
|
||||
|
||||
-------------------------------------------------
|
||||
-- build a SNMP v1 packet
|
||||
-- set value: .1.3.6.1.4.1.9.9.96.1.1.1.1.16 (ServerAddress is set to the IP address of the TFTP server )
|
||||
|
||||
request = sendrequest(socket, ".1.3.6.1.4.1.9.9.96.1.1.1.1.16.9999",tftpserver)
|
||||
request = snmpHelper:set({reqId=28428}, ".1.3.6.1.4.1.9.9.96.1.1.1.1.16.9999",tftpserver)
|
||||
|
||||
-------------------------------------------------
|
||||
-- build a SNMP v1 packet
|
||||
-- set value: .1.3.6.1.4.1.9.9.96.1.1.1.1.6 (CopyFilename is set to IP-config)
|
||||
|
||||
request = sendrequest(socket, ".1.3.6.1.4.1.9.9.96.1.1.1.1.6.9999",host.ip .. "-config")
|
||||
request = snmpHelper:set({reqId=28428}, ".1.3.6.1.4.1.9.9.96.1.1.1.1.6.9999",host.ip .. "-config")
|
||||
|
||||
-------------------------------------------------
|
||||
-- build a SNMP v1 packet
|
||||
-- set value: .1.3.6.1.4.1.9.9.96.1.1.1.1.14 (Start copying by setting CopyStatus to active [1])
|
||||
-- more options: 1:active, 2:notInService, 3:notReady, 4:createAndGo, 5:createAndWait, 6:destroy
|
||||
|
||||
request = sendrequest(socket, ".1.3.6.1.4.1.9.9.96.1.1.1.1.14.9999",1)
|
||||
request = snmpHelper:set({reqId=28428}, ".1.3.6.1.4.1.9.9.96.1.1.1.1.14.9999",1)
|
||||
|
||||
-- wait for sometime and print the status of filetransfer
|
||||
tftp.start()
|
||||
@@ -162,16 +134,8 @@ action = function(host, port)
|
||||
-- build a SNMP v1 packet
|
||||
-- get value: .1.3.6.1.4.1.9.9.96.1.1.1.1.10 (Check the status of filetransfer) 1:waiting, 2:running, 3:successful, 4:failed
|
||||
|
||||
local options = {}
|
||||
options.reqId = 28428
|
||||
local payload = snmp.encode(snmp.buildPacket(snmp.buildGetRequest(options, ".1.3.6.1.4.1.9.9.96.1.1.1.1.10.9999")))
|
||||
|
||||
try(socket:send(payload))
|
||||
|
||||
local status
|
||||
local response
|
||||
-- read in any response we might get
|
||||
status, response = socket:receive()
|
||||
status, response = snmpHelper:get({reqId=28428}, ".1.3.6.1.4.1.9.9.96.1.1.1.1.10.9999")
|
||||
|
||||
if (not status) or (response == "TIMEOUT") then
|
||||
return "\n ERROR: Failed to receive cisco configuration file"
|
||||
@@ -205,9 +169,8 @@ action = function(host, port)
|
||||
-- build a SNMP v1 packet
|
||||
-- set value: .1.3.6.1.4.1.9.9.96.1.1.1.1.14 (Destroy settings by setting CopyStatus to destroy [6])
|
||||
|
||||
request = sendrequest(socket, ".1.3.6.1.4.1.9.9.96.1.1.1.1.14.9999",6)
|
||||
request = snmpHelper:set({reqId=28428}, ".1.3.6.1.4.1.9.9.96.1.1.1.1.14.9999",6)
|
||||
|
||||
try(socket:close())
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user