diff --git a/nselib/dns.lua b/nselib/dns.lua
index 26c7fe1a4..140ccdc34 100644
--- a/nselib/dns.lua
+++ b/nselib/dns.lua
@@ -278,39 +278,37 @@ local answerFetcher = {}
-- @param dec Decoded DNS response.
-- @param retAll If true, return all entries, not just the first.
-- @return First entry (or all of them), treated as TXT.
-answerFetcher[types.TXT] =
- function(dec, retAll)
- if not retAll then
- return string.sub(dec.answers[1].data, 2)
- else
- local answers = {}
- for _, v in ipairs(dec.answers) do
- if v.data then table.insert(answers, string.sub(v.data, 2)) end
- end
- return answers
+answerFetcher[types.TXT] = function(dec, retAll)
+ if not retAll then
+ return string.sub(dec.answers[1].data, 2)
+ else
+ local answers = {}
+ for _, v in ipairs(dec.answers) do
+ if v.data then table.insert(answers, string.sub(v.data, 2)) end
end
+ return answers
end
+end
---
-- Answer fetcher for A records
-- @param dec Decoded DNS response.
-- @param retAll If true, return all entries, not just the first.
-- @return First IP (or all of them) of response packet.
-answerFetcher[types.A] =
- function(dec, retAll)
- local answers = {}
- for _, ans in ipairs(dec.answers) do
- if ans.dtype == types.A then
- if not retAll then
- return ans.ip
- else
- table.insert(answers, ans.ip)
- end
+answerFetcher[types.A] = function(dec, retAll)
+ local answers = {}
+ for _, ans in ipairs(dec.answers) do
+ if ans.dtype == types.A then
+ if not retAll then
+ return ans.ip
+ else
+ table.insert(answers, ans.ip)
end
end
- if retAll then return answers end
- return dec
end
+ if retAll then return answers end
+ return dec
+end
---
@@ -318,43 +316,56 @@ answerFetcher[types.A] =
-- @param dec Decoded DNS response.
-- @param retAll If true, return all entries, not just the first.
-- @return Domain entry of first answer RR (or all of them) in response packet.
-answerFetcher[types.CNAME] =
- function(dec, retAll)
- if not retAll then
- return dec.answers[1].domain
- else
- local answers = {}
- for _, v in ipairs(dec.answers) do
- if v.domain then table.insert(answers, v.domain) end
- end
- return answers
+answerFetcher[types.CNAME] = function(dec, retAll)
+ if not retAll then
+ return dec.answers[1].domain
+ else
+ local answers = {}
+ for _, v in ipairs(dec.answers) do
+ if v.domain then table.insert(answers, v.domain) end
end
+ return answers
end
+end
---
-- Answer fetcher for MX records.
-- @param dec Decoded DNS response.
-- @param retAll If true, return all entries, not just the first.
-- @return Domain entry of first answer RR (or all of them) in response packet.
-answerFetcher[types.MX] =
- function(dec, retAll)
- if not retAll then
- if dec.answers[1] then
- return dec.answers[1].MX.pref .. ":" .. dec.answers[1].MX.server .. ":" .. dec.add[1].ip
- else
- return dec
- end
+answerFetcher[types.MX] = function(dec, retAll)
+ if not retAll then
+ if dec.answers[1] then
+ return dec.answers[1].MX.pref .. ":" .. dec.answers[1].MX.server .. ":" .. dec.add[1].ip
else
- local answers = {}
- for _, v in ipairs(dec.answers) do
- if v.MX then table.insert(answers, v.MX.pref .. ":" .. v.MX.server .. ":" .. v.MX.ip) end
- end
- return answers
+ return dec
end
+ else
+ local answers = {}
+ for _, v in ipairs(dec.answers) do
+ if v.MX then table.insert(answers, v.MX.pref .. ":" .. v.MX.server .. ":" .. v.MX.ip) end
+ end
+ return answers
end
+end
+---
+-- Answer fetcher for NS records.
+-- @name answerFetcher[types.NS]
+-- @class function
+-- @param dec Decoded DNS response.
+-- @param retAll If true, return all entries, not just the first.
+-- @return Domain entry of first answer RR (or all of them) in response packet.
answerFetcher[types.NS] = answerFetcher[types.CNAME]
+
+---
+-- Answer fetcher for PTR records.
+-- @name answerFetcher[types.PTR]
+-- @class function
+-- @param dec Decoded DNS response.
+-- @param retAll If true, return all entries, not just the first.
+-- @return Domain entry of first answer RR (or all of them) in response packet.
answerFetcher[types.PTR] = answerFetcher[types.CNAME]
---
@@ -362,21 +373,20 @@ answerFetcher[types.PTR] = answerFetcher[types.CNAME]
-- @param dec Decoded DNS response.
-- @param retAll If true, return all entries, not just the first.
-- @return First IPv6 (or all of them) of response packet.
-answerFetcher[types.AAAA] =
- function(dec, retAll)
- local answers = {}
- for _, ans in ipairs(dec.answers) do
- if ans.dtype == types.AAAA then
- if not retAll then
- return ans.ipv6
- else
- table.insert(answers, ans.ipv6)
- end
+answerFetcher[types.AAAA] = function(dec, retAll)
+ local answers = {}
+ for _, ans in ipairs(dec.answers) do
+ if ans.dtype == types.AAAA then
+ if not retAll then
+ return ans.ipv6
+ else
+ table.insert(answers, ans.ipv6)
end
end
- if retAll then return answers end
- return dec
end
+ if retAll then return answers end
+ return dec
+end
---
@@ -516,28 +526,26 @@ local decoder = {}
---
-- Decodes IP of A record, puts it in entry.ip.
-- @param entry RR in packet.
-decoder[types.A] =
- function(entry)
- local ip = {}
- local _
- _, ip[1], ip[2], ip[3], ip[4] = bin.unpack(">C4", entry.data)
- entry.ip = table.concat(ip, ".")
- end
+decoder[types.A] = function(entry)
+ local ip = {}
+ local _
+ _, ip[1], ip[2], ip[3], ip[4] = bin.unpack(">C4", entry.data)
+ entry.ip = table.concat(ip, ".")
+end
---
-- Decodes IP of AAAA record, puts it in entry.ipv6.
-- @param entry RR in packet.
-decoder[types.AAAA] =
- function(entry)
- local ip = {}
- local pos = 1
- local num
- for i = 1, 8 do
- pos, num = bin.unpack(">S", entry.data, pos)
- table.insert(ip, string.format('%x', num))
- end
- entry.ipv6 = table.concat(ip, ":")
+decoder[types.AAAA] = function(entry)
+ local ip = {}
+ local pos = 1
+ local num
+ for i = 1, 8 do
+ pos, num = bin.unpack(">S", entry.data, pos)
+ table.insert(ip, string.format('%x', num))
end
+ entry.ipv6 = table.concat(ip, ":")
+end
---
-- Decodes SSH fingerprint record, puts it in entry.SSHFP as
@@ -546,13 +554,12 @@ decoder[types.AAAA] =
-- entry.SSHFP has the fields algorithm,
-- fptype, and fingerprint.
-- @param entry RR in packet.
-decoder[types.SSHFP] =
- function(entry)
- local _
- entry.SSHFP = {}
- _, entry.SSHFP.algorithm,
- entry.SSHFP.fptype, entry.SSHFP.fingerprint = bin.unpack(">C2H" .. (#entry.data - 2), entry.data)
- end
+decoder[types.SSHFP] = function(entry)
+ local _
+ entry.SSHFP = {}
+ _, entry.SSHFP.algorithm,
+ entry.SSHFP.fptype, entry.SSHFP.fingerprint = bin.unpack(">C2H" .. (#entry.data - 2), entry.data)
+end
---
@@ -564,22 +571,21 @@ decoder[types.SSHFP] =
-- @param entry RR in packet.
-- @param data Complete encoded DNS packet.
-- @param pos Position in packet after RR.
-decoder[types.SOA] =
- function(entry, data, pos)
+decoder[types.SOA] = function(entry, data, pos)
- local np = pos - #entry.data
+ local np = pos - #entry.data
- entry.SOA = {}
+ entry.SOA = {}
- np, entry.SOA.mname = decStr(data, np)
- np, entry.SOA.rname = decStr(data, np)
- np, entry.SOA.serial,
- entry.SOA.refresh,
- entry.SOA.retry,
- entry.SOA.expire,
- entry.SOA.minimum
- = bin.unpack(">I5", data, np)
- end
+ np, entry.SOA.mname = decStr(data, np)
+ np, entry.SOA.rname = decStr(data, np)
+ np, entry.SOA.serial,
+ entry.SOA.refresh,
+ entry.SOA.retry,
+ entry.SOA.expire,
+ entry.SOA.minimum
+ = bin.unpack(">I5", data, np)
+end
---
-- Decodes records that consist only of one domain, for example CNAME, NS, PTR.
@@ -593,12 +599,44 @@ local function decDomain(entry, data, pos)
_, entry.domain = decStr(data, np)
end
+---
+-- Decodes CNAME records.
+-- Puts result in entry.domain.
+-- @name decoder[types.CNAME]
+-- @class function
+-- @param entry RR in packet.
+-- @param data Complete encoded DNS packet.
+-- @param pos Position in packet after RR.
decoder[types.CNAME] = decDomain
+---
+-- Decodes NS records.
+-- Puts result in entry.domain.
+-- @name decoder[types.NS]
+-- @class function
+-- @param entry RR in packet.
+-- @param data Complete encoded DNS packet.
+-- @param pos Position in packet after RR.
decoder[types.NS] = decDomain
+---
+-- Decodes PTR records.
+-- Puts result in entry.domain.
+-- @name decoder[types.PTR]
+-- @class function
+-- @param entry RR in packet.
+-- @param data Complete encoded DNS packet.
+-- @param pos Position in packet after RR.
decoder[types.PTR] = decDomain
+---
+-- Decodes TXT records.
+-- Puts result in entry.domain.
+-- @name decoder[types.TXT]
+-- @class function
+-- @param entry RR in packet.
+-- @param data Complete encoded DNS packet.
+-- @param pos Position in packet after RR.
decoder[types.TXT] = function () end
---
@@ -659,7 +697,7 @@ end
---
-- Decodes DNS flags.
--- @param Flags as a binary digit string.
+-- @param flgStr Flags as a binary digit string.
-- @return Table representing flags.
local function decodeFlags(flgStr)
flags = {}
diff --git a/nselib/nmap.luadoc b/nselib/nmap.luadoc
index 01fb0696b..eb51e35f1 100644
--- a/nselib/nmap.luadoc
+++ b/nselib/nmap.luadoc
@@ -61,7 +61,6 @@ function timing_level()
-- currently scanned group of hosts.
-- @param host Host table, containing an "ip" field.
-- @param port Port table, containing "number" and "protocol" fields.
--- @param protocol Protocol string ("tcp" or "udp")
-- @return A new port table holding the status and information for the port.
-- @usage p = nmap.get_port_state({ip="127.0.0.1"}, {number="80", protocol="tcp"})
function get_port_state(host, port)
@@ -464,10 +463,10 @@ function ethernet_open(interface_name)
--- Sends a raw ethernet frame.
-- \n\n
-- The dnet object must be associated with a previously opened interface. The
--- packet must include the IP and ethernet headers. including IP header and
--- ethernet header. If there was no previous valid call to ethernet_open() an
--- error is thrown ("dnet is not valid opened ethernet interface").
--- @param packet
+-- packet must include the IP and ethernet headers If there was no previous
+-- valid call to ethernet_open() an error is thrown ("dnet is not valid opened
+-- ethernet interface").
+-- @param packet An ethernet frame to send.
-- @see new_dnet
-- @usage dnet:ethernet_open(packet)
function ethernet_send(packet)
diff --git a/nselib/smb.lua b/nselib/smb.lua
index 90584cd38..69c3b56a3 100644
--- a/nselib/smb.lua
+++ b/nselib/smb.lua
@@ -821,9 +821,9 @@ end
--@param name The name to take apart
--@param list [optional] If list is set, names will be added to it then returned
--@return An array of the sub names
-local function get_subnames(name)
+local function get_subnames(name, list)
local i = -1
- local list = {}
+ local list = list or {}
repeat
local subname = name
@@ -1384,7 +1384,7 @@ end
--@param socket The socket
--@param uid The UserID, returned by SMB_COM_SESSION_SETUP_ANDX
--@param tid The TreeID, returned by SMB_COM_TREE_CONNECT_ANDX
---@param return (status, result) If statis is false, result is an error message. If status is true,
+--@return (status, result) If statis is false, result is an error message. If status is true,
-- the disconnect was successful.
function tree_disconnect(socket, uid, tid)
local response = ""
@@ -1420,7 +1420,7 @@ end
---Logs off the current user. Strictly speaking this isn't necessary, but it's the polite thing to do.
--@param socket The socket.
--@param uid The user ID.
---@param return (status, result) If statis is false, result is an error message. If status is true,
+--@return (status, result) If statis is false, result is an error message. If status is true,
-- the logoff was successful.
function logoff(socket, uid)
local header, parameters
@@ -1549,7 +1549,7 @@ end
--@param func The function to call. The only one I've tested is 0x26, named pipes.
--@param function_parameters The parameter data to pass to the function. This is untested, since none of the
-- transactions I've done have required parameters.
---@param data The data to send with the packet. This is basically the next protocol layer
+--@param function_data The data to send with the packet. This is basically the next protocol layer
--@param uid The UserID
--@param tid The TreeID (handle to $IPC)
--@param fid The FileID (opened by create_file)
diff --git a/nselib/snmp.lua b/nselib/snmp.lua
index 968fdb2bf..dc8a644a6 100644
--- a/nselib/snmp.lua
+++ b/nselib/snmp.lua
@@ -415,11 +415,6 @@ end
---
-- Create SNMP Trap PDU
---@param enterpriseOid
---@param agentIp
---@param genTrap
---@param specTrap
---@param timeStamp
--@return Table representing PDU
function buildTrap(enterpriseOid, agentIp, genTrap, specTrap, timeStamp)
local req = {}
diff --git a/nselib/ssh2.lua b/nselib/ssh2.lua
index 898314be7..9a49a286c 100644
--- a/nselib/ssh2.lua
+++ b/nselib/ssh2.lua
@@ -40,7 +40,7 @@ transport.build = function( payload )
end
--- Extract the payload from a received SSH-2 packet.
---@param received SSH2 packet.
+--@param packet received SSH2 packet.
--@return payload of the SSH2 packet.
transport.payload = function( packet )
local packet_length, padding_length, payload_length, payload, offset
diff --git a/nselib/url.lua b/nselib/url.lua
index 7aa486df2..6a1dab920 100644
--- a/nselib/url.lua
+++ b/nselib/url.lua
@@ -23,11 +23,6 @@ _VERSION = "URL 1.0"
--[[ Internal functions --]]
----
--- Protects a path segment, to prevent it from interfering with the
--- url parsing.
--- @param s binary string to be encoded.
--- @return escaped representation of string binary.
local function make_set(t)
local s = {}
for i,v in base.ipairs(t) do
@@ -43,6 +38,11 @@ local segment_set = make_set {
")", ":", "@", "&", "=", "+", "$", ",",
}
+---
+-- Protects a path segment, to prevent it from interfering with the
+-- url parsing.
+-- @param s binary string to be encoded.
+-- @return escaped representation of string binary.
local function protect_segment(s)
return string.gsub(s, "([^A-Za-z0-9_])", function (c)
if segment_set[c] then return c
@@ -205,7 +205,7 @@ end
-- Builds a absolute URL from a base and a relative URL according to RFC 2396.
-- @param base_url a base URL.
-- @param relative_url a relative URL.
--- @param corresponding absolute URL.
+-- @return corresponding absolute URL.
-----------------------------------------------------------------------------
function absolute(base_url, relative_url)
if type(base_url) == "table" then
@@ -332,7 +332,7 @@ end
-- Builds a query string from dictionary based table.
-- \n\n
-- This is the inverse of parse_query.
--- @param dictionary table where table['name'] = value.
+-- @param query dictionary table where table['name'] = value.
-- @return query string (name=value&name=value ...)
-----------------------------------------------------------------------------
function build_query(query)
diff --git a/scripts/whois.nse b/scripts/whois.nse
index 78d4f1047..f9f405b1b 100644
--- a/scripts/whois.nse
+++ b/scripts/whois.nse
@@ -135,6 +135,8 @@ action = function( host )
if not nmap.registry.whois then
---
-- Data and flags shared between threads.\n
+ -- @name whois
+ -- @class table
--@field whoisdb_default_order The default number and order of whois services to query.
--@field using_local_assignments_file Set this to: false; to avoid using the data from IANA hosted assignments files (false when whodb=nofile).
--@field local_assignments_file_expiry A period, between 0 and 7 days, during which cached assignments data may be used without being refreshed.
@@ -145,8 +147,6 @@ action = function( host )
-- returned instead. Set to true when whodb=nofollow
--@field using_cache A flag which modifies the size of ranges in a cache entry. Set to false when whodb=nocache
--@field cache Storage for cached redirects, records and other data for output.
- -- @name whois
- -- @class table
nmap.registry.whois = {}
nmap.registry.whois.whoisdb_default_order = {"arin","ripe","apnic"}
nmap.registry.whois.using_cache = true
@@ -170,6 +170,8 @@ action = function( host )
--\n The table, indexed by whois service id, holds a table of fields captured from each queried service. Once it has been determined that a record
--\n represents the final record we wish to output, the existing values are destroyed and replaced with the one required record. This is done purely
--\n to make it easier to reference the data of a desired record. Other values in the table are as follows\n
+ -- @name data
+ -- @class table
--@field data.iana is set after the table is initialised and is the number of times a response encountered represents "The Whole Address Space".
--\n If the value reaches 2 it is assumed that a valid record is held at ARIN.
--@field data.id is set in analyse_response() after final record and is the service name at which a valid record has been found. Used in
@@ -178,19 +180,17 @@ action = function( host )
-- format_data_for_output().
--@field data.comparison is set in analyse_response() after final record and is a string concatenated from fields extracted from a record and which
-- serves as a fingerprint for a record, used in get_cache_key(), to compare two records for equality.
- -- @name data
- -- @class table
local data = {}
data.iana = 0
---
-- Used in the main loop to manage mutexes, the structure of tracking is as follows:\n
+ -- @name tracking
+ -- @class table
--@field this_db The service for which a thread will wait for exclusive access before sending a query to it.
--@field next_db The next service to query. Allows a thread to continue in the main "while do" loop.
--@field last_db The value of this_db after sending a query, used when exclusive access to a service is no longer required.
--@field completed An array of services previously queried.
- -- @name tracking
- -- @class table
local tracking = {}
tracking.completed = {}
diff --git a/scripts/zoneTrans.nse b/scripts/zoneTrans.nse
index 12c4fe42d..4683153e4 100644
--- a/scripts/zoneTrans.nse
+++ b/scripts/zoneTrans.nse
@@ -187,9 +187,6 @@ function build_domain(host)
end
--- Retrieve type specific data (rdata) from dns packets
---@param data
---@param offset
---@param ttype
function get_rdata(data, offset, ttype)
local field, info, i
@@ -235,9 +232,6 @@ function get_rdata(data, offset, ttype)
end
--- Get a single answer record from the current offset
---@param table
---@param data
---@param offset
function get_answer_record(table, data, offset)
local line, rdlen, ttype