1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Convert a few files to Unix line endings

This commit is contained in:
dmiller
2017-07-18 18:46:02 +00:00
parent dff7eca79f
commit 7f779ef8b6
2 changed files with 297 additions and 297 deletions

View File

@@ -1,8 +1,8 @@
#ifndef LIBSSH2 #ifndef LIBSSH2
#define LIBSSH2 #define LIBSSH2
#define LIBSSH2LIBNAME "libssh2" #define LIBSSH2LIBNAME "libssh2"
int luaopen_libssh2 (lua_State *L); int luaopen_libssh2 (lua_State *L);
#endif #endif

View File

@@ -1,289 +1,289 @@
local stdnse = require "stdnse" local stdnse = require "stdnse"
local shortport = require "shortport" local shortport = require "shortport"
local comm = require "comm" local comm = require "comm"
local string = require "string" local string = require "string"
local table = require "table" local table = require "table"
description = [[ description = [[
OpenWebNet is a communications protocol developed by Bticino since 2000. OpenWebNet is a communications protocol developed by Bticino since 2000.
Retrieves device identifying information and number of connected devices. Retrieves device identifying information and number of connected devices.
References: References:
* https://www.myopen-legrandgroup.com/solution-gallery/openwebnet/ * https://www.myopen-legrandgroup.com/solution-gallery/openwebnet/
* http://www.pimyhome.org/wiki/index.php/OWN_OpenWebNet_Language_Reference * http://www.pimyhome.org/wiki/index.php/OWN_OpenWebNet_Language_Reference
]] ]]
--- ---
-- @usage -- @usage
-- nmap --script openwebnet-discovery -- nmap --script openwebnet-discovery
-- --
-- @output -- @output
-- | openwebnet-discover: -- | openwebnet-discover:
-- | IP Address: 192.168.200.35 -- | IP Address: 192.168.200.35
-- | Net Mask: 255.255.255.0 -- | Net Mask: 255.255.255.0
-- | MAC Address: 00:03:50:01:d3:11 -- | MAC Address: 00:03:50:01:d3:11
-- | Device Type: F453AV -- | Device Type: F453AV
-- | Firmware Version: 3.0.14 -- | Firmware Version: 3.0.14
-- | Uptime: 12d9h42m1s -- | Uptime: 12d9h42m1s
-- | Date and Time: 4-07-2017T19:17:27 -- | Date and Time: 4-07-2017T19:17:27
-- | Kernel Version: 2.3.8 -- | Kernel Version: 2.3.8
-- | Distribution Version: 3.0.1 -- | Distribution Version: 3.0.1
-- | Lighting: 115 -- | Lighting: 115
-- | Automation: 15 -- | Automation: 15
-- |_ Burglar Alarm: 12 -- |_ Burglar Alarm: 12
-- --
-- @xmloutput -- @xmloutput
-- <elem key="IP Address">192.168.200.35</elem> -- <elem key="IP Address">192.168.200.35</elem>
-- <elem key="Net Mask">255.255.255.0</elem> -- <elem key="Net Mask">255.255.255.0</elem>
-- <elem key="MAC Address">00:03:50:01:d3:11</elem> -- <elem key="MAC Address">00:03:50:01:d3:11</elem>
-- <elem key="Device Type">F453AV</elem> -- <elem key="Device Type">F453AV</elem>
-- <elem key="Firmware Version">3.0.14</elem> -- <elem key="Firmware Version">3.0.14</elem>
-- <elem key="Uptime">12d9h42m1s</elem> -- <elem key="Uptime">12d9h42m1s</elem>
-- <elem key="Date and Time">4-07-2017T19:17:27</elem> -- <elem key="Date and Time">4-07-2017T19:17:27</elem>
-- <elem key="Kernel Version">2.3.8</elem> -- <elem key="Kernel Version">2.3.8</elem>
-- <elem key="Distribution Version">3.0.1</elem> -- <elem key="Distribution Version">3.0.1</elem>
-- <elem key="Lighting">115</elem> -- <elem key="Lighting">115</elem>
-- <elem key="Automation">15</elem> -- <elem key="Automation">15</elem>
-- <elem key="Burglar Alarm">12</elem> -- <elem key="Burglar Alarm">12</elem>
author = "Rewanth Cool" author = "Rewanth Cool"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html" license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"discovery", "safe"} categories = {"discovery", "safe"}
portrule = shortport.port_or_service(20000, "openwebnet") portrule = shortport.port_or_service(20000, "openwebnet")
local device = { local device = {
[2] = "MHServer", [2] = "MHServer",
[4] = "MH200", [4] = "MH200",
[6] = "F452", [6] = "F452",
[7] = "F452V", [7] = "F452V",
[11] = "MHServer2", [11] = "MHServer2",
[12] = "F453AV", [12] = "F453AV",
[13] = "H4684", [13] = "H4684",
[15] = "F427 (Gateway Open-KNX)", [15] = "F427 (Gateway Open-KNX)",
[16] = "F453", [16] = "F453",
[23] = "H4684", [23] = "H4684",
[27] = "L4686SDK", [27] = "L4686SDK",
[44] = "MH200N", [44] = "MH200N",
[51] = "F454", [51] = "F454",
[200] = "F454 (new?)" [200] = "F454 (new?)"
} }
local who = { local who = {
[0] = "Scenarios", [0] = "Scenarios",
[1] = "Lighting", [1] = "Lighting",
[2] = "Automation", [2] = "Automation",
[3] = "Power Management", [3] = "Power Management",
[4] = "Heating", [4] = "Heating",
[5] = "Burglar Alarm", [5] = "Burglar Alarm",
[6] = "Door Entry System", [6] = "Door Entry System",
[7] = "Multimedia", [7] = "Multimedia",
[9] = "Auxiliary", [9] = "Auxiliary",
[13] = "Device Communication", [13] = "Device Communication",
[14] = "Light+shutters actuators lock", [14] = "Light+shutters actuators lock",
[15] = "CEN", [15] = "CEN",
[16] = "Sound System", [16] = "Sound System",
[17] = "Scenario Programming", [17] = "Scenario Programming",
[18] = "Energy Management", [18] = "Energy Management",
[24] = "Lighting Management", [24] = "Lighting Management",
[25] = "CEN plus", [25] = "CEN plus",
[1000] = "Diagnostic", [1000] = "Diagnostic",
[1001] = "Automation Diagnostic", [1001] = "Automation Diagnostic",
[1004] = "Heating Diagnostic", [1004] = "Heating Diagnostic",
[1008] = "Door Entry System Diagnostic", [1008] = "Door Entry System Diagnostic",
[1013] = "Device Diagnostic" [1013] = "Device Diagnostic"
} }
local device_dimension = { local device_dimension = {
["Time"] = "0", ["Time"] = "0",
["Date"] = "1", ["Date"] = "1",
["IP Address"] = "10", ["IP Address"] = "10",
["Net Mask"] = "11", ["Net Mask"] = "11",
["MAC Address"] = "12", ["MAC Address"] = "12",
["Device Type"] = "15", ["Device Type"] = "15",
["Firmware Version"] = "16", ["Firmware Version"] = "16",
["Hardware Version"] = "17", ["Hardware Version"] = "17",
["Uptime"] = "19", ["Uptime"] = "19",
["Micro Version"] = "20", ["Micro Version"] = "20",
["Date and Time"] = "22", ["Date and Time"] = "22",
["Kernel Version"] = "23", ["Kernel Version"] = "23",
["Distribution Version"] = "24", ["Distribution Version"] = "24",
["Gateway IP address"] = "50", ["Gateway IP address"] = "50",
["DNS IP address 1"] = "51", ["DNS IP address 1"] = "51",
["DNS IP address 2"] = "52" ["DNS IP address 2"] = "52"
} }
local ACK = "*#*1##" local ACK = "*#*1##"
local NACK = "*#*0##" local NACK = "*#*0##"
-- Initiates a socket connection -- Initiates a socket connection
-- Returns the socket and error message -- Returns the socket and error message
local function get_socket(host, port, request) local function get_socket(host, port, request)
local sd, response, early_resp = comm.opencon(host, port, request, {recv_before=true, request_timeout=10000}) local sd, response, early_resp = comm.opencon(host, port, request, {recv_before=true, request_timeout=10000})
if sd == nil then if sd == nil then
stdnse.debug("Socket connection error.") stdnse.debug("Socket connection error.")
return nil, response return nil, response
end end
if not response then if not response then
stdnse.debug("Poor internet connection or no response.") stdnse.debug("Poor internet connection or no response.")
return nil, response return nil, response
end end
if response == NACK then if response == NACK then
stdnse.debug("Received a negative ACK as response.") stdnse.debug("Received a negative ACK as response.")
return nil, response return nil, response
end end
return sd, nil return sd, nil
end end
local function get_response(sd, request) local function get_response(sd, request)
local res = {} local res = {}
local status, data local status, data
sd:send(request) sd:send(request)
repeat repeat
status, data = sd:receive_buf("##", true) status, data = sd:receive_buf("##", true)
if status == nil then if status == nil then
stdnse.debug("Error: " .. data) stdnse.debug("Error: " .. data)
if data == "TIMEOUT" then if data == "TIMEOUT" then
-- Avoids false results by capturing NACK after TIMEOUT occured. -- Avoids false results by capturing NACK after TIMEOUT occured.
status, data = sd:receive_buf("##", true) status, data = sd:receive_buf("##", true)
break break
else else
-- Captures other kind of errors like EOF -- Captures other kind of errors like EOF
sd:close() sd:close()
return res return res
end end
end end
if status and data ~= ACK then if status and data ~= ACK then
table.insert(res, data) table.insert(res, data)
end end
if data == ACK then if data == ACK then
break break
end end
-- If response is NACK, it means the request method is not supported -- If response is NACK, it means the request method is not supported
if data == NACK then if data == NACK then
res = nil res = nil
break break
end end
until not status until not status
return res return res
end end
local function format_dimensions(res) local function format_dimensions(res)
if res["Date and Time"] then if res["Date and Time"] then
local params = { local params = {
"hour", "min", "sec", "msec", "dayOfWeek", "year", "month", "day" "hour", "min", "sec", "msec", "dayOfWeek", "year", "month", "day"
} }
local values = {} local values = {}
for counter, val in ipairs(stdnse.strsplit("%.%s*", res["Date and Time"])) do for counter, val in ipairs(stdnse.strsplit("%.%s*", res["Date and Time"])) do
values[ params[counter] ] = val values[ params[counter] ] = val
end end
res["Date and Time"] = stdnse.format_timestamp(values) res["Date and Time"] = stdnse.format_timestamp(values)
end end
if res["Device Type"] then if res["Device Type"] then
res["Device Type"] = device[ tonumber( res["Device Type"] ) ] res["Device Type"] = device[ tonumber( res["Device Type"] ) ]
end end
if res["MAC Address"] then if res["MAC Address"] then
res["MAC Address"] = string.gsub(res["MAC Address"], "(%d+)(%.?)", function(num, separator) res["MAC Address"] = string.gsub(res["MAC Address"], "(%d+)(%.?)", function(num, separator)
if separator == "." then if separator == "." then
return string.format("%02x:", num) return string.format("%02x:", num)
else else
return string.format("%02x", num) return string.format("%02x", num)
end end
end end
) )
end end
if res["Uptime"] then if res["Uptime"] then
local t = {} local t = {}
local units = { local units = {
"d", "h", "m", "s" "d", "h", "m", "s"
} }
for counter, v in ipairs(stdnse.strsplit("%.%s*", res["Uptime"])) do for counter, v in ipairs(stdnse.strsplit("%.%s*", res["Uptime"])) do
table.insert(t, v .. units[counter]) table.insert(t, v .. units[counter])
end end
res["Uptime"] = table.concat(t, "") res["Uptime"] = table.concat(t, "")
end end
return res return res
end end
action = function(host, port) action = function(host, port)
local output = stdnse.output_table() local output = stdnse.output_table()
local sd, err = get_socket(host, port, nil) local sd, err = get_socket(host, port, nil)
-- Socket connection creation failed -- Socket connection creation failed
if sd == nil then if sd == nil then
return err return err
end end
-- Fetching list of dimensions of a device -- Fetching list of dimensions of a device
for _, device in ipairs({"IP Address", "Net Mask", "MAC Address", "Device Type", "Firmware Version", "Uptime", "Date and Time", "Kernel Version", "Distribution Version"}) do for _, device in ipairs({"IP Address", "Net Mask", "MAC Address", "Device Type", "Firmware Version", "Uptime", "Date and Time", "Kernel Version", "Distribution Version"}) do
local head = "*#13**" local head = "*#13**"
local tail = "##" local tail = "##"
stdnse.debug("Fetching " .. device) stdnse.debug("Fetching " .. device)
local res = get_response(sd, head .. device_dimension[device] .. tail) local res = get_response(sd, head .. device_dimension[device] .. tail)
-- Extracts substring from the result -- Extracts substring from the result
-- Ex: -- Ex:
-- Request - *#13**16## -- Request - *#13**16##
-- Response - *#13**16*3*0*14## -- Response - *#13**16*3*0*14##
-- Trimmed Output - 3*0*14 -- Trimmed Output - 3*0*14
if res and next(res) then if res and next(res) then
local regex = string.gsub(head, "*", "%%*") .. device_dimension[device] .. "%*" .."(.+)" .. tail local regex = string.gsub(head, "*", "%%*") .. device_dimension[device] .. "%*" .."(.+)" .. tail
local tempRes = string.match(res[1], regex) local tempRes = string.match(res[1], regex)
if tempRes then if tempRes then
output[device] = string.gsub(tempRes, "*", ".") output[device] = string.gsub(tempRes, "*", ".")
end end
end end
end end
-- Format the output based on dimension -- Format the output based on dimension
output = format_dimensions(output) output = format_dimensions(output)
-- Fetching list of each device -- Fetching list of each device
for i = 1, 6 do for i = 1, 6 do
stdnse.debug("Fetching the list of " .. who[i] .. " devices.") stdnse.debug("Fetching the list of " .. who[i] .. " devices.")
local res = get_response(sd, "*#" .. i .. "*0##") local res = get_response(sd, "*#" .. i .. "*0##")
if res and #res > 0 then if res and #res > 0 then
output[who[i]] = #res output[who[i]] = #res
end end
end end
if #output > 0 then if #output > 0 then
return output return output
else else
return nil return nil
end end
end end