File: nikto_httpoptions.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 (196 lines) | stat: -rw-r--r-- 6,877 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
#VERSION,2.09
# $Id: nikto_httpoptions.plugin 632 2011-02-19 02:49:31Z sullo $
###############################################################################
#  Copyright (C) 2006 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:
# HTTP options check
###############################################################################
sub nikto_httpoptions_init {
    my $id = { name      => "httpoptions",
               full_name => "HTTP Options",
               author    => "Sullo",
               description =>
                 "Performs a variety of checks against the HTTP options returned from the server.",
               hooks => { scan => { method => \&nikto_httpoptions,
                                    weight => 20,
                                    },
                            },
               copyright => "2008 CIRT Inc."
               };
    return $id;
}

# This just gets the HTTP options & checks 'em out.
# See RFC 2626 for more info...

sub nikto_httpoptions {
    return if $mark->{'terminate'};
    my ($mark) = @_;
    my %headers;

    # test for both OPTIONS / and OPTIONS * as they may give different results
    (my $res, $content) =
      nfetch($mark, "*", "OPTIONS", "", \%headers, "", "httpoptions: OPTIONS *");
    my $aoptions = "$headers{'allow'}, ";
    my $poptions = "$headers{'public'}, ";
    my ($allow_methods, $public_methods);
    my $txt = "";
    my $dbarray;

    $dbarray = init_db("db_httpoptions");

    ($res, $content) = nfetch($mark, "/", "OPTIONS", "", \%headers, "", "httpoptions: OPTIONS /");
    $aoptions .= $headers{'allow'};
    $poptions .= $headers{'public'};

    foreach my $o (split(/,[ ]?/, $aoptions)) {
        $allow_methods .= ", $o" unless ($allow_methods =~ /\b$o\b/ || $o eq '');
    }
    $allow_methods =~ s/^[ ]?, //;
    foreach my $o (split(/,[ ]?/, $poptions)) {
        $public_methods .= ", $o" unless ($public_methods =~ /\b$o\b/ || $o eq '');
    }
    $public_methods =~ s/^[ ]?, //;

    # proxy can impose its methods... should actually check this not just warn
    if ($CLI{'useproxy'} ne "") { $txt = "(May be proxy's methods, not server's)"; }

    %davmethods = ();
    if ($allow_methods ne "") {
        add_vulnerability($mark, "Allowed HTTP Methods: $allow_methods $txt", 999990, 0);
        foreach my $m (split /,? /, $allow_methods) {
            my $method = eval_methods($m, "Allow", $dbarray, $mark);
            if ($method ne "") { $davmethods{$method} = 1 }
        }
    }

    if ($public_methods ne "") {
        add_vulnerability($mark, "Public HTTP Methods: $public_methods $txt", 999985, 0);
        foreach my $m (split /,? /, $public_methods) {
            my $method = eval_methods($m, "Public", $dbarray, $mark);
            if ($method ne "") { $davmethods{$method} = 1 }
        }
    }

    if (scalar(keys(%davmethods)) > 0) {
        $message = "WebDAV enabled (";
        for my $key (keys %davmethods) {
            $message .= "$key ";
        }
        $message .= "listed as allowed)";
        add_vulnerability($mark, "$message", "999977", "0");
    }

    # Check for other weirdness
    # IIS Debug
    return if $mark->{'terminate'};
    ($res, $content) = nfetch($mark, "/", "DEBUG", "", "", "", "httpoptions: DEBUG");
    if ($res == 200) {
        add_vulnerability(
            $mark,
            "DEBUG HTTP verb may show server debugging information. See http://msdn.microsoft.com/en-us/library/e8z01xdh%28VS.80%29.aspx for details.",
            999972,
            0,
            "DEBUG"
            );
    }

    # IIS PROPFIND HEADER
    return if $mark->{'terminate'};
    %headers = ("Host"           => "",
                "Content-Length" => "0",);
    ($res, $content) =
      nfetch($mark, "/", "PROPFIND", "", \%headers, { noclean => 1 }, "httpoptions: PROPFIND");
    if ($res == 207) {
        if ($content =~ "<a:href>http://") {
            my $ipfound = $content;
            $ipfound =~ s/^.*<a:href>//g;
            $ipfound =~ s/<\/a:href>.*$//g;
            add_vulnerability($mark,
                           "PROPFIND HTTP verb may show the server's internal IP address: $ipfound",
                           999973, 13431);
        }
    }

    # Special checks for TRACE/TRACK to see whether its vulnerable
    %headers = ("Host" => "Nikto",);
    foreach my $method (split(/ /, "TRACE TRACK")) {

        # Check for all flavours of HTTP
        foreach my $version (split(/ /, "1.0 1.1")) {
            return if $mark->{'terminate'};
            $request{'whisker'}{'version'} = $version;
            ($res, $content) =
              nfetch($mark, "/", $method, "", \%headers, "", "httpoptions: $method");
            if ($res == 200) {
                if ($content =~ "Nikto") {
                    add_vulnerability($mark,
                          "HTTP $method method is active, suggesting the host is vulnerable to XST",
                          999971, 877);

                    # now we know its vulnerable stop testing
                    last;
                }
            }
        }
    }

    $request{'whisker'}->{'version'} = $NIKTOCONFIG{'DEFAULTHTTPVER'};

    # Now release memory for the dbarray
    undef @$dbarray;
    return;
}

sub eval_methods {
    my $method  = $_[0] || return;
    my $type    = $_[1];
    my $dbarray = $_[2];
    my $mark    = $_[3];
    my $message;
    $method = uc($method);

    # Now search database for the method.
    foreach my $item (@$dbarray) {
        if (   $method eq "PROPPATCH"
            || $method eq "SEARCH"
            || $method eq "PROPFIND"
            || $method eq "COPY"
            || $method eq "LOCK"
            || $method eq "UNLOCK") {
            return $method;
        }

        if ($item->{'method'} eq $method) {
            if ($item->{'nikto_id'} eq "0") {

                # is webdav
                return $method;
            }
            else {
                $message = $item->{'message'};
                $message =~ s/\@TYPE\@/$type/;
                add_vulnerability($mark, "$message", $item->{'nikto_id'}, $item->{'osvdb'});
            }
        }
    }

    return "";
}

1;