From 80591c9cc611bab585d1d10514025b7b73378ec6 Mon Sep 17 00:00:00 2001 From: ron Date: Thu, 12 Mar 2009 14:56:23 +0000 Subject: [PATCH] Cleaned up output of smb-server-stats.nse --- nselib/smb.lua | 41 +++++++++++------------------------- nselib/stdnse.lua | 18 ++++++++++++++++ scripts/smb-server-stats.nse | 16 +++++--------- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/nselib/smb.lua b/nselib/smb.lua index f4f8071fe..d08b205bb 100644 --- a/nselib/smb.lua +++ b/nselib/smb.lua @@ -258,23 +258,6 @@ function get_port(host) return nil end ----Either return the string itself, or return "" (or the value of the second parameter) if the string --- was blank or nil. ---@param string The base string. ---@param blank The string to return if string was blank ---@return Either string or, if it was blank, blank -local function string_or_blank(string, blank) - if(string == nil or string == "") then - if(blank == nil) then - return "" - else - return blank - end - else - return string - end -end - ---Turn off extended security negotiations for this connection. There are a few reasons you might want to -- do that, the main ones being that extended security is going to be marginally slower and it's not going -- to give the same level of information in some cases (namely, it doesn't present the server's name). @@ -1224,9 +1207,9 @@ function start_session_basic(smb, overrides, use_default, log_errors) -- Check if they were logged in as a guest if(log_errors == nil or log_errors == true) then if(smb['is_guest'] == 1) then - stdnse.print_debug(1, "SMB: Login as %s\\%s failed, but was given guest access (username may be wrong, or system may only allow guest)", accounts[i]['domain'], string_or_blank(accounts[i]['username'])) + stdnse.print_debug(1, "SMB: Login as %s\\%s failed, but was given guest access (username may be wrong, or system may only allow guest)", accounts[i]['domain'], stdnse.string_or_blank(accounts[i]['username'])) else - stdnse.print_debug(1, "SMB: Login as %s\\%s succeeded", accounts[i]['domain'], string_or_blank(accounts[i]['username'])) + stdnse.print_debug(1, "SMB: Login as %s\\%s succeeded", accounts[i]['domain'], stdnse.string_or_blank(accounts[i]['username'])) end end @@ -1238,7 +1221,7 @@ function start_session_basic(smb, overrides, use_default, log_errors) else -- This username failed, print a warning and keep going if(log_errors == nil or log_errors == true) then - stdnse.print_debug(1, "SMB: Login as %s\\%s failed (%s)", accounts[i]['domain'], string_or_blank(accounts[i]['username']), get_status_name(status)) + stdnse.print_debug(1, "SMB: Login as %s\\%s failed (%s)", accounts[i]['domain'], stdnse.string_or_blank(accounts[i]['username']), get_status_name(status)) end end end @@ -1352,9 +1335,9 @@ function start_session_extended(smb, overrides, use_default, log_errors) -- Check if they were logged in as a guest if(log_errors == nil or log_errors == true) then if(smb['is_guest'] == 1) then - stdnse.print_debug(1, string.format("SMB: Extended login as %s\\%s failed, but was given guest access (username may be wrong, or system may only allow guest)", accounts[i]['domain'], string_or_blank(accounts[i]['username']))) + stdnse.print_debug(1, string.format("SMB: Extended login as %s\\%s failed, but was given guest access (username may be wrong, or system may only allow guest)", accounts[i]['domain'], stdnse.string_or_blank(accounts[i]['username']))) else - stdnse.print_debug(1, string.format("SMB: Extended login as %s\\%s succeeded", accounts[i]['domain'], string_or_blank(accounts[i]['username']))) + stdnse.print_debug(1, string.format("SMB: Extended login as %s\\%s succeeded", accounts[i]['domain'], stdnse.string_or_blank(accounts[i]['username']))) end end @@ -1368,7 +1351,7 @@ function start_session_extended(smb, overrides, use_default, log_errors) -- Display a message to the user, and try the next account if(log_errors == nil or log_errors == true) then - stdnse.print_debug(1, "SMB: Extended login as %s\\%s failed (%s)", accounts[i]['domain'], string_or_blank(accounts[i]['username']), status_name) + stdnse.print_debug(1, "SMB: Extended login as %s\\%s failed (%s)", accounts[i]['domain'], stdnse.string_or_blank(accounts[i]['username']), status_name) end -- Reset the user id and security_blob @@ -2199,12 +2182,12 @@ function get_os(host) end -- Convert blank values to something useful - response['os'] = string_or_blank(smbstate['os'], "Unknown") - response['lanmanager'] = string_or_blank(smbstate['lanmanager'], "Unknown") - response['domain'] = string_or_blank(smbstate['domain'], "Unknown") - response['server'] = string_or_blank(smbstate['server'], "Unknown") - response['date'] = string_or_blank(smbstate['date'], "Unknown") - response['timezone_str'] = string_or_blank(smbstate['timezone_str'], "Unknown") + response['os'] = stdnse.string_or_blank(smbstate['os'], "Unknown") + response['lanmanager'] = stdnse.string_or_blank(smbstate['lanmanager'], "Unknown") + response['domain'] = stdnse.string_or_blank(smbstate['domain'], "Unknown") + response['server'] = stdnse.string_or_blank(smbstate['server'], "Unknown") + response['date'] = stdnse.string_or_blank(smbstate['date'], "Unknown") + response['timezone_str'] = stdnse.string_or_blank(smbstate['timezone_str'], "Unknown") -- Kill SMB smb.stop(smbstate) diff --git a/nselib/stdnse.lua b/nselib/stdnse.lua index 0eb257eaf..2b7e0fb35 100644 --- a/nselib/stdnse.lua +++ b/nselib/stdnse.lua @@ -241,3 +241,21 @@ function tohex( s, options ) return hex end +---Either return the string itself, or return "" (or the value of the second parameter) if the string +-- was blank or nil. +-- +--@param string The base string. +--@param blank The string to return if string was blank +--@return Either string or, if it was blank, blank +function string_or_blank(string, blank) + if(string == nil or string == "") then + if(blank == nil) then + return "" + else + return blank + end + else + return string + end +end + diff --git a/scripts/smb-server-stats.nse b/scripts/smb-server-stats.nse index 7239e7078..bb802272c 100644 --- a/scripts/smb-server-stats.nse +++ b/scripts/smb-server-stats.nse @@ -21,12 +21,9 @@ up to version 1.0.3 (and possibly higher). -- @output -- Host script results: -- | smb-server-stats: --- | Server statistics collected since 2008-10-17 09:32:41 (4d0h24m29s): --- | |_ Traffic 133467 bytes (0.38b/s) sent, 167696 bytes (0.48b/s) received --- | |_ Failed logins: 5 --- | |_ Permission errors: 1, System errors: 0 --- | |_ Print jobs spooled: 0 --- |_ |_ Files opened (including pipes): 18 +-- | Server statistics collected since 2008-12-12 14:53:27 (89d17h37m48s): +-- | |_ 22884718 bytes (2.95 b/s) sent, 28082489 bytes (3.62 b/s) received +-- |_ |_ 5759 failed logins, 16 permission errors, 0 system errors, 0 print jobs, 1273 files opened ----------------------------------------------------------------------- author = "Ron Bowes" @@ -58,11 +55,8 @@ action = function(host) end response = response .. string.format("Server statistics collected since %s (%s):\n", stats['start_str'], stats['period_str']) - response = response .. string.format("|_ Traffic %d bytes (%.2f b/s) sent, %d bytes (%.2f b/s) received\n", stats['bytessent'], stats['bytessentpersecond'], stats['bytesrcvd'], stats['bytesrcvdpersecond']) - response = response .. string.format("|_ Failed logins: %d\n", stats['pwerrors']) - response = response .. string.format("|_ Permission errors: %d, System errors: %d\n", stats['permerrors'], stats['syserrors']) - response = response .. string.format("|_ Print jobs spooled: %s\n", stats['jobsqueued']) - response = response .. string.format("|_ Files opened (including pipes): %d\n", stats['fopens']) + response = response .. string.format("|_ %d bytes (%.2f b/s) sent, %d bytes (%.2f b/s) received\n", stats['bytessent'], stats['bytessentpersecond'], stats['bytesrcvd'], stats['bytesrcvdpersecond']) + response = response .. string.format("|_ %d failed logins, %d permission errors, %d system errors, %d print jobs, %d files opened\n", stats['pwerrors'], stats['permerrors'], stats['syserrors'], stats['jobsqueued'], stats['fopens']) return response end