mirror of
https://github.com/nmap/nmap.git
synced 2025-12-20 06:29:02 +00:00
Re-indent some libs and scripts, change 4 to 2-space indent
Mostly found with:
for i in nselib/*.lua scripts/*.nse; do
echo $(perl -lne 'BEGIN{$a=$p=0}next unless $_;/^(\s*)/;' \
-e '$l=length$1;next if$l==$p;$a+=(abs($l-$p)-$a)/$.;' \
-e '$p=$l;END{print$a}' $i) $i
done | sort -nr
And indented with: https://gist.github.com/bonsaiviking/8845871
whois-ip.nse was particularly mangled (probably my fault due to using
vim's built-in indentation script, but it could be structured better)
This commit is contained in:
@@ -112,7 +112,7 @@ RPC_args = {
|
|||||||
-- TCP appears to be more stable than UDP in most cases, so try it first
|
-- TCP appears to be more stable than UDP in most cases, so try it first
|
||||||
local RPC_PROTOCOLS = (nmap.registry.args and nmap.registry.args[RPC_args['rpcbind'].proto] and
|
local RPC_PROTOCOLS = (nmap.registry.args and nmap.registry.args[RPC_args['rpcbind'].proto] and
|
||||||
type(nmap.registry.args[RPC_args['rpcbind'].proto]) == 'table') and
|
type(nmap.registry.args[RPC_args['rpcbind'].proto]) == 'table') and
|
||||||
nmap.registry.args[RPC_args['rpcbind'].proto] or { "tcp", "udp" }
|
nmap.registry.args[RPC_args['rpcbind'].proto] or { "tcp", "udp" }
|
||||||
|
|
||||||
-- used to cache the contents of the rpc datafile
|
-- used to cache the contents of the rpc datafile
|
||||||
local RPC_PROGRAMS
|
local RPC_PROGRAMS
|
||||||
|
|||||||
@@ -146,8 +146,8 @@ action = function(host, port)
|
|||||||
description = [[
|
description = [[
|
||||||
vsFTPd version 2.3.4 backdoor, this was reported on 2011-07-04.]],
|
vsFTPd version 2.3.4 backdoor, this was reported on 2011-07-04.]],
|
||||||
references = {
|
references = {
|
||||||
'http://scarybeastsecurity.blogspot.com/2011/07/alert-vsftpd-download-backdoored.html',
|
'http://scarybeastsecurity.blogspot.com/2011/07/alert-vsftpd-download-backdoored.html',
|
||||||
'https://dev.metasploit.com/redmine/projects/framework/repository/revisions/13093',
|
'https://dev.metasploit.com/redmine/projects/framework/repository/revisions/13093',
|
||||||
},
|
},
|
||||||
dates = {
|
dates = {
|
||||||
disclosure = {year = '2011', month = '07', day = '03'},
|
disclosure = {year = '2011', month = '07', day = '03'},
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ end
|
|||||||
-- These are the subject/issuer name fields that will be shown, in this order,
|
-- These are the subject/issuer name fields that will be shown, in this order,
|
||||||
-- without a high verbosity.
|
-- without a high verbosity.
|
||||||
local NON_VERBOSE_FIELDS = { "commonName", "organizationName",
|
local NON_VERBOSE_FIELDS = { "commonName", "organizationName",
|
||||||
"stateOrProvinceName", "countryName" }
|
"stateOrProvinceName", "countryName" }
|
||||||
|
|
||||||
function stringify_name(name)
|
function stringify_name(name)
|
||||||
local fields = {}
|
local fields = {}
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ action = function( host )
|
|||||||
if not status then
|
if not status then
|
||||||
stdnse.print_debug( "%s %s pcall caught an exception in get_next_action: %s.", SCRIPT_NAME, host.ip, retval )
|
stdnse.print_debug( "%s %s pcall caught an exception in get_next_action: %s.", SCRIPT_NAME, host.ip, retval )
|
||||||
if not tracking.last_db then tracking.last_db, tracking.this_db = tracking.this_db or tracking.next_db, nil end
|
if not tracking.last_db then tracking.last_db, tracking.this_db = tracking.this_db or tracking.next_db, nil end
|
||||||
else tracking = retval end
|
else tracking = retval end
|
||||||
end
|
end
|
||||||
|
|
||||||
nmap.registry.whois.mutex[tracking.last_db] "done"
|
nmap.registry.whois.mutex[tracking.last_db] "done"
|
||||||
@@ -1642,18 +1642,18 @@ function script_init( )
|
|||||||
|
|
||||||
nmap.registry.whois.init_done = true
|
nmap.registry.whois.init_done = true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Parses the command line arguments passed to the script with --script-args.
|
-- Parses the command line arguments passed to the script with --script-args.
|
||||||
-- Sets flags in the registry which threads read to determine certain behaviours.
|
-- Sets flags in the registry which threads read to determine certain behaviours.
|
||||||
-- Permitted args are 'nofile' - Prevents use of a list of assignments to determine which service to query,
|
-- Permitted args are 'nofile' - Prevents use of a list of assignments to determine which service to query,
|
||||||
-- 'nofollow' - Prevents following redirects found in records,
|
-- 'nofollow' - Prevents following redirects found in records,
|
||||||
-- 'arin', 'ripe', 'apnic', etc. - Service id's, as defined in the whoisdb table in the registry (see script_init).
|
-- 'arin', 'ripe', 'apnic', etc. - Service id's, as defined in the whoisdb table in the registry (see script_init).
|
||||||
|
|
||||||
function get_args()
|
function get_args()
|
||||||
|
|
||||||
if not nmap.registry.args then return end
|
if not nmap.registry.args then return end
|
||||||
|
|
||||||
@@ -1696,22 +1696,22 @@ function script_init( )
|
|||||||
stdnse.print_debug( 2, "%s: whoisdb_default_order: %s.", SCRIPT_NAME, table.concat( t, " " ) )
|
stdnse.print_debug( 2, "%s: whoisdb_default_order: %s.", SCRIPT_NAME, table.concat( t, " " ) )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Makes IANA hosted assignments data available for lookups against that data. In more detail it:
|
-- Makes IANA hosted assignments data available for lookups against that data. In more detail it:
|
||||||
-- Caches a local copy of remote assignments data if copies do not currently exist or are out-of-date.
|
-- Caches a local copy of remote assignments data if copies do not currently exist or are out-of-date.
|
||||||
-- Checks whether the cached copies require updating and performs update as required.
|
-- Checks whether the cached copies require updating and performs update as required.
|
||||||
-- Parses the cached copies and populates a table of lookup data which is returned to the caller.
|
-- Parses the cached copies and populates a table of lookup data which is returned to the caller.
|
||||||
-- Sets a flag in the registry to prevent use of the lookup data in the event of an error.
|
-- Sets a flag in the registry to prevent use of the lookup data in the event of an error.
|
||||||
-- @return Table of lookup data (or nil in case of an error).
|
-- @return Table of lookup data (or nil in case of an error).
|
||||||
-- @return Nil or error message in case of an error.
|
-- @return Nil or error message in case of an error.
|
||||||
-- @see get_parentpath, file_exists, requires_updating, read_from_file, conditional_download,
|
-- @see get_parentpath, file_exists, requires_updating, read_from_file, conditional_download,
|
||||||
-- write_to_file, parse_assignments
|
-- write_to_file, parse_assignments
|
||||||
|
|
||||||
function get_local_assignments_data()
|
function get_local_assignments_data()
|
||||||
|
|
||||||
if not next( nmap.registry.whois.remote_assignments_files ) then
|
if not next( nmap.registry.whois.remote_assignments_files ) then
|
||||||
nmap.registry.whois.using_local_assignments_file = false
|
nmap.registry.whois.using_local_assignments_file = false
|
||||||
@@ -1825,17 +1825,17 @@ function script_init( )
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Uses <code>nmap.fetchfile</code> to get the path of the parent directory of the supplied Nmap datafile SCRIPT_NAME.
|
-- Uses <code>nmap.fetchfile</code> to get the path of the parent directory of the supplied Nmap datafile SCRIPT_NAME.
|
||||||
-- @param fname String - Filename of an Nmap datafile.
|
-- @param fname String - Filename of an Nmap datafile.
|
||||||
-- @return String - The filepath of the directory containing the supplied SCRIPT_NAME including the trailing slash (or nil in case of an error).
|
-- @return String - The filepath of the directory containing the supplied SCRIPT_NAME including the trailing slash (or nil in case of an error).
|
||||||
-- @return Nil or error message in case of an error.
|
-- @return Nil or error message in case of an error.
|
||||||
|
|
||||||
function get_parentpath( fname )
|
function get_parentpath( fname )
|
||||||
|
|
||||||
if type( fname ) ~= "string" or fname == "" then
|
if type( fname ) ~= "string" or fname == "" then
|
||||||
return nil, "Error in get_parentpath: Expected fname as a string."
|
return nil, "Error in get_parentpath: Expected fname as a string."
|
||||||
@@ -1849,17 +1849,17 @@ function script_init( )
|
|||||||
path = path:sub( 1, path:len() - fname:len() )
|
path = path:sub( 1, path:len() - fname:len() )
|
||||||
return path
|
return path
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Given a filepath, checks for the existence of that file.
|
-- Given a filepath, checks for the existence of that file.
|
||||||
-- @param file Path to a file.
|
-- @param file Path to a file.
|
||||||
-- @return Boolean True if file exists and can be read or false if file does not exist or is empty or cannot be otherwise read.
|
-- @return Boolean True if file exists and can be read or false if file does not exist or is empty or cannot be otherwise read.
|
||||||
-- @return Nil or error message. No error message if the file is empty or does not exist, only if the file cannot be read for some other reason.
|
-- @return Nil or error message. No error message if the file is empty or does not exist, only if the file cannot be read for some other reason.
|
||||||
|
|
||||||
function file_exists( file )
|
function file_exists( file )
|
||||||
|
|
||||||
local f, err, _ = io.open( file, "r" )
|
local f, err, _ = io.open( file, "r" )
|
||||||
if ( f and f:read() ) then
|
if ( f and f:read() ) then
|
||||||
@@ -1876,23 +1876,23 @@ function script_init( )
|
|||||||
return false, ( "unforseen error while checking " .. file )
|
return false, ( "unforseen error while checking " .. file )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Checks whether a cached file requires updating via HTTP.
|
-- Checks whether a cached file requires updating via HTTP.
|
||||||
-- The cached file should contain the following string on the second line: "<timestamp><Last-Modified-Date><Entity-Tag>".
|
-- The cached file should contain the following string on the second line: "<timestamp><Last-Modified-Date><Entity-Tag>".
|
||||||
-- where timestamp is number of seconds since epoch at the time the file was last cached and
|
-- where timestamp is number of seconds since epoch at the time the file was last cached and
|
||||||
-- Last-Modified-Date is an HTTP compliant date sting returned by an HTTP server at the time the file was last cached and
|
-- Last-Modified-Date is an HTTP compliant date sting returned by an HTTP server at the time the file was last cached and
|
||||||
-- Entity-Tag is an HTTP Etag returned by an HTTP server at the time the file was last cached.
|
-- Entity-Tag is an HTTP Etag returned by an HTTP server at the time the file was last cached.
|
||||||
-- @param file Filepath of the cached file.
|
-- @param file Filepath of the cached file.
|
||||||
-- @return Boolean False if file does not require updating, true otherwise.
|
-- @return Boolean False if file does not require updating, true otherwise.
|
||||||
-- @return nil or a valid modified-date (string).
|
-- @return nil or a valid modified-date (string).
|
||||||
-- @return nil or a valid entity_tag (string).
|
-- @return nil or a valid entity_tag (string).
|
||||||
-- @see file_is_expired
|
-- @see file_is_expired
|
||||||
|
|
||||||
function requires_updating( file )
|
function requires_updating( file )
|
||||||
|
|
||||||
local last_cached, mod, etag, has_expired
|
local last_cached, mod, etag, has_expired
|
||||||
|
|
||||||
@@ -1925,17 +1925,17 @@ function script_init( )
|
|||||||
|
|
||||||
return has_expired, mod, etag
|
return has_expired, mod, etag
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Reads a file, line by line, into a table.
|
-- Reads a file, line by line, into a table.
|
||||||
-- @param file String representing a filepath.
|
-- @param file String representing a filepath.
|
||||||
-- @return Table (array-style) of lines read from the file (or nil in case of an error).
|
-- @return Table (array-style) of lines read from the file (or nil in case of an error).
|
||||||
-- @return Nil or error message in case of an error.
|
-- @return Nil or error message in case of an error.
|
||||||
|
|
||||||
function read_from_file( file )
|
function read_from_file( file )
|
||||||
|
|
||||||
if type( file ) ~= "string" or file == "" then
|
if type( file ) ~= "string" or file == "" then
|
||||||
return nil, "Error in read_from_file: Expected file as a string."
|
return nil, "Error in read_from_file: Expected file as a string."
|
||||||
@@ -1958,21 +1958,21 @@ function script_init( )
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Performs either an HTTP Conditional GET request if mod_date or e_tag is passed, or a plain GET request otherwise.
|
-- Performs either an HTTP Conditional GET request if mod_date or e_tag is passed, or a plain GET request otherwise.
|
||||||
-- Will follow a single redirect for the remote resource.
|
-- Will follow a single redirect for the remote resource.
|
||||||
-- @param url String representing the full URL of the remote resource.
|
-- @param url String representing the full URL of the remote resource.
|
||||||
-- @param mod_date String representing an HTTP date.
|
-- @param mod_date String representing an HTTP date.
|
||||||
-- @param e_tag String representing an HTTP entity tag.
|
-- @param e_tag String representing an HTTP entity tag.
|
||||||
-- @return Table as per <code>http.request</code> or <code>nil</code> in case of a non-HTTP error.
|
-- @return Table as per <code>http.request</code> or <code>nil</code> in case of a non-HTTP error.
|
||||||
-- @return Nil or error message in case of an error.
|
-- @return Nil or error message in case of an error.
|
||||||
-- @see http.request
|
-- @see http.request
|
||||||
|
|
||||||
function conditional_download( url, mod_date, e_tag )
|
function conditional_download( url, mod_date, e_tag )
|
||||||
|
|
||||||
if type( url ) ~= "string" or url == "" then
|
if type( url ) ~= "string" or url == "" then
|
||||||
return nil, "Error in conditional_download: Expected url as a string."
|
return nil, "Error in conditional_download: Expected url as a string."
|
||||||
@@ -2007,19 +2007,19 @@ function script_init( )
|
|||||||
|
|
||||||
return request_response
|
return request_response
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Writes the supplied content to file.
|
-- Writes the supplied content to file.
|
||||||
-- @param file String representing a filepath (if it exists it will be overwritten).
|
-- @param file String representing a filepath (if it exists it will be overwritten).
|
||||||
-- @param content String or table of data to write to file. Empty string or table is permitted.
|
-- @param content String or table of data to write to file. Empty string or table is permitted.
|
||||||
-- A table will be written to file with each element of the table on a new line.
|
-- A table will be written to file with each element of the table on a new line.
|
||||||
-- @return Boolean True on success or nil in case of an error.
|
-- @return Boolean True on success or nil in case of an error.
|
||||||
-- @return Nil or error message in case of an error.
|
-- @return Nil or error message in case of an error.
|
||||||
|
|
||||||
function write_to_file( file, content )
|
function write_to_file( file, content )
|
||||||
|
|
||||||
if type( file ) ~= "string" or file == "" then
|
if type( file ) ~= "string" or file == "" then
|
||||||
return nil, "Error in write_to_file: Expected file as a string."
|
return nil, "Error in write_to_file: Expected file as a string."
|
||||||
@@ -2043,18 +2043,18 @@ function script_init( )
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Converts raw data from an assignments file into a form optimised for lookups against that data.
|
-- Converts raw data from an assignments file into a form optimised for lookups against that data.
|
||||||
-- @param address_family_spec Table (assoc. array) containing patterns for extracting data.
|
-- @param address_family_spec Table (assoc. array) containing patterns for extracting data.
|
||||||
-- @param table_of_lines Table containing a line of data per table element.
|
-- @param table_of_lines Table containing a line of data per table element.
|
||||||
-- @return Table - each element of the form { range = { first = data, last = data }, service = data } (or nil in case of an error).
|
-- @return Table - each element of the form { range = { first = data, last = data }, service = data } (or nil in case of an error).
|
||||||
-- @return Nil or error message in case of an error.
|
-- @return Nil or error message in case of an error.
|
||||||
|
|
||||||
function parse_assignments( address_family_spec, table_of_lines )
|
function parse_assignments( address_family_spec, table_of_lines )
|
||||||
|
|
||||||
if #table_of_lines < 1 then
|
if #table_of_lines < 1 then
|
||||||
return nil, "Error in parse_assignments: Expected table_of_lines as a non-empty table."
|
return nil, "Error in parse_assignments: Expected table_of_lines as a non-empty table."
|
||||||
@@ -2088,18 +2088,18 @@ function script_init( )
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Checks the age of the supplied timestamp and compares it to the value of local_assignments_file_expiry.
|
-- Checks the age of the supplied timestamp and compares it to the value of local_assignments_file_expiry.
|
||||||
-- @param time_string String representing a timestamp (seconds since epoch).
|
-- @param time_string String representing a timestamp (seconds since epoch).
|
||||||
-- @return Boolean True if the period elapsed since the timestamp is longer than the value of local_assignments_file_expiry
|
-- @return Boolean True if the period elapsed since the timestamp is longer than the value of local_assignments_file_expiry
|
||||||
-- also returns true if the parameter is not of the expected type, otherwise returns false.
|
-- also returns true if the parameter is not of the expected type, otherwise returns false.
|
||||||
-- @see sane_expiry_period
|
-- @see sane_expiry_period
|
||||||
|
|
||||||
function file_is_expired( time_string )
|
function file_is_expired( time_string )
|
||||||
|
|
||||||
if type( time_string ) ~= "string" or time_string == "" then return true end
|
if type( time_string ) ~= "string" or time_string == "" then return true end
|
||||||
local allowed_age = nmap.registry.whois.local_assignments_file_expiry
|
local allowed_age = nmap.registry.whois.local_assignments_file_expiry
|
||||||
@@ -2114,17 +2114,17 @@ function script_init( )
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Checks that the supplied string represents a period of time between 0 and 7 days.
|
-- Checks that the supplied string represents a period of time between 0 and 7 days.
|
||||||
-- @param period String representing a period.
|
-- @param period String representing a period.
|
||||||
-- @return Number representing the supplied period or a failsafe period in whole seconds.
|
-- @return Number representing the supplied period or a failsafe period in whole seconds.
|
||||||
-- @see get_period
|
-- @see get_period
|
||||||
|
|
||||||
function sane_expiry_period( period )
|
function sane_expiry_period( period )
|
||||||
|
|
||||||
local sane_default_expiry = 57600 -- 16h
|
local sane_default_expiry = 57600 -- 16h
|
||||||
local max_expiry = 604800 -- 7d
|
local max_expiry = 604800 -- 7d
|
||||||
@@ -2135,20 +2135,20 @@ function script_init( )
|
|||||||
if period < max_expiry then return period end
|
if period < max_expiry then return period end
|
||||||
return max_expiry
|
return max_expiry
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Converts a string representing a period of time made up of a quantity and a unit such as "24h"
|
-- Converts a string representing a period of time made up of a quantity and a unit such as "24h"
|
||||||
-- into whole seconds.
|
-- into whole seconds.
|
||||||
-- @param period String combining a quantity and a unit of time.
|
-- @param period String combining a quantity and a unit of time.
|
||||||
-- Acceptable units are days (D or d), hours (H or h), minutes (M or m) and seconds (S or s).
|
-- Acceptable units are days (D or d), hours (H or h), minutes (M or m) and seconds (S or s).
|
||||||
-- If a unit is not supplied or not one of the above acceptable units, it is assumed to be seconds.
|
-- If a unit is not supplied or not one of the above acceptable units, it is assumed to be seconds.
|
||||||
-- Negative or fractional periods are permitted.
|
-- Negative or fractional periods are permitted.
|
||||||
-- @return Number representing the supplied period in whole seconds (or nil in case of an error).
|
-- @return Number representing the supplied period in whole seconds (or nil in case of an error).
|
||||||
|
|
||||||
function get_period( period )
|
function get_period( period )
|
||||||
|
|
||||||
if type( period ) ~= string or ( period == "" ) then return nil end
|
if type( period ) ~= string or ( period == "" ) then return nil end
|
||||||
local quant, unit = period:match( "(-?+?%d*%.?%d*)([SsMmHhDd]?)" )
|
local quant, unit = period:match( "(-?+?%d*%.?%d*)([SsMmHhDd]?)" )
|
||||||
@@ -2167,18 +2167,18 @@ function script_init( )
|
|||||||
|
|
||||||
return ( math.modf( quant * unit ) )
|
return ( math.modf( quant * unit ) )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Passed to <code>table.sort</code>, will sort a table of IP assignments such that sub-assignments appear before their parent.
|
-- Passed to <code>table.sort</code>, will sort a table of IP assignments such that sub-assignments appear before their parent.
|
||||||
-- This function is not in use at the moment (see get_local_assignments_data) and will not appear in nse documentation.
|
-- This function is not in use at the moment (see get_local_assignments_data) and will not appear in nse documentation.
|
||||||
-- @param first Table { range = { first = IP_addr, last = IP_addr } }
|
-- @param first Table { range = { first = IP_addr, last = IP_addr } }
|
||||||
-- @param second Table { range = { first = IP_addr, last = IP_addr } }
|
-- @param second Table { range = { first = IP_addr, last = IP_addr } }
|
||||||
-- @return Boolean True if the tables are already in the correct order, otherwise false.
|
-- @return Boolean True if the tables are already in the correct order, otherwise false.
|
||||||
|
|
||||||
function sort_assignments( first, second )
|
function sort_assignments( first, second )
|
||||||
|
|
||||||
local f_lo, f_hi = first.range.first, first.range.last
|
local f_lo, f_hi = first.range.first, first.range.last
|
||||||
local s_lo, s_hi = second.range.first, second.range.last
|
local s_lo, s_hi = second.range.first, second.range.last
|
||||||
@@ -2190,4 +2190,4 @@ function script_init( )
|
|||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user