mirror of
https://github.com/nmap/nmap.git
synced 2026-08-04 06:40:48 +00:00
Correcting the uptime parsing and reporting in SNMPsysdesr.nse when the uptime is less than about 46 hours. The amount of bytes holding the uptime is variable up to 4, but the script was assuming it always held 4 bytes of uptime. When the real uptime was less than 46 hours, this script was reporting an uptime anywhere from 5 days to 130 days (I think it actually reported 0 days once, but the hours were all messed up).
This commit is contained in:
parent
c89f191406
commit
43523f441b
2 changed files with 24 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue