Library ls

Report file and directory listings.

For scripts that gather and report directory listings, this script provides a common output format and helpful script arguments.

The arguments can either be set for all the scripts using this module (--script-args ls.arg=value) or for one particular script (--script-args afp-ls.arg=value). If both are specified for the same argument, the script-specific value is used.

Author:

  • Pierre Lalet <pierre@droids-corp.org>

Copyright © Same as Nmap--See https://nmap.org/book/man-legal.html

Source: https://svn.nmap.org/nmap/nselib/ls.lua

Script Arguments

ls.errors

(boolean) Report errors

ls.human

(boolean) Show file sizes in human-readable format with K, M, G, T, P suffixes. Some services return human-readable sizes natively; in these cases, the size is reported as given.

ls.maxdepth

The maximum depth to recurse into a directory. If less than 0 (e.g. -1) then recursion is unlimited. (default: 0, no recursion).

ls.empty

(boolean) Report empty volumes (with no information or error)

ls.checksum

(boolean) Download each file and calculate a SHA1 checksum. Although this is a module argument, the implementation is done in each script and is currently only supported by smb-ls and http-ls

ls.maxfiles

The maximum number of files to return. Set to 0 or less to disable this limit. (default: 10).

Functions

add_file (output, file)

Add a new file to the current volume.

config (argname)

Get a config value from (by order or priority): 1. a script-specific argument (e.g., http-ls.argname) 2. a module argument (ls.argname) 3. the default value

end_listing (output)

Close current listing. Return both the structured and the human readable outputs.

end_vol (output)

Close the current volume. It is mandatory to call this function before calling new_vol() again or before calling end_listing().

new_listing ()

Create a new script output.

new_vol (output, name, hasperms)

Create a new volume within the provided output

report_error (output, err, level)

Report an error, using stdnse.debug() and (depending on the configuration settings) adding the error message to the output.

report_info (output, info, level)

Report information, using stdnse.debug() and adding the message to the output.

Functions

add_file (output, file)

Add a new file to the current volume.

Parameters

output
The ls output object, from new_listing()
file
A table containing the information about the file

Return value:

Boolean true if the script may continue adding files, false if maxfiles has been reached.
config (argname)

Get a config value from (by order or priority): 1. a script-specific argument (e.g., http-ls.argname) 2. a module argument (ls.argname) 3. the default value

Parameters

argname
The name of the configuration parameter

Return value:

The configuration value
end_listing (output)

Close current listing. Return both the structured and the human readable outputs.

Parameters

output
The ls output object, from new_listing()

Return values:

  1. Structured output
  2. Human readable output
end_vol (output)

Close the current volume. It is mandatory to call this function before calling new_vol() again or before calling end_listing().

Parameters

output
The ls output object, from new_listing()
new_listing ()

Create a new script output.

Return value:

The ls output object to be passed to other functions
new_vol (output, name, hasperms)

Create a new volume within the provided output

Parameters

output
The ls output object, from new_listing()
name
The name of the volume
hasperms
Boolean true if the volume listing will include permissions
report_error (output, err, level)

Report an error, using stdnse.debug() and (depending on the configuration settings) adding the error message to the output.

Parameters

output
The ls output object, from new_listing()
err
The error message to report
level
The debug level (default: 1)
report_info (output, info, level)

Report information, using stdnse.debug() and adding the message to the output.

Parameters

output
The ls output object, from new_listing()
info
The info message to report
level
The debug level (default: 1)