-
Notifications
You must be signed in to change notification settings - Fork 60
/
Siemens-Scalance-module.nse
84 lines (60 loc) · 1.78 KB
/
Siemens-Scalance-module.nse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
local nmap = require "nmap"
local shortport = require "shortport"
local snmp = require "snmp"
local stdnse = require "stdnse"
local table = require "table"
description = [[
Checks for SCADA Siemens <code>SCALANCE</code> modules.
The higher the verbosity or debug level, the more disallowed entries are shown.
]]
---
-- @output
-- | Siemens-Scalance-module:
-- |_ SCALANCE W788-1PRO
author = "Jose Ramon Palanco, drainware"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"default", "discovery", "safe"}
dependencies = {"snmp-brute"}
portrule = shortport.portnumber(161, "udp", {"open", "open|filtered"})
function process_answer( tbl )
local new_tab = {}
for _, v in ipairs( tbl ) do
if string.find (v.value, "SCALANCE") then
version = v.value:gsub("SCALANCE", "VERSION:")
model = version:match("%W+ %s*(.-)%d%d%d")
if model == "W" then
version = version .. " (wireless device)"
elseif model == "X" then
version = version .. " (network switch)"
elseif model == "S" then
version = version .. " (firewall)"
end
else
return nil
end
table.insert( new_tab, version)
end
table.sort( new_tab )
return new_tab
end
action = function(host, port)
local socket = nmap.new_socket()
local catch = function() socket:close() end
local try = nmap.new_try(catch)
local snmpoid = "1.3.6.1.2.1.1.1"
local services = {}
local status
socket:set_timeout(5000)
try(socket:connect(host, port))
status, services = snmp.snmpWalk( socket, snmpoid )
socket:close()
if ( not(status) ) or ( services == nil ) or ( #services == 0 ) then
return
end
services = process_answer(services)
if services == nil then
return
end
nmap.set_port_state(host, port, "open")
return stdnse.format_output( true, services )
end