File: nikto_report_html.plugin

package info (click to toggle)
nikto 1%3A2.1.4-2
  • links: PTS, VCS
  • area: non-free
  • in suites: wheezy
  • size: 2,276 kB
  • sloc: perl: 4,328; makefile: 11
file content (209 lines) | stat: -rw-r--r-- 8,037 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#VERSION,2.05
# $Id: nikto_report_html.plugin 632 2011-02-19 02:49:31Z sullo $
###############################################################################
#  Copyright (C) 2007 CIRT, Inc.
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; version 2
#  of the License only.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
###############################################################################
# PURPOSE:
# Reporting
###############################################################################
sub nikto_report_html_init {
    my $id = { name              => "report_html",
               full_name         => "Report as HTML",
               author            => "Sullo/Jabra",
               description       => "Produces an HTML report.",
               report_head       => \&html_head,
               report_summary    => \&html_summary,
               report_host_start => \&html_host_start,
               report_host_end   => \&html_host_end,
               report_item       => \&html_item,
               report_close      => \&html_close,
               report_format     => 'htm',
               copyright         => "2008 CIRT Inc."
               };

    # load up the templates now
    html_open_templates();
    return $id;
}
###############################################################################
sub html_head {
    my ($file) = @_;

    # Write header for html file, return file handle
    open(OUT, ">>$file") || die print STDERR "+ ERROR: Unable to open '$file' for write: $@\n";

    my $html = html_change_vars($TEMPLATES{'htm_start'});
    $html =~ s/\#NIKTODTD/$CONFIGFILE{'NIKTODTD'}/;
    print OUT "$html";

    return OUT;
}
###############################################################################
sub html_close {
    my ($handle, $mark) = @_;
    my $html = html_change_vars($TEMPLATES{'htm_close'}, $mark);
    print $handle "$html\n";

    close($handle);
    return;
}
###############################################################################
sub html_summary {
    my ($handle, $mark) = @_;
    my $html = html_change_vars($TEMPLATES{'htm_summary'}, $mark);
    print $handle $html;

    return;
}
###############################################################################
sub html_host_start {
    my ($handle, $mark) = @_;
    my $html = html_change_vars($TEMPLATES{'htm_host_head'}, $mark);
    print $handle "$html\n";

    return;
}
###############################################################################
sub html_host_end {
    my ($handle, $mark) = @_;
    my $html = html_change_vars($TEMPLATES{'htm_end'}, $mark);
    print $handle "$html\n";

    return;
}
###############################################################################
sub html_item {
    my ($handle, $mark, $item) = @_;
    my $html = html_change_vars($TEMPLATES{'htm_host_item'}, $mark, $item);
    print $handle "$html\n";

    return;
}
###############################################################################
sub html_open_templates {
    foreach my $t (dirlist($CONFIGFILE{'TEMPLATEDIR'}, "htm.*")) {
        open(T, "<$CONFIGFILE{'TEMPLATEDIR'}/$t");
        my @TEMPLATE = <T>;
        close(T);
        my $T = join("", @TEMPLATE);
        $t =~ s/\..*$//;
        $TEMPLATES{$t} = $T;
    }

    return;
}
###############################################################################
sub html_change_vars {
    my ($template, $mark, $item) = @_;
    my %variables;
    my $protocol = "http";
    if ($mark->{'ssl'}) { $protocol .= "s"; }

    $variables{"#TEMPL_HCTR"}        = $VARIABLES{'TEMPL_HCTR'};
    $variables{"#TEMPL_END"}         = date_disp($mark->{'end_time'});
    $variables{"#TEMPL_HOSTNAME"}    = simple_enc($mark->{'hostname'});
    $variables{"#TEMPL_HOST_HEADER"} = $mark->{'hostname'};
    if (defined $mark->{'vhost'}) {
        $variables{"#TEMPL_HOST_HEADER"} = $mark->{'vhost'};
    }
    $variables{"#TEMPL_IP"}                 = simple_enc($mark->{'ip'});
    $variables{"#TEMPL_ITEMS_TESTED"}       = $COUNTERS{'total_checks'};
    $variables{"#TEMPL_PORT"}               = $mark->{'port'};
    $variables{"#TEMPL_START"}              = date_disp($mark->{'start_time'});
    $variables{"#TEMPL_NIKTO_VER"}          = $VARIABLES{'version'};
    $variables{"#TEMPL_BANNER"}             = simple_enc($mark->{'banner'});
    $variables{"#TEMPL_NIKTO_CLI"}          = $CLI{'all_options'};
    $variables{"#TEMPL_CTR"}                = $COUNTERS{'total_checks'};
    $variables{"#TEMPL_NIKTO_HOSTS_TESTED"} = $COUNTERS{'hosts_completed'};
    $variables{"#TEMPL_ELAPSED"}            = $mark->{'end_time'} - $mark->{'start_time'};
    $variables{"#TEMPL_LINK_NAME"}          = "$protocol://$mark->{'hostname'}:$mark->{'port'}";
    $variables{"#TEMPL_LINK_IP"}            = "$protocol://$mark->{'ip'}:$mark->{'port'}/";
    $variables{"#TEMPL_ITEMS_FOUND"}        = $mark->{'total_vulns'};
    $variables{"#TEMPL_SCAN_START"}         = localtime($COUNTERS{'scan_start'});
    $variables{"#TEMPL_SCAN_END"}           = localtime($COUNTERS{'scan_end'});
    $variables{"#TEMPL_SCAN_ELAPSED"}       = $COUNTERS{'scan_elapsed'} . " seconds";

    $variables{"#TEMPL_LINK_NAME"} = "N/A";
    if ($mark->{'hostname'} ne "") {
        $variables{"#TEMPL_LINK_NAME"} = "$protocol://$mark->{'hostname'}:$mark->{'port'}/";
    }

    # do now in case we return early
    foreach my $var (keys %variables) {
        $template =~ s/$var/$variables{$var}/g;
    }

    if ($item->{'uri'} eq '') { return $template }

    $variables{"#ID"} = $item->{'nikto_id'};

    # OSVDB info
    my $OSVDB = $item->{'osvdb'};
    if ($OSVDB !~ /\d+/) { $OSVDB = 0; }
    $OSVDB_LINK                     = "http://osvdb.org/$OSVDB";
    $variables{"#TEMPL_OSVDB_LINK"} = $OSVDB_LINK;
    $variables{"#TEMPL_OSVDB"}      = $OSVDB;

    # Scanner Messages Handling
    $variables{"#TEMPL_SMMSG"} = $item->{'message'};

    # Positives Handling
    if ($template =~ /\#TEMPL_MSG/) {
        my $msg = simple_enc($item->{'message'});

        # Message & handling for customized html output
        # 740000 = multiple index files -- linkify file names
        if ($item->{'nikto_id'} == 740000) {
            $item->{'message'} =~ /^(.*: )(.*)$/;
            $msg = $1;
            my @links;
            foreach my $f (parse_csv($2)) {    #@files) {
                $f =~ s/\s//g;
                next if $f eq '';
                push(@links,
                     "<a href=\"$protocol://$mark->{'display_name'}:$mark->{'port'}/$f\">$f</a>");
            }
            $msg .= join(", ", @links);
        }

        $variables{"#TEMPL_URI"}         = simple_enc($item->{'uri'});
        $variables{"#TEMPL_MSG"}         = $msg;
        $variables{"#TEMPL_HTTP_METHOD"} = $item->{'method'};
        $variables{"#TEMPL_ITEM_IP_LINK"} =
          "$protocol://$variables{\"#TEMPL_IP\"}:$mark->{'port'}$variables{\"#TEMPL_URI\"}";
        $variables{"#TEMPL_ITEM_NAME_LINK"} = "";
        if ($mark->{'hostname'} ne "") {
            $variables{"#TEMPL_ITEM_NAME_LINK"} =
              "$protocol://$variables{\"#TEMPL_HOSTNAME\"}:$mark->{'port'}$variables{\"#TEMPL_URI\"}";
        }

    }

    foreach my $var (keys %variables) { $template =~ s/$var/$variables{$var}/g; }

    return $template;
}
###############################################################################
sub simple_enc {
    my $var = $_[0] || return;
    $var =~ s/</&lt;/g;
    $var =~ s/>/&gt;/g;
    $var =~ s/"/&quot;/g;
    return $var;
}

1;