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
|
#VERSION,2.03
# $Id: nikto_auth.plugin 632 2011-02-19 02:49:31Z sullo $
###############################################################################
# Copyright (C) 2004 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:
# Search content for known bad strings
###############################################################################
sub nikto_auth_init {
my $id = { name => 'auth',
full_name => 'Guess authentication',
author => 'Sullo/Deity',
description => 'Attempt to guess authentication realms',
hooks => {
start => { method => \&nikto_auth_load,
weight => 1,
},
postfetch => { method => \&nikto_auth,
weight => 19,
cond => '$result->{whisker}->{code} eq 401',
},
prefetch => { method => \&nikto_auth_pre,
weight => 19,
},
},
copyright => "2010 CIRT Inc"
};
use vars qw/$REALMS/;
return $id;
}
# Load up the database as soon as we can
sub nikto_auth_load {
$REALMS = init_db("db_realms");
if (defined $CLI{'hostauth'}) {
my @x = split(/:/, $CLI{'hostauth'});
my $HOSTAUTH = { nikto_id => "700500",
realm => (defined $x[2]) ? $x[2] : '@ANY',
password => $x[1],
id => $x[0],
message => "Credentials provided by CLI.",
};
unshift(@{$REALMS}, $HOSTAUTH);
}
}
# Prefetch method can only set a default if it exists, since we don't have
# any returned 401 header. This may mean we send auth headers when they are not
# required, but it shouldn't matter. It also means if there are multiple realms
# the postfetch method will keep changing default...
sub nikto_auth_pre {
my ($mark, $parameters, $request, $result) = @_;
if ($mark->{'realms'}{'default'}{'authtype'} ne '') {
LW2::auth_set($mark->{'realms'}{'default'}{'authtype'},
$request,
$mark->{'realms'}{'default'}{'id'},
$mark->{'realms'}{'default'}{'password'});
$request->{'whisker'}->{'allow_short_reads'} = 1;
LW2::http_fixup_request($request);
}
return $request, $result;
}
# Split up www-authenticate to realm and method
sub split_auth_header {
my $header = $_[0] || return;
my ($realm, $authtype);
my @authenticate = split(/=/, $header);
if ($authenticate[0] =~ /^ntlm/i) {
$realm = $authtype = 'NTLM';
}
else {
$realm = $authenticate[1];
$realm =~ s/^\"//;
$realm =~ s/\".*$//;
if ($authenticate[0] =~ /^basic/i) {
$authtype = 'basic';
}
elsif ($authenticate[0] =~ /^digest/i) {
$authtype = 'digest';
}
}
return $realm, $authtype;
}
# Actual authentication and retry takes place here.
# User-supplied credentials will be tried first if present
sub nikto_auth {
my ($mark, $parameters, $request, $result) = @_;
my ($authtype) = 'basic';
my ($body) = $result->{'whisker'}->{'data'};
my ($uri) = $result->{'whisker'}->{'uri'};
my ($method) = $result->{'whisker'}->{'method'} || "GET";
my ($realm, $save_auth);
unless (defined $result->{'www-authenticate'}) {
nprint("+ ERROR: No authentication header defined: $uri");
return $request, $result;
}
my ($realm, $authtype) = split_auth_header($result->{'www-authenticate'});
# did we already test this realm?
if (exists $mark->{'realms'}{$realm}{'status'}) {
return $request, $result;
}
# Save to revert
$save_auth = $result{'www-authenticate'};
nprint("+ $uri - Requires Authentication for realm '$realm'")
if ($OUTPUT{'show_auth'} || $uri =~ /^$CLI{'root'}\/?$/);
# Now we have this we can try guessing the password
foreach my $entry (@{$REALMS}) {
return if $mark->{'terminate'};
unless ($realm =~ /$entry->{'realm'}/i || $entry->{'realm'} eq '@ANY') { next; }
if ($result->{'www-authenticate'} =~ /^ntlm/i) {
$authtype = 'ntlm';
}
# Set up LW hash
LW2::auth_set($authtype, $request, $entry->{'id'}, $entry->{'password'});
# Patch to fix short reads
$request->{'whisker'}->{'allow_short_reads'} = 1;
LW2::http_fixup_request($request);
sleeper();
LW2::http_do_request_timeout($request, $result); # test auth
$COUNTERS{'totalrequests'}++;
dump_var("Auth Request", $request);
dump_var("Auth Response", $result);
$mark->{'realms'}{$realm}{'status'} = 0;
$mark->{'realms'}{$realm}{'id'} = $entry->{'id'};
$mark->{'realms'}{$realm}{'password'} = $entry->{'password'};
$mark->{'realms'}{$realm}{'authtype'} = $authtype;
if ($result{'www-authenticate'} =~ /^ntlm/i) {
# NTLM is different...
my @ntlm_x = split(/ /, $result{'www-authenticate'});
if ($#ntlm_x == 1) {
sleeper();
$request->{'whisker'}->{'allow_short_reads'} = 1;
LW2::http_fixup_request($request);
LW2::http_do_request_timeout(\%request, \%result);
$COUNTERS{'totalrequests'}++;
}
}
if ($result->{'www-authenticate'} eq '' && !defined $result->{'whisker'}->{'error'}) {
unless ($entry->{'checked'} == 1) {
my $message;
if ($entry->{'message'} eq "Credentials provided by CLI.") {
$message =
"Successfully authenticated to realm '$realm' with user-supplied credentials.";
}
elsif ($entry->{'id'} eq '' && $entry->{'password'} eq '') {
$message =
"Blank credentials found at $request{whisker}->{uri}, $entry->{'realm'}: $entry->{'msg'}.";
}
else {
$message =
"Default account found for '$realm' at $request->{'whisker'}->{'uri'} (ID '$entry->{'id'}', PW '$entry->{'password'}'). $entry->{message}.";
}
add_vulnerability($mark, $message, $entry->{tid}, 0, "GET",
$request{whisker}->{uri}, $result);
# Mark it successful
$entry->{'checked'} = 1;
$mark->{'realms'}{$realm}{'status'} = 1;
$mark->{'realms'}{'default'} = $mark->{'realms'}{$realm};
last;
}
}
else {
$result->{'www-authenticate'} = $save_auth;
}
}
LW2::auth_unset(\%request);
return $request, $result;
}
1;
|