source: trunk/plugins/nikto_report_xml.plugin @ 269

Revision 269, 8.4 KB checked in by sullo, 3 years ago (diff)

moved $DIV into %NIKTO
more code cleanup

Line 
1#VERSION,2.02
2# $Id: nikto_reports.plugin 125 2009-07-20 21:59:00Z deity $
3###############################################################################
4#  Copyright (C) 2007 CIRT, Inc.
5#
6#  This program is free software; you can redistribute it and/or
7#  modify it under the terms of the GNU General Public License
8#  as published by the Free Software Foundation; version 2
9#  of the License only.
10#
11#  This program is distributed in the hope that it will be useful,
12#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#  GNU General Public License for more details.
15#
16#  You should have received a copy of the GNU General Public License
17#  along with this program; if not, write to the Free Software
18#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19###############################################################################
20# PURPOSE:
21# Reporting
22###############################################################################
23sub nikto_report_xml_init
24{
25   my $id =
26   {
27      name              => "report_xml",
28      full_name         => "Report as XML",
29      author            => "Sullo/Jabra",
30      description       => "Produces an XML report.",
31      report_head       => \&xml_head,
32      report_host_start => \&xml_host_start,
33      report_host_end   => \&xml_host_end,
34      report_item       => \&xml_item,
35      report_close      => \&xml_close,
36      report_format     => 'xml',
37      copyright         => "2008 CIRT Inc."
38   };
39   # load up the templates now
40   xml_open_templates();
41   return $id;
42}
43
44sub xml_head
45{
46   my ($file) = @_;
47   # Write header for xml file, return file handle
48   open(OUT, ">>$file") || die print STDERR "+ ERROR: Unable to open '$file' for write: $@\n";
49
50   my $xml = xml_change_vars($TEMPLATES{xml_start});
51   $xml =~ s/\#NIKTODTD/$NIKTOCONFIG{NIKTODTD}/;
52   print OUT "$xml";
53
54   return OUT;
55}
56###############################################################################
57sub xml_close
58{
59   my ($handle,$mark) = @_;
60   my $xml = xml_change_vars($TEMPLATES{xml_close},$mark);
61   print $handle "$xml\n";
62
63   close($handle);
64   return;
65}
66###############################################################################
67sub xml_host_start
68{
69   my ($handle, $mark) = @_;
70   my $xml = xml_change_vars($TEMPLATES{xml_host_head},$mark);
71   print $handle "$xml\n";
72
73   return;
74}
75###############################################################################
76sub xml_host_end
77{
78   my ($handle, $mark) = @_;
79   my $xml = xml_change_vars($TEMPLATES{xml_end},$mark);
80   print $handle "$xml\n";
81
82   return;
83}
84###############################################################################
85sub xml_item
86{
87   my ($handle, $mark, $item) = @_;
88   my $xml = xml_change_vars($TEMPLATES{xml_host_item},$mark,$item);
89   print $handle "$xml\n";
90
91   return;
92}
93###############################################################################
94sub xml_open_templates
95{
96    my @ts        = dirlist($NIKTOCONFIG{TEMPLATEDIR});
97    my $have_cirt = 0;
98    foreach my $t (@ts)
99    {
100        open(T, "<$NIKTOCONFIG{TEMPLATEDIR}/$t");
101        my @TEMPLATE = <T>;
102        close(T);
103        my $T = join("", @TEMPLATE);
104        $t =~ s/\..*$//;
105
106        # :-)
107        if ($T =~ /\s?20[0-9]{2}\s?CIRT, Inc/i) { $have_cirt = 1; }
108
109        $TEMPLATES{$t} = $T;
110    }
111
112    if (!$have_cirt)
113    {
114        print "\nIt looks like you may have removed the Nikto copyright from the reports. Please remember that this program is copyrighted, takes a lot of work to maintain, and is completely free for non-commercial use.\n\nIf this message has been a mistake, please notify sullo\@cirt.net.\n\n";
115    }
116
117    return;
118}
119###############################################################################
120sub xml_change_vars
121{
122    my ($template, $mark, $item) = @_;
123    my %variables;
124    my $protocol = "http";
125    if ($mark->{ssl}) { $protocol .= "s"; }
126
127    $variables{"#TEMPL_HCTR"}               = $NIKTO{'TEMPL_HCTR'};
128    $variables{"#TEMPL_END"}                = date_disp($mark->{end_time});
129    $variables{"#TEMPL_HOSTNAME"}           = simple_enc($mark->{hostname});
130    $variables{"#TEMPL_HOST_HEADER"}        = $mark->{hostname};
131    if (defined $mark->{vhost})
132    {
133       $variables{"#TEMPL_HOST_HEADER"}     = $mark->{vhost};
134    }
135    $variables{"#TEMPL_SSL_INFO"}           = "";
136    if (defined $mark->{sslcyphers})
137    {
138       $variables{"#TEMPL_SSL_INFO"}        = "<ssl ciphers=\"$mark->{sslcyphers}\" issuers=\"$mark->{sslissuers}\" info=\"$mark->{sslinfo}\" />";
139    }
140    $variables{"#TEMPL_IP"}                 = simple_enc($mark->{ip});
141    $variables{"#TEMPL_ITEMS_TESTED"}       = $mark->{total_checks};
142    $variables{"#TEMPL_PORT"}               = $mark->{port};
143    $variables{"#TEMPL_START"}              = date_disp($mark->{start_time});
144    $variables{"#TEMPL_END"}                = date_disp($mark->{end_time});
145    $variables{"#TEMPL_NIKTO_VER"}          = $NIKTO{'version'};
146    $variables{"#TEMPL_BANNER"}             = simple_enc($mark->{banner});
147    $variables{"#TEMPL_NIKTO_CLI"}          = $CLI{'all_options'};
148    $variables{"#TEMPL_CTR"}                = $mark->{total_checks};
149    $variables{"#TEMPL_NIKTO_HOSTS_TESTED"} = $COUNTERS{hosts_total};
150    $variables{"#TEMPL_ELAPSED"}            = $mark->{end_time}-$mark->{start_time};
151    $variables{"#TEMPL_LINK_NAME"}          = "$protocol://$mark->{hostname}:$mark->{port}";
152    $variables{"#TEMPL_LINK_IP"}            = "$protocol://$mark->{ip}:$mark->{port}/";
153    $variables{"#TEMPL_ITEMS_FOUND"}        = $mark->{total_vulns};
154
155    $variables{"#TEMPL_LINK_NAME"} = "N/A";
156    if ($mark->{hostname} ne "")
157    {
158        $variables{"#TEMPL_LINK_NAME"} = "$protocol://$mark->{hostname}:$mark->{port}/";
159    }
160
161    foreach my $var (keys %variables)
162    {
163       $template =~ s/$var/$variables{$var}/g;
164    }
165
166    # Scanner Messages Handling
167    if ($template =~ /\#TEMPL_SMMSG/)
168    {
169        my $template_orig  = $template;
170        my $template_final = "";
171
172        if ($item->{uri} ne '') { next; }
173        my $OSVDB = $item->{osvdb};
174        if ($OSVDB !~ /\d+/) { $OSVDB = 0; }
175        $OSVDB_LINK = "http://osvdb.org/$OSVDB";
176        $template =~ s/\#TEMPL_SMMSG/$item->{message}/;
177        $template =~ s/\#TEMPL_OSVDB_LINK/$OSVDB_LINK/;
178        $template =~ s/\#TEMPL_OSVDB/$OSVDB/;
179        $template =~ s/\#ID/$item->{nikto_id}/;
180        $template_final .= $template;
181        $template = $template_orig;
182        $template = "$template_final\n";
183    }
184
185    # Positives Handling
186    if ($template =~ /\#TEMPL_MSG/)
187    {
188        my $template_orig  = $template;
189        my $template_final = "";
190        if ($item->{uri} eq '') { next; }
191        foreach my $uri (split(' ',$item->{uri}))
192        {
193           $item->{uri}                     = simple_enc($item->{uri});
194           $variables{"#TEMPL_URI"}         = $uri;
195           $variables{"#TEMPL_MSG"}         = $item->{message};
196           $variables{"#TEMPL_HTTP_METHOD"} = $item->{method};
197 
198           $variables{"#TEMPL_ITEM_IP_LINK"} = "$protocol://$variables{\"#TEMPL_IP\"}:$mark->{port}$variables{\"#TEMPL_URI\"}";
199           $variables{"#TEMPL_ITEM_NAME_LINK"} = "";
200           if ($mark->{hostname} ne "")
201           {
202               $variables{"#TEMPL_ITEM_NAME_LINK"} = "$protocol://$variables{\"#TEMPL_HOSTNAME\"}:$mark->{port}$variables{\"#TEMPL_URI\"}";
203           }
204 
205           $OSVDB      = "";
206           $OSVDB_LINK = "";
207           foreach my $o (split(/ /, $item->{osvdb}))
208           {
209               if ($o eq "")
210               {
211                   $o = "0";
212               }
213
214               $OSVDB      .= "$o";
215               $OSVDB_LINK .= "http://osvdb.org/$o";
216           }
217
218           $template =~ s/\#TEMPL_OSVDB_LINK/$OSVDB_LINK/;
219           $template =~ s/\#TEMPL_OSVDB/$OSVDB/;
220           $template =~ s/\#ID/$item->{nikto_id}/;
221
222           foreach my $var (keys %variables) { $template =~ s/$var/$variables{$var}/g; }
223           $template_final .= $template;
224           $template = $template_orig;
225       }
226       $template = "$template_final\n";
227    }
228    return $template;
229}
230###############################################################################
231sub simple_xml_enc
232{
233    my $var = $_[0] || return;
234    $var =~ s/&/%26/g;
235    return $var;
236}
237###############################################################################
238sub simple_enc
239{
240    my $var = $_[0] || return;
241    $var =~ s/</&lt;/g;
242    $var =~ s/>/&gt;/g;
243    $var =~ s/"/&quot;/g;
244    return $var;
245}
246
247sub nikto_reports { }    # so core doesn't freak
248
2491;
Note: See TracBrowser for help on using the repository browser.