mirror of
https://github.com/nmap/nmap.git
synced 2025-12-17 13:09:02 +00:00
Style changes to nbstat.nse
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
-- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html
|
-- @copyright Same as Nmap--See https://nmap.org/book/man-legal.html
|
||||||
|
|
||||||
local bin = require "bin"
|
local bin = require "bin"
|
||||||
local bit = require "bit"
|
|
||||||
local dns = require "dns"
|
local dns = require "dns"
|
||||||
local math = require "math"
|
local math = require "math"
|
||||||
local nmap = require "nmap"
|
local nmap = require "nmap"
|
||||||
@@ -61,8 +60,8 @@ function name_encode(name, scope)
|
|||||||
local L1_encoded = {}
|
local L1_encoded = {}
|
||||||
for i=1, #name, 1 do
|
for i=1, #name, 1 do
|
||||||
local b = string.byte(name, i)
|
local b = string.byte(name, i)
|
||||||
L1_encoded[i*2-1] = string.char(bit.rshift(bit.band(b, 0xF0), 4) + 0x41)
|
L1_encoded[i*2-1] = string.char(((b & 0xF0) >> 4) + 0x41)
|
||||||
L1_encoded[i*2] = string.char(bit.rshift(bit.band(b, 0x0F), 0) + 0x41)
|
L1_encoded[i*2] = string.char((b & 0x0F) + 0x41)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Do the L2 encoding
|
-- Do the L2 encoding
|
||||||
@@ -100,9 +99,7 @@ function name_decode(encoded_name)
|
|||||||
stdnse.debug3("Decoding name '%s'", encoded_name)
|
stdnse.debug3("Decoding name '%s'", encoded_name)
|
||||||
|
|
||||||
name = name:gsub("(.)(.)", function (a, b)
|
name = name:gsub("(.)(.)", function (a, b)
|
||||||
local ch = 0
|
local ch = ((string.byte(a) - 0x41) << 4) | (string.byte(b) - 0x41)
|
||||||
ch = bit.bor(ch, bit.lshift(string.byte(a) - 0x41, 4))
|
|
||||||
ch = bit.bor(ch, bit.lshift(string.byte(b) - 0x41, 0))
|
|
||||||
return string.char(ch)
|
return string.char(ch)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -199,7 +196,7 @@ function get_server_name(host, names)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, #names, 1 do
|
for i = 1, #names, 1 do
|
||||||
if names[i]['suffix'] == 0x00 && (names[i]['flags'] & 0x8000 == 0) then
|
if names[i]['suffix'] == 0x00 and (names[i]['flags'] & 0x8000) == 0 then
|
||||||
return true, names[i]['name']
|
return true, names[i]['name']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -366,11 +363,11 @@ function do_nbstat(host)
|
|||||||
if(ANCOUNT ~= 1) then
|
if(ANCOUNT ~= 1) then
|
||||||
return false, "Server returned an invalid number of answers"
|
return false, "Server returned an invalid number of answers"
|
||||||
end
|
end
|
||||||
if(bit.band(FLAGS, 0x8000) == 0) then
|
if FLAGS & 0x8000 == 0 then
|
||||||
return false, "Server's flags didn't indicate a response"
|
return false, "Server's flags didn't indicate a response"
|
||||||
end
|
end
|
||||||
if(bit.band(FLAGS, 0x0007) ~= 0) then
|
if FLAGS & 0x0007 ~= 0 then
|
||||||
return false, string.format("Server returned a NetBIOS error: 0x%02x", bit.band(FLAGS, 0x0007))
|
return false, string.format("Server returned a NetBIOS error: 0x%02x", FLAGS & 0x0007)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Start parsing the answer field
|
-- Start parsing the answer field
|
||||||
@@ -462,31 +459,31 @@ end
|
|||||||
--@param flags The 16-bit flags field
|
--@param flags The 16-bit flags field
|
||||||
--@return A string representing the flags
|
--@return A string representing the flags
|
||||||
function flags_to_string(flags)
|
function flags_to_string(flags)
|
||||||
local result = ""
|
local result = {}
|
||||||
|
|
||||||
if(bit.band(flags, 0x8000) ~= 0) then
|
if flags & 0x8000 ~= 0 then
|
||||||
result = result .. "<group>"
|
result[#result+1] = "<group>"
|
||||||
else
|
else
|
||||||
result = result .. "<unique>"
|
result[#result+1] = "<unique>"
|
||||||
end
|
end
|
||||||
|
|
||||||
if(bit.band(flags, 0x1000) ~= 0) then
|
if flags & 0x1000 ~= 0 then
|
||||||
result = result .. "<deregister>"
|
result[#result+1] = "<deregister>"
|
||||||
end
|
end
|
||||||
|
|
||||||
if(bit.band(flags, 0x0800) ~= 0) then
|
if flags & 0x0800 ~= 0 then
|
||||||
result = result .. "<conflict>"
|
result[#result+1] = "<conflict>"
|
||||||
end
|
end
|
||||||
|
|
||||||
if(bit.band(flags, 0x0400) ~= 0) then
|
if flags & 0x0400 ~= 0 then
|
||||||
result = result .. "<active>"
|
result[#result+1] = "<active>"
|
||||||
end
|
end
|
||||||
|
|
||||||
if(bit.band(flags, 0x0200) ~= 0) then
|
if flags & 0x0200 ~= 0 then
|
||||||
result = result .. "<permanent>"
|
result[#result+1] = "<permanent>"
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
return table.concat(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -114,16 +114,8 @@ end
|
|||||||
|
|
||||||
action = function(host)
|
action = function(host)
|
||||||
|
|
||||||
local i
|
|
||||||
local status
|
|
||||||
local names, statistics
|
|
||||||
local server_name, user_name
|
|
||||||
local mac, prefix, manuf
|
|
||||||
local response = {}
|
|
||||||
|
|
||||||
|
|
||||||
-- Get the list of NetBIOS names
|
-- Get the list of NetBIOS names
|
||||||
status, names, statistics = netbios.do_nbstat(host)
|
local status, names, statistics = netbios.do_nbstat(host)
|
||||||
status, names, statistics = netbios.do_nbstat(host)
|
status, names, statistics = netbios.do_nbstat(host)
|
||||||
status, names, statistics = netbios.do_nbstat(host)
|
status, names, statistics = netbios.do_nbstat(host)
|
||||||
status, names, statistics = netbios.do_nbstat(host)
|
status, names, statistics = netbios.do_nbstat(host)
|
||||||
@@ -132,24 +124,28 @@ action = function(host)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Get the server name
|
-- Get the server name
|
||||||
status, server_name = netbios.get_server_name(host, names)
|
local status, server_name = netbios.get_server_name(host, names)
|
||||||
if(status == false) then
|
if(status == false) then
|
||||||
return stdnse.format_output(false, server_name)
|
return stdnse.format_output(false, server_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the workstation name
|
-- Get the workstation name
|
||||||
status, workstation_name = netbios.get_workstation_name(host, names)
|
local status, workstation_name = netbios.get_workstation_name(host, names)
|
||||||
if(status == false) then
|
if(status == false) then
|
||||||
return stdnse.format_output(false, workstation_name)
|
return stdnse.format_output(false, workstation_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get the logged in user
|
-- Get the logged in user
|
||||||
status, user_name = netbios.get_user_name(host, names)
|
local status, user_name = netbios.get_user_name(host, names)
|
||||||
if(status == false) then
|
if(status == false) then
|
||||||
return stdnse.format_output(false, user_name)
|
return stdnse.format_output(false, user_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Format the Mac address in the standard way
|
-- Format the Mac address in the standard way
|
||||||
|
local mac = {
|
||||||
|
address = "<unknown>",
|
||||||
|
manuf = "unknown"
|
||||||
|
}
|
||||||
if(#statistics >= 6) then
|
if(#statistics >= 6) then
|
||||||
local status, mac_prefixes = datafiles.parse_mac_prefixes()
|
local status, mac_prefixes = datafiles.parse_mac_prefixes()
|
||||||
if not status then
|
if not status then
|
||||||
@@ -158,11 +154,10 @@ action = function(host)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- MAC prefixes are matched on the first three bytes, all uppercase
|
-- MAC prefixes are matched on the first three bytes, all uppercase
|
||||||
prefix = string.upper(string.format("%02x%02x%02x", statistics:byte(1), statistics:byte(2), statistics:byte(3)))
|
local prefix = string.upper(string.format("%02x%02x%02x", statistics:byte(1), statistics:byte(2), statistics:byte(3)))
|
||||||
mac = {
|
mac.address = ("%02x:%02x:%02x:%02x:%02x:%02x"):format( statistics:byte(1), statistics:byte(2), statistics:byte(3), statistics:byte(4), statistics:byte(5), statistics:byte(6) )
|
||||||
address = ("%02x:%02x:%02x:%02x:%02x:%02x"):format( statistics:byte(1), statistics:byte(2), statistics:byte(3), statistics:byte(4), statistics:byte(5), statistics:byte(6) ),
|
mac.manuf = mac_prefixes[prefix] or "unknown"
|
||||||
manuf = mac_prefixes[prefix] or "unknown"
|
|
||||||
}
|
|
||||||
host.registry['nbstat'] = {
|
host.registry['nbstat'] = {
|
||||||
server_name = server_name,
|
server_name = server_name,
|
||||||
workstation_name = workstation_name,
|
workstation_name = workstation_name,
|
||||||
@@ -173,11 +168,6 @@ action = function(host)
|
|||||||
mac.address = "<unknown>"
|
mac.address = "<unknown>"
|
||||||
mac.manuf = "unknown"
|
mac.manuf = "unknown"
|
||||||
end
|
end
|
||||||
else
|
|
||||||
mac = {
|
|
||||||
address = "<unknown>",
|
|
||||||
manuf = "unknown"
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
setmetatable(mac, {
|
setmetatable(mac, {
|
||||||
-- MAC is formatted as "00:11:22:33:44:55 (Manufacturer)"
|
-- MAC is formatted as "00:11:22:33:44:55 (Manufacturer)"
|
||||||
@@ -189,6 +179,7 @@ action = function(host)
|
|||||||
user_name = "<unknown>"
|
user_name = "<unknown>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local response = stdnse.output_table()
|
||||||
response["server_name"] = server_name
|
response["server_name"] = server_name
|
||||||
response["workstation_name"] = workstation_name
|
response["workstation_name"] = workstation_name
|
||||||
response["user"] = user_name
|
response["user"] = user_name
|
||||||
|
|||||||
Reference in New Issue
Block a user