Table of Contents
Though some checks can be found in other plugins, the
scan_database.db contains the bulk of the web test
information. Here is a description of the field values:
Table 7.1. Scan Database Fields
| Test ID | Nikto test ID |
| OSVDB-ID | Corresponding vulnerability entry number for osvdb.org |
| Server Type | Generic server matching type |
| URI | URI to retrieve |
| HTTP Method | HTTP method to use for URI |
| Match 1 | String or code to match for successful test |
| Match 1 (Or) | String or code to alternatively match for successful test |
| Match1 (And) | String or code to also match for successful test |
| Fail 1 | String or code to match for test failure |
| Fail 2 | String or code to match for test failure (alternative) |
| Summary | Summary message to report for successful test |
| HTTP Data | HTTP data to be sent during POST tests |
| Headers | Additional headers to send during test |
Users can create their own, private tests for any of the
databases. By placing a syntactically correct database file in the
plugins directory, with a file name prefaced with a
"u", the data will be loaded along with the built-in checks.
For example, create the file
plugins/udb_tests and it will be loaded at the same
time plugins/db_tests is loaded. These files will
also be checked for syntax when -dbcheck is
used.
For tests which require a "private" OSVDB ID, use the OSVDB ID 0 (zero). This should be used for all vulnerabilities that do not (or should not) exist in OSVDB, as ID 0 is for testing only. You are encouraged to send missing information to OSVDB at moderators@osvdb.org.
For the "Test ID", it is recommended you use unique numbers between 400000 and 499999 to allow for growth of the Nikto database without interfering with your own tests (note: numbers above 500000 are reserved for other tests).
Please help Nikto's continued success by sending test updates to
<sullo@cirt.net>.
The scan database is a CSV delimited file which contains most of the tests. Fields are enclosed by quotes and separated by commas. The field order is:
Test-ID, OSVDB-ID, Tuning Type, URI, HTTP Method, Match 1, Match 1 Or, Match1 And, Fail 1, Fail 2, Summary, HTTP Data, Headers
Here is an example test:
"120","3092","2","/manual/","GET","200","","","","","Web server manual","",""
To allow a bit more flexibility, Nikto allows plugins so that there is easy expansion of existing capabilities and some future proofing.
Plugins are run in four different phases, these are:
- Initialisation (mandatory)
Plugin initialisation is performed before targets are assigned. During this phase, the plugin should tell Nikto about its existence and capabilities. It may optionally set up any later required variables.
- Reconnaisance (optional)
During the reconnaisance phase, the plugin should look for interesting information that may be of use during the scan phase. It may report vulnerablities, though this is discouraged.
- Scan (optional)
The scan phase should perform the meat of the plugin - this is where it should look at the web server and return any potential vulnerabilities.
- Reporting (optional)
The reporting phase is used to export any found vulnerabilities into a format that they can be used later, for example written as a file report, or imported into a database. No testing of the web server, or reporting of new vulnerbilies should be performed in this phase.
This phase is slightly more complex than the others and may be called at several points during Nikto's execution, as detailed later
Plugins are written in standard perl in the current context. They
should be placed within the PLUGINDIR defined in the
Nikto configuration file and must have a filename ending in
.plugin.
An important concept to grasp about plugins and the order that are executed in is plugin weight: each phase will execute all defined plugins in the order defined by the weight. A plugin's weight is defined as a number between 1 and 100, where 1 is high priority and 100 is low priority. Plugins of equal weight will be executed in an undefined order.
As described above, all plugins must be able to execute in the initialisation phase or they will be ignored.
A perl sub must exist called
. The sub
is passed no parameters and should return a hash reference to a hash
that should contain the following entries:filename_init
name (mandatory)The short name of the plugin. This is used to identify the plugin during verbose logging and will, in future versions, be used to select plugin execution. The name should be one word and, ideally, lower case.
full_name (mandatory)The full name of the plugin. This is used to identify the plugin during verbose logging and may be used in reporting modules to identify tests run against the web server.
author (mandatory)The name or handle of the author of the plugin. This may be used during reporting to identify ownerships of copyright of tests run against the web server.
description (mandatory)A short sentence to describe the purpose of the plugin. This may be used during reporting, or by a front end to describe the purpose of the plugin.
copyright (mandatory)The copyright string (or lack of it) of the plugin. This may be used during reporting to ensure that appropriate copyright is assigned to reports.
recon_method (optional)This should be a reference to a function used during the reconnaisance phase of the plugin's execution. If this is left undefined then the plugin will not execute during the reconnaisance phase.
recon_cond (optional)This is an expression to be evaluated before the plugin is executed; if true, the plugins is executed, if false, the plugin is skipped. This can be used to minimise plugin execution.
recon_weight (optional)This is the weight used to schedule the running of the plugin during the reconnaisance phase. If this is left undefined it will default to 50.
scan_method (optional)This should be a reference to a function used during the scan phase of the plugin's execution. If this is left undefined then the plugin will not execute during the scan phase.
scan_cond (optional)This is an expression to be evaluated before the plugin is executed; if true, the plugins is executed, if false, the plugin is skipped. This can be used to minimise plugin execution.
scan_weight (optional)This is the weight used to schedule the running of the plugin during the scan phase. If this is left undefined it will default to 50.
report_head (optional)This should be a reference to a function executed before any testing commences. If this is left undefined then the plugin will not be called to produce a report header.
report_host_start (optional)This should be a reference to a function executed before the reconnaisance phase of each host. If this is left undefined then the plugin will not be called to produce a host header.
report_host_end (optional)This should be a reference to a function executed after the scan phase of each host. If this is left undefined then the plugin will not be called to produce a host footer.
report_item (optional)This should be a reference to a function executed after each found vulnerability. If this is left undefined then the plugin will not be called to produce an item record.
report_close (optional)This should be a reference to a function executed after testing of all hosts has been finished. If this is left undefined then the plugin will not be called to close the report.
report_format (optional)This should describe the file format that the plugin
handles. This is internally matched with the contents of the
-output switch to reduce excessive calls
to plugins.
report_weight (optional)This is the weight used to schedule the running of the plugin during the reporting phase. If this is left undefined it will default to 50.
Example 7.1. Example initialisation function
sub nikto_dictionary_attack_init
{
my $id =
{
name => "dictionary",
full_name => "Dictionary attack",
author => "Deity",
description => "Attempts to dictionary attack commonly known directories/files",
recon_method => \&nikto_dictionary_attack,
recon_cond => '$CLI{mutate} =~ /6/',
recon_weight => 20,
copyright => "2009 CIRT Inc"
};
return $id;
} The reconnaisance phase is executed for each target at the start of each scan.
Each reconnaisance method such expect to take a
mark hash ref. It should return nothing.
void
recon_method( | mark); |
hashref | mark; |
The reconnaisance phase is intended to be used to pull information about the web server for later use by the plugin, or by other plugins. Reporting vulnerabilities in this phase is discouraged.
Example uses of the reconnaisance phase are to spider a site, check for known applications etc.
The scan phase is the meat of the plugin's life, this is run, for each target, immediately after the reconnaisance phase.
Each scan should check for vulnerabilities it knows about and report on them as it finds one.
void
scan_method( | mark); |
hashref | mark; |
This is potentially the most convoluted phase as it has several hooks that may be used for each section in the scan's lifetime.
The hooks are:
This hook is called immediately after target acquisition and before the reconnaisance phase. It is designed to allow the reporting plugin to open the report and ensure that any headers are appropiately written.
handle
report_head( | filename); |
string | filename; |
The filename parameter is a bit of a
misnomer; it will be a copy of the string passed to the
-output switch and may indicate, for example,
a database name.
The handle is a handle that will be
passed to other reporting functions for this plugin so should be
internally consistent.
This hook is called immediately before the reconnaisance phase for each target. It is designed to allow the reporting plugin to write any host specfic information.
void
report_host_start( | rhandle, | |
mark); |
handle | rhandle; |
hashref | mark; |
The rhandle parameter is the output of
the plugin's Report Head function.
The mark parameter is a hashref for the
target information (described below).
This hook is called immediately after the scan phase for each target. It is designed to allow the reporting plugin to close any host specfic information.
void
report_host_end( | rhandle, | |
mark); |
handle | rhandle; |
hashref | mark; |
The rhandle parameter is the output of
the plugin's Report Head function.
The mark parameter is a hashref for the
target information (described below).
This hook is called once for each vulnerability found on the target This should report details about the vulnerability.
void
report_item( | rhandle, | |
| mark, | ||
vulnerbility); |
handle | rhandle; |
hashref | mark; |
hashref | vulnerbility; |
The rhandle parameter is the output of
the plugin's Report Head function.
The mark parameter is a hashref for the
target information (described below).
The vulnerability parameter is a
hashref for the vulnerability information (described below).
The below data structures are used to communicate between the various plugin methods. Unless otherwise mentioned, they are all standard perl hash references with the detailed members.
The mark hash contains all information about a target. It contains the below members. It should be read-only.
Table 7.2. Members of the Mark structure
identHost identifier, usually equivalent to what was passed on the command line. hostnameHost name of the target. ipIP address of the target. portTCP port of the target. display_nameEither the hostname, or the IP address of the target, dependant on whether a hostname has been discovered. sslFlag to indicate whether the target runs over SSL. If it is set to 0, then the plugin should not use SSL. Any other value indicates SSL should be used. vhostVirtual hostname to use for the target. rootRoot URI to use for the target. bannerBanner of the target's web server.
The vulnerability hash contains all information about a
vulnerability. It contains the below members. It should be read-only
and should only be written using the
add_vulnerability method.
Table 7.3. Members of the Vulnerability structure
mark Hash ref to a mark data structure. message Message for the vulnerability. nikto_id Test ID (tid) of the vulnerability, this should be a unique number which'll identify the vulnerability. osvdb OSVDB reference to the vulnerability in the Open Source Vulnerability Database. This may be 0 if an OSVDB reference is not relevant or doesn't exist. method HTTP method used to find the vulnerability. uri URI for the result. result Any HTTP data, excluding headers.
Several standard methods are defined in
nikto_core.plugin that can be used for all
plugins. It is strongly advised that these should be used where
possible instead of writing new methods.
For some methods, such as add_vulnerability which write to global variables, these must be
the only interface to those global variables.
array change_variables( | line); |
string | line; |
Expands any variables in the line parameter. The expansions are
variables defined in the global array @VARIABLES,
which may be read from db_variables, or added by
reconnaisance plugin methods.
int is_404( | uri, | |
| content, | ||
HTTPcode); |
string | uri; |
string | content; |
string | HTTPcode; |
Makes a guess whether the result is a real web page or an error page. As several web servers are badly configured and don't return HTTP 404 codes when a page isn't found, Nikto attempts to look for common error pages. Returns 1 if the page looks like an error.
string get_ext( | uri); |
string | uri; |
Attempts to work out the extension of the uri. Will return the extension or the special cases: DIRECTORY, DOTFILE, NONE.
string date_disp( | ); |
| ; |
Returns the current time in a human readable format (YYYY-mm-dd hh:mm:ss)
string rm_active( | content); |
string | content; |
Attempts to remove active content (e.g. dates, adverts etc.) from a page. Returns a filtered version of the content.
string get_banner( | mark); |
hashref | mark; |
Pulls the web servers banner. This is automatically performed for all targets before a mark is passed to the plugin.
boolean content_present( | HTTPcode); |
string | HTTPcode; |
Checks the HTTPresponse against known "found" responses. TRUE indicates that the request was probably successful.
string HTTPCode, string content
fetch( | uri, | |
| method, | ||
| content, | ||
| headers, | ||
noclean); |
string | uri; |
string | method; |
string | content; |
hashref | headers; |
boolean | noclean; |
Deprecated
Performs a simple HTTP request to URI using the HTTP method,
method. content supplies
any data to pass in the HTTP body. headers allows any custom headers to be placed in the request.
noclean is a flag specifying that the request
shouldn't be cleaned up before being sent (e.g. if the Host: header is
blank).
string HTTPCode, string content
nfetch( | uri, | |
| method, | ||
| content, | ||
| headers, | ||
noclean); |
string | uri; |
string | method; |
string | content; |
hashref | headers; |
boolean | noclean; |
An updated version of fetch that uses a local, rather than a global request/result structure. This should be used in preference to fetch.
hashref setup_hash( | requesthash, | |
mark); |
hashref | requesthash; |
hashref | mark; |
Sets up up a libwhisker hash with the normal Nikto variables. This should be used if any custom calls to libwhisker are used.
string char_escape( | line); |
string | line; |
Escapes any characters within line.
array parse_csv( | text); |
string | text; |
Breaks a line of CSV text into an array of items.
arrayref init_db( | dbname); |
string | dbname; |
Initialises a database that is in PLUGINDIR and returns an arrayref. The arrayref is to an array of hashrefs, each
hash member is configured by the first line in the database file, for
example:
"nikto_id","md5hash","description"
This will result in an array of hashrefs with parameters:
array[0]->{nikto_id}
array[0]->{md5hash}
array[0]->{description}void add_vulnerability( | mark, | |
| message, | ||
| nikto_id, | ||
| osvdb, | ||
| method, | ||
| uri, | ||
data); |
hashref | mark; |
string | message; |
string | nikto_id; |
string | osvdb; |
string | method; |
string | uri; |
string | data; |
Adds a vulnerability for the mark, displays it to standard out and sends it to any reporting plugins.
void nprint( | message, | |
display); |
string | message; |
string | display; |
Prints message to standard out.
Display specifies a filter for the message,
currently this can be "v" for verbose and "d" for debug output.
The following global variables exist within Nikto, most of them are defined for internal use and their use by plugins is not advised. Several have been deprecated, these should not be used by plugins.
%TEMPLATES (read/write)Hash to store the HTML and XML report templates.
%ERRSTRINGS (read)Hash to contain all the entries in db_404 - a list of strings that may indicate a 404.
%CLI (read)Hash of passed CLI parameters
%VARIABLES (read) (write)Hash of contents of the entries in db_variables. Plugins should only write to this hash in the reconnaisance phase.
%TESTS (read) (write)Hash of the db_tests database. This is only intended to be used by the tests plugin, though it could be used by a reconnaisance plugin to add tests on the fly.
$CONTENT (read) (write)
(deprecated)Global variable to store data from a fetch or nfetch. A local variable should be used instead
%NIKTO (read)Hash which contains internal Nikto data, such as help for the command line parameters.
%REALMS (read)Hash of data from db_realms.
%NIKTOCONFIG (read)Hash containing the data read from the configuration files.
%request (read) (write)
(deprecated), %result (read) (write)
(deprecated)Global libwhisker hash. This should not be used; nfetch or a local hash should be used.
%COUNTERS (read) (write)Hash containing various global counters (e.g. number of requests)
%db_extensions (read) (deprecated)Hash containing a list of common extensions
%FoF (read) (write)Hash containing data for each extension and what the server produces if a request for a non-existent file is requested.
%UPDATES (read) (write)Hash containing any updates that need to be sent back to cirt.net
$DIV (read)Divider mark for the items sent to standard out.
@DBFILE (read)Placeholder used to hold the contents of
db_tests.
@BUILDITEMS (read) (write)
(deprecated)Array to hold information for tests to act on later. Use should be avoided, a local variable should be used instead.
$PROXYCHECKED (read) (deprecated)Flag to see whether connection through the proxy has been checked.
$http_eol (read) (deprecated)Contains the http end of line pattern.
@RESULTS (read)Array of reported vulnerabilities, should only be written
to through add_vulnerability.
@PLUGINS (read)Array of hashrefs for each plugin. Used internally to run plugins.
@MARKS (read)Array of marks to indicate each target.
@REPORTS (read)Ordered array that reporting plugins should be run in. Used for efficency on calling reporting plugins.
%CACHE (read) (write)Containing the URI cache, should only be read/written
through nfetch. Members:
Each test, whether it comes from one of the databases or in code, must have a unique identifier. The numbering scheme for writing tests is as follows:
Table 7.5. TID Scheme
000000 db_tests 400000 user defined tests ( udb*files)500000 db_favicon 600000 db_outdated 700000 db_realms 800000 db_server_msgs 900000 tests defined in code
As much data as possible in the %TESTS hash
should be populated for each new test that is defined in code (plugins).
These fields include URI for the test, message to print on success, HTTP
method and OSVDB ID. Without a 'message' value in
%TESTS output will not be saved in HTML or XML
reports. Not all tests are expected to have a uri, method or OSVDB ID.
Here is an example of setting those fields:
$TESTS{999999}{uri}="/~root";
$TESTS{999999}{message}="Enumeration of users is possible by requesting ~username";
$TESTS{999999}{method}="GET";
$TESTS{999999}{osvdb}=637;Any new or updated code, tests or information sent to the author is assumed to free of copyrights. By sending new or updated code, tests or information to the author you relinquish all claims of copyright on the material, and agree that this code can be claimed under the same copyright as Nikto.