mirror of
https://github.com/nmap/nmap.git
synced 2025-12-15 20:29:03 +00:00
Merge from Dependencies branch (nmap-exp/patrick/dependencies)
with modifications from [2].
** Short description from [1] **
I have created a patch to NSE that replaces runlevels with a table of
dependencies that clearly outlines what other scripts the script
depends on. The table is of the form:
dependences = {"script1", script2", ...}
Runlevels become an internal representation of the order of scripts
that are generated by the dependencies. Dependencies only enforce
an execution order and not a requirement for execution.
[1] http://seclists.org/nmap-dev/2009/q4/295
[2] http://seclists.org/nmap-dev/2009/q4/446
This commit is contained in:
@@ -875,22 +875,64 @@ that.</para>
|
||||
|
||||
</sect2>
|
||||
|
||||
<sect2 id="nse-format-runlevel">
|
||||
<title><literal>runlevel</literal> Field</title>
|
||||
<indexterm><primary sortas="runlevel script variable">“<varname>runlevel</varname>” script variable</primary></indexterm>
|
||||
<indexterm><primary>run level of scripts</primary></indexterm>
|
||||
<para>
|
||||
This optional field determines script execution order. When
|
||||
this section is absent, the run level defaults to 1.0. Scripts with a given <literal>runlevel</literal> execute after any with a lower <literal>runlevel</literal> and before any scripts with a higher <literal>runlevel</literal> against a single target machine. The order of scripts with the same <literal>runlevel</literal> is undefined and they often run concurrently. One
|
||||
application of run levels is allowing scripts to depend on
|
||||
each other. If <literal>script A</literal> relies on some
|
||||
information gathered by <literal>script B</literal>, give
|
||||
<literal>B</literal> a lower run level than
|
||||
<literal>A</literal>. <literal>Script B</literal> can store
|
||||
information in the NSE registry for <literal>A</literal> to
|
||||
retrieve later. For information on the NSE registry, see
|
||||
<xref linkend="nse-api-registry"/>.
|
||||
</para>
|
||||
<sect2 id="nse-format-dependencies">
|
||||
<title><literal>dependencies</literal> Field</title>
|
||||
<indexterm><primary sortas="dependencies script variable">“<varname>dependencies</varname>” script variable</primary></indexterm>
|
||||
<indexterm><primary>script dependencies</primary></indexterm>
|
||||
<para>
|
||||
In earlier versions of NSE, script authors were able to specify a
|
||||
<literal>runlevel</literal> that would specify the execution order of
|
||||
the scripts NSE will run. Scripts that had a smaller runlevel would
|
||||
run before scripts with a larger runlevel. Scripts with an equal
|
||||
runlevel would run concurrently. This method of describing an ordered
|
||||
execution has been replaced by <literal>dependencies</literal>.
|
||||
Dependencies specify other discrete scripts that the script depends on
|
||||
for its execution. A script may need to depend on another script for
|
||||
many reasons. For example, many scripts may rely on authentication
|
||||
credentials discovered by brute-forcing scripts.
|
||||
</para>
|
||||
<para>
|
||||
Scripts may specify an array of script names that the script depends
|
||||
on. When we say "depends on", we mean it in a loose sense. That is, a
|
||||
script will still run despite missing dependencies. Given the
|
||||
dependencies, the script will run after all the scripts listed in the
|
||||
dependencies array. We may specify a dependencies array like so:
|
||||
<programlisting>
|
||||
dependencies = {"script1", "script2"}
|
||||
</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
The dependencies table is an optional script field. NSE will assume
|
||||
the script has no dependencies if the field is omitted.
|
||||
</para>
|
||||
<para>
|
||||
Dependencies offer many advantages over runlevels. First, and
|
||||
obviously, scripts can now specify each script they depend on without
|
||||
worrying about specifying an arbitrary number that is greater than
|
||||
scripts it depends on. Second, scripts no longer limit NSE's ability
|
||||
to intelligently schedule scripts to maximize parallelism. Having
|
||||
unique runlevels would force NSE to schedule the scripts to execute
|
||||
serially.
|
||||
</para>
|
||||
<para>
|
||||
Runlevels are still used as an internal representation of the order of
|
||||
scripts that are automatically generated by the dependencies. When
|
||||
running your scripts you will see each runlevel (and the number of
|
||||
runlevels) grouping of scripts run in NSE's output:
|
||||
<screen>
|
||||
NSE: Script scanning 127.0.0.1.
|
||||
NSE: Starting runlevel 1 (of 3) scan.
|
||||
Initiating NSE at 17:38
|
||||
Completed NSE at 17:38, 0.00s elapsed
|
||||
NSE: Starting runlevel 2 (of 3) scan.
|
||||
Initiating NSE at 17:38
|
||||
Completed NSE at 17:38, 0.00s elapsed
|
||||
NSE: Starting runlevel 3 (of 3) scan.
|
||||
Initiating NSE at 17:38
|
||||
Completed NSE at 17:38, 0.00s elapsed
|
||||
NSE: Script Scanning completed.
|
||||
</screen>
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2 id="nse-format-rules">
|
||||
|
||||
Reference in New Issue
Block a user