Skip to content

Commit

Permalink
o Added the new --script-args-file option which allows you to specify
Browse files Browse the repository at this point in the history
  the name of a file containing all of your desired NSE script
  arguments.  The arguments may be separated with commas or newlines
  and may be overridden by arguments specified on the command-line
  with --script-args. [Daniel Miller]
  • Loading branch information
fyodor committed Jan 3, 2012
1 parent 27aec63 commit bb62bab
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Nmap Changelog ($Id$); -*-text-*-

o Added the new --script-args-file option which allows you to specify
the name of a file containing all of your desired NSE script
arguments. The arguments may be separated with commas or newlines
and may be overridden by arguments specified on the command-line
with --script-args. [Daniel Miller]

o [NSE] Added the script http-vuln-cve2009-3960 that detects and exploits the
CVE 2009-3960 XML injection vulnerability in Adobe products. [Hani
Benhabiles]
Expand Down
1 change: 1 addition & 0 deletions NmapOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ class NmapOps {
#ifndef NOLUA
int script;
char *scriptargs;
char *scriptargsfile;
int scriptversion;
int scripttrace;
int scriptupdatedb;
Expand Down
12 changes: 9 additions & 3 deletions docs/nmap.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: nmap
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
.\" Date: 01/01/2012
.\" Date: 01/02/2012
.\" Manual: Nmap Reference Guide
.\" Source: Nmap
.\" Language: English
.\"
.TH "NMAP" "1" "01/01/2012" "Nmap" "Nmap Reference Guide"
.TH "NMAP" "1" "01/02/2012" "Nmap" "Nmap Reference Guide"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -1358,6 +1358,13 @@ pairs\&. Names and values may be strings not containing whitespace or the charac
The online NSE Documentation Portal at
\m[blue]\fB\%http://nmap.org/nsedoc/\fR\m[]
lists the arguments that each script accepts\&.
.RE
.PP
\fB\-\-script\-args\-file \fR\fB\fIfilename\fR\fR .\" --script-args-file .\" script arguments from file
.RS 4
Lets you load arguments to NSE scripts from a file\&. Any arguments on the command line supersede ones in the file\&. The file can be an absolute path, or a path relative to Nmap\*(Aqs usual search path (NMAPDIR, etc\&.) Arguments can be comma\-separated or newline\-separated, but otherwise follow the same rules as for
\fB\-\-script\-args\fR, without requiring special quoting and escaping, since they are not parsed by the shell\&.
.RE
.PP
\fB\-\-script\-help \fR\fB\fIfilename\fR\fR\fB|\fR\fB\fIcategory\fR\fR\fB|\fR\fB\fIdirectory\fR\fR\fB|\fR\fB\fIexpression\fR\fR\fB|all\fR\fB[,\&.\&.\&.]\fR .\" --script-help
.RS 4
Expand All @@ -1368,7 +1375,6 @@ script, you would run
\fBnmap \-\-script\-help ftp\-anon\fR\&. In addition to getting help for individual scripts, you can use this as a preview of what scripts will be run for a specification, for example with
\fBnmap \-\-script\-help default\fR\&.
.RE
.RE
.PP
\fB\-\-script\-trace\fR .\" --script-trace
.RS 4
Expand Down
18 changes: 17 additions & 1 deletion docs/refguide.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,24 @@ The online NSE Documentation Portal at <ulink url="http://nmap.org/nsedoc/"/>
lists the arguments that each script accepts.
</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--script-args-file <replaceable>filename</replaceable></option>
<indexterm significance="preferred"><primary><option>--script-args-file</option></primary></indexterm>
<indexterm><primary>script arguments from file</primary><seealso><option>--script-args-file</option></seealso></indexterm></term>

<listitem>
<para>
Lets you load arguments to NSE scripts from a file. Any arguments on the
command line supersede ones in the file. The file can be an absolute path,
or a path relative to Nmap's usual search path (NMAPDIR, etc.)
Arguments can be comma-separated or newline-separated, but otherwise follow
the same rules as for <option>--script-args</option>, without requiring
special quoting and escaping, since they are not parsed by the shell.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--script-help <replaceable>filename</replaceable>|<replaceable>category</replaceable>|<replaceable>directory</replaceable>|<replaceable>expression</replaceable>|all<optional>,...</optional></option>
Expand All @@ -2431,7 +2448,6 @@ lists the arguments that each script accepts.
</listitem>
</varlistentry>

</varlistentry>
<varlistentry>
<term><option>--script-trace</option>
<indexterm significance="preferred"><primary><option>--script-trace</option></primary></indexterm></term>
Expand Down
27 changes: 25 additions & 2 deletions docs/scripting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ Black Hat Briefings in 2010.</para>
execute by providing categories, script file names, or the name of
directories full of scripts you wish to execute. You can customize
some scripts by providing arguments to them via the
<option>--script-args</option><indexterm><primary><option>--script-args</option></primary></indexterm>
option.
<option>--script-args</option><indexterm><primary><option>--script-args</option></primary></indexterm> and <option>--script-args-file</option><indexterm><primary><option>--script-args-file</option></primary></indexterm>
options.
The <option>--script-help</option><indexterm><primary><option>--script-help</option></primary></indexterm>
shows a description of what each selected script does.
The two remaining options,
Expand Down Expand Up @@ -702,6 +702,20 @@ Nmap script database, but should be used cautiously since Nmap may contain explo
</listitem>
</varlistentry>

<varlistentry>
<term>
<indexterm><primary><option>--script-args-file</option></primary></indexterm>
<option>--script-args-file <replaceable>filename</replaceable></option>
</term>
<listitem>
<para>This option is the same as
<option>--script-args</option> except that you pass the
arguments in a file rather than on the command-line. See
<xref linkend="nse-args"/> for a detailed
explanation.</para>
</listitem>
</varlistentry>

<varlistentry>
<term>
<indexterm><primary><option>--script-help</option></primary></indexterm>
Expand Down Expand Up @@ -971,6 +985,15 @@ http://nmap.org/nsedoc/scripts/afp-showmount.html
the <varname>whois</varname> table in the example below.
</para>

<para>Rather than pass the arguments on the command line with
<option>--script-args</option>, you may store them in a file
(separated by commas or newlines) and specify just the file name
with <option>--script-args-file</option>. Options specified
with <option>--script-args</option> on the command-line take
precedence over those given in a file. The filename may be
given as an absolute path or relative to Nmap's usual
search path (NMAPDIR, etc.)

<para>Here is a typical Nmap invocation with script arguments:
<informalexample>
<indexterm><primary><option>--script-args</option></primary><secondary>example of</secondary></indexterm>
Expand Down
4 changes: 4 additions & 0 deletions nmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ void parse_options(int argc, char **argv) {
{"script_updatedb", no_argument, 0, 0},
{"script-args",required_argument,0,0},
{"script_args",required_argument,0,0},
{"script-args-file",required_argument,0,0},
{"script_args_file",required_argument,0,0},
{"script-help",required_argument,0,0},
{"script_help",required_argument,0,0},
#endif
Expand Down Expand Up @@ -657,6 +659,8 @@ void parse_options(int argc, char **argv) {
o.chooseScripts(optarg);
} else if (optcmp(long_options[option_index].name,"script-args")==0){
o.scriptargs=strdup(optarg);
} else if (optcmp(long_options[option_index].name,"script-args-file")==0){
o.scriptargsfile=strdup(optarg);
} else if (optcmp(long_options[option_index].name, "script-trace") == 0) {
o.scripttrace = 1;
} else if (optcmp(long_options[option_index].name, "script-updatedb") == 0){
Expand Down
1 change: 1 addition & 0 deletions nse_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ static void open_cnse (lua_State *L)
setbfield(L, -1, "scripthelp", o.scripthelp);
setsfield(L, -1, "script_dbpath", SCRIPT_ENGINE_DATABASE);
setsfield(L, -1, "scriptargs", o.scriptargs);
setsfield(L, -1, "scriptargsfile", o.scriptargsfile);
setsfield(L, -1, "NMAP_URL", NMAP_URL);
}

Expand Down
13 changes: 13 additions & 0 deletions nse_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,19 @@ do -- Load script arguments (--script-args)
end
end
nmap.registry.args = parse_table("{"..args.."}", 1);
-- Check if user wants to read scriptargs from a file
if cnse.scriptargsfile ~= nil then --scriptargsfile path/to/file
local t, path = cnse.fetchfile_absolute(cnse.scriptargsfile)
assert(t == 'file', format("%s is not a file", path))
local argfile = assert(open(path, 'r'));
local argstring = argfile:read("*a")
argstring = gsub(argstring,"\n",",")
local tmpargs = parse_table("{"..argstring.."}",1)
for k,v in pairs(nmap.registry.args) do
tmpargs[k] = v
end
nmap.registry.args = tmpargs
end
end

-- Update Missing Script Database?
Expand Down

0 comments on commit bb62bab

Please sign in to comment.