diff --git a/CHANGELOG b/CHANGELOG index 9611f8921..359f17ce5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,9 @@ o Added NSE Datafiles library which reads and parses Nmap's nmap-* (e.g. port numbers) indexing names (e.g. service names). The rpcinfo.nse script was also updated to use this library. [Kris] +o Corrected uptime parsing and reporting in SNMPsysdesr.nse for an + uptime of less than 46 hours. [Kris] + o Added many additional PCRE option flags to the list returned by the NSE pcre.flags() function. [Kris] diff --git a/scripts/SNMPsysdesr.nse b/scripts/SNMPsysdesr.nse index bf2390038..7921346fd 100644 --- a/scripts/SNMPsysdesr.nse +++ b/scripts/SNMPsysdesr.nse @@ -90,18 +90,30 @@ action = function(host, port) try(socket:close()) - if string.find(response, "\006\001\002\001\001\003") == nil then + local start, stop = response:find("\006\001\002\001\001\003\000") + + if start == nil then return result end - local length,uptime,s1,s2,s3,s4 - - length = string.len(response) - - s1,s2,s3,s4 = string.byte(response, length - 3, length) - - uptime = s1*(2^24) + s2*(2^16) + s3*(2^8) + s4 - + local uplen,uptime,s1,s2,s3,s4 + + uplen = response:byte(stop + 2) + + s1,s2,s3,s4 = response:byte(stop + 3, stop + 3 + uplen) + + if uplen == 4 then + uptime = s1*(2^24) + s2*(2^16) + s3*(2^8) + s4 + elseif uplen == 3 then + uptime = s1*(2^16) + s2*(2^8) + s3 + elseif uplen == 2 then + uptime = s1*(2^8) + s2 + elseif uplen == 1 then + uptime = s1 + else + return result + end + local days, hours, minutes, seconds, htime, mtime, stime days = math.floor(uptime / 8640000) htime = math.fmod(uptime, 8640000)