From 0d47952611198ef6b1163f366dc03922d20b1475 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 09:42:04 +0200 Subject: Adding upstream version 7.94+git20230807.3be01efb1+dfsg. Signed-off-by: Daniel Baumann --- scripts/hddtemp-info.nse | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 scripts/hddtemp-info.nse (limited to 'scripts/hddtemp-info.nse') diff --git a/scripts/hddtemp-info.nse b/scripts/hddtemp-info.nse new file mode 100644 index 0000000..86dee83 --- /dev/null +++ b/scripts/hddtemp-info.nse @@ -0,0 +1,69 @@ +local comm = require "comm" +local math = require "math" +local shortport = require "shortport" +local string = require "string" +local stringaux = require "stringaux" +local table = require "table" + +description = [[ +Reads hard disk information (such as brand, model, and sometimes temperature) from a listening hddtemp service. +]] + +--- +-- @usage +-- nmap -p 7634 -sV -sC +-- +-- @output +-- 7634/tcp open hddtemp +-- | hddtemp-info: +-- |_ /dev/sda: WDC WD2500JS-60MHB1: 38 C +-- +-- @xmloutput +-- +-- WDC WD2500JS-60MHB1 +-- C +-- /dev/sda +-- 38 +--
+-- +-- WDC WD3200BPVT-75JJ5T0 +-- C +-- /dev/sdb +-- 41 +--
+ +author = "Toni Ruottu" +license = "Same as Nmap--See https://nmap.org/book/man-legal.html" +categories = {"default", "discovery", "safe"} + + +portrule = shortport.port_or_service (7634, "hddtemp", {"tcp"}) + +local fmt_meta = { + __tostring = function (t) + return string.format("%s: %s: %s %s", t.device, t.label, t.temperature, t.unit) + end +} +action = function( host, port ) + -- 5000B should be enough for 100 disks + local status, data = comm.get_banner(host, port, {bytes=5000}) + if not status then + return + end + local separator = string.sub(data, 1, 1) + local fields = stringaux.strsplit(separator, data) + local info = {} + local disks = math.floor((# fields) / 5) + for i = 0, (disks - 1) do + local start = i * 5 + local diskinfo = { + device = fields[start + 2], + label = fields[start + 3], + temperature = fields[start + 4], + unit = fields[start + 5], + } + setmetatable(diskinfo, fmt_meta) + table.insert(info, diskinfo) + end + return info +end -- cgit v1.2.3